-
Notifications
You must be signed in to change notification settings - Fork 10
Fix Vec2/3/4 #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix Vec2/3/4 #286
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
import construct | ||
|
||
from mercury_engine_data_structures.common_types import Vec2, Vec3, Vec4 | ||
|
||
if TYPE_CHECKING: | ||
from mercury_engine_data_structures.game_check import Game | ||
from mercury_engine_data_structures.pointer_set import PointerSet | ||
|
@@ -118,9 +120,9 @@ class PrimitiveKind(Enum): | |
PrimitiveKind.UINT_16: int, | ||
PrimitiveKind.UINT_64: int, | ||
PrimitiveKind.FLOAT: float, | ||
PrimitiveKind.VECTOR_2: typing.Sequence, | ||
PrimitiveKind.VECTOR_3: typing.Sequence, | ||
PrimitiveKind.VECTOR_4: typing.Sequence, | ||
PrimitiveKind.VECTOR_2: Vec2, | ||
PrimitiveKind.VECTOR_3: Vec3, | ||
PrimitiveKind.VECTOR_4: Vec4, | ||
PrimitiveKind.BYTES: bytes, | ||
PrimitiveKind.PROPERTY: str | int, | ||
} | ||
|
@@ -133,12 +135,6 @@ class PrimitiveKind(Enum): | |
PrimitiveKind.PROPERTY: (0, 2**64 - 1), | ||
} | ||
|
||
primitive_vector_lengths = { | ||
PrimitiveKind.VECTOR_2: 2, | ||
PrimitiveKind.VECTOR_3: 3, | ||
PrimitiveKind.VECTOR_4: 4, | ||
} | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class PrimitiveType(BaseType): | ||
|
@@ -171,12 +167,6 @@ def _find_type_errors(self, __value: typing.Any) -> BaseException | None: | |
return None | ||
return ValueError(f"{__value} is out of range of [{hex(low)}, {hex(high)}]") | ||
|
||
if self.primitive_kind in primitive_vector_lengths: | ||
length = primitive_vector_lengths[self.primitive_kind] | ||
if len(__value) == length and all(isinstance(v, float) for v in __value): | ||
return None | ||
return ValueError(f"Invalid CVector{length}D: {__value}") | ||
|
||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should keep this length check, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want that to explicitly fail? Shouldn't you be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could you use that instead of this length check if you prefer. still needs to be a special case tho |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import pytest | ||
|
||
from mercury_engine_data_structures.common_types import Vec2, Vec3, Vec4 | ||
from mercury_engine_data_structures.formats import dread_types | ||
from mercury_engine_data_structures.game_check import Game | ||
from mercury_engine_data_structures.type_lib import TypeLib, get_type_lib_for_game | ||
|
@@ -31,9 +32,9 @@ def _dread_type_lib(): | |
("unsigned_int", 2**32 - 1, None), | ||
("unsigned_long", 2**64 - 1, None), | ||
("float", 0.0, None), | ||
("base::math::CVector2D", [0.0, 0.0], None), | ||
("base::math::CVector3D", [0.0, 0.0, 0.0], None), | ||
("base::math::CVector4D", [0.0, 0.0, 0.0, 0.0], None), | ||
("base::math::CVector2D", Vec2(0.0, 0.0), None), | ||
("base::math::CVector3D", Vec3(0.0, 0.0, 0.0), None), | ||
("base::math::CVector4D", Vec4(0.0, 0.0, 0.0, 0.0), None), | ||
("base::global::CRntFile", b"\x24\x03", None), | ||
("base::global::CName", "", None), | ||
("base::global::CName", 2**64 - 1, None), | ||
|
@@ -44,9 +45,9 @@ def _dread_type_lib(): | |
("unsigned_int", None, TypeError("Expected int; got NoneType")), | ||
("unsigned_long", None, TypeError("Expected int; got NoneType")), | ||
("float", None, TypeError("Expected float; got NoneType")), | ||
("base::math::CVector2D", None, TypeError("Expected typing.Sequence; got NoneType")), | ||
("base::math::CVector3D", None, TypeError("Expected typing.Sequence; got NoneType")), | ||
("base::math::CVector4D", None, TypeError("Expected typing.Sequence; got NoneType")), | ||
("base::math::CVector2D", None, TypeError("Expected Vec2; got NoneType")), | ||
("base::math::CVector3D", None, TypeError("Expected Vec3; got NoneType")), | ||
("base::math::CVector4D", None, TypeError("Expected Vec4; got NoneType")), | ||
("base::global::CRntFile", None, TypeError("Expected bytes; got NoneType")), | ||
("base::global::CName", None, TypeError("Expected str | int; got NoneType")), | ||
("base::global::CName", None, TypeError("Expected str | int; got NoneType")), | ||
|
@@ -56,10 +57,10 @@ def _dread_type_lib(): | |
("unsigned_int", 2**32, ValueError("4294967296 is out of range of [0x0, 0xffffffff]")), | ||
("unsigned_long", 2**64, ValueError("18446744073709551616 is out of range of [0x0, 0xffffffffffffffff]")), | ||
("base::global::CName", -1, ValueError("-1 is out of range of [0x0, 0xffffffffffffffff]")), | ||
("base::math::CVector2D", ["foo", "bar"], ValueError("Invalid CVector2D: ['foo', 'bar']")), | ||
("base::math::CVector2D", [0.0], ValueError("Invalid CVector2D: [0.0]")), | ||
("base::math::CVector3D", [0.0], ValueError("Invalid CVector3D: [0.0]")), | ||
("base::math::CVector4D", [0.0], ValueError("Invalid CVector4D: [0.0]")), | ||
("base::math::CVector2D", ["foo", "bar"], TypeError("Expected Vec2; got list")), | ||
("base::math::CVector2D", [0.0], TypeError("Expected Vec2; got list")), | ||
("base::math::CVector3D", [0.0], TypeError("Expected Vec3; got list")), | ||
("base::math::CVector4D", [0.0], TypeError("Expected Vec4; got list")), | ||
|
||
# struct | ||
( | ||
"base::reflection::CType", | ||
|
@@ -156,7 +157,7 @@ def _dread_type_lib(): | |
{ | ||
"@type": "game::logic::collision::CCircleShape2D", | ||
"@value": { | ||
"vPos": [0.0, 0.0, 0.0], | ||
"vPos": Vec3(0.0, 0.0, 0.0), | ||
"bIsSolid": False, | ||
"fRadius": 1.0, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably just make this take a Vec2 as the argument