From 4299e0b1effffbeb094a6a0eab6166c49cd9464e Mon Sep 17 00:00:00 2001 From: Thanatos Date: Mon, 25 Sep 2023 20:54:02 +0200 Subject: [PATCH 1/2] Rename unknown, add all_actors method --- .../formats/bmsld.py | 14 +++++++++----- tests/formats/test_bmsld.py | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mercury_engine_data_structures/formats/bmsld.py b/src/mercury_engine_data_structures/formats/bmsld.py index d89cf1b0..6a639f6d 100644 --- a/src/mercury_engine_data_structures/formats/bmsld.py +++ b/src/mercury_engine_data_structures/formats/bmsld.py @@ -1,5 +1,5 @@ import logging -from typing import Iterator +from typing import Iterator, Tuple import construct from construct import Const, Construct, Container, Flag, Float32l, Hex, Int32ul, Struct, Switch @@ -55,10 +55,9 @@ x=Float, y=Float, z=Float, - unk05=Hex(Int32ul), - unk06=Hex(Int32ul), - unk07=Hex(Int32ul), - + x_rotation=Float32l, + y_rotation=Float32l, + z_rotation=Float32l, components=make_vector(Struct( component_type=StrId, command=StrId, @@ -149,6 +148,11 @@ class Bmsld(BaseResource): def construct_class(cls, target_game: Game) -> Construct: return BMSLD + def all_actors(self) -> Iterator[Tuple[int, str, construct.Container]]: + for layer in self.raw.actors: + for actor_name, actor in layer.items(): + yield layer, actor_name, actor + def all_actor_groups(self) -> Iterator[tuple[str, Container]]: for sub_area in self.raw.sub_areas: yield sub_area.name, sub_area diff --git a/tests/formats/test_bmsld.py b/tests/formats/test_bmsld.py index aa060ba1..e672c4f2 100644 --- a/tests/formats/test_bmsld.py +++ b/tests/formats/test_bmsld.py @@ -60,6 +60,10 @@ def test_get_actor_group(surface_bmsld: Bmsld): with pytest.raises(KeyError): surface_bmsld.get_actor_group("blabla") +def test_all_actors(surface_bmsld: Bmsld): + all_actors = list(surface_bmsld.all_actors()) + assert len(all_actors) == 232 + def test_all_actor_group_names_for_actor(surface_bmsld: Bmsld): groups = surface_bmsld.all_actor_group_names_for_actor("LE_EnergyRecharge") assert groups == [ From 478b6feb7e76f7dc963ed5318b876b5c05ccd40e Mon Sep 17 00:00:00 2001 From: Thanatos Date: Mon, 25 Sep 2023 21:47:10 +0200 Subject: [PATCH 2/2] Make position and rotation a vector --- src/mercury_engine_data_structures/formats/bmsld.py | 10 +++------- .../samus_returns_types.json | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/mercury_engine_data_structures/formats/bmsld.py b/src/mercury_engine_data_structures/formats/bmsld.py index 6a639f6d..7011b993 100644 --- a/src/mercury_engine_data_structures/formats/bmsld.py +++ b/src/mercury_engine_data_structures/formats/bmsld.py @@ -4,7 +4,7 @@ import construct from construct import Const, Construct, Container, Flag, Float32l, Hex, Int32ul, Struct, Switch -from mercury_engine_data_structures.common_types import Float, StrId, make_dict, make_vector +from mercury_engine_data_structures.common_types import CVector3D, Float, StrId, make_dict, make_vector from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage from mercury_engine_data_structures.formats import BaseResource from mercury_engine_data_structures.formats.collision import collision_formats @@ -52,12 +52,8 @@ ProperActor = Struct( type=StrId, - x=Float, - y=Float, - z=Float, - x_rotation=Float32l, - y_rotation=Float32l, - z_rotation=Float32l, + position=CVector3D, + rotation=CVector3D, components=make_vector(Struct( component_type=StrId, command=StrId, diff --git a/src/mercury_engine_data_structures/samus_returns_types.json b/src/mercury_engine_data_structures/samus_returns_types.json index 39257118..ed04be66 100644 --- a/src/mercury_engine_data_structures/samus_returns_types.json +++ b/src/mercury_engine_data_structures/samus_returns_types.json @@ -1353,12 +1353,8 @@ "parent": "CGameObject", "fields": { "type": "base::global::StrId", - "x": "float", - "y": "float", - "z": "float", - "unk05": "unsigned", - "unk06": "unsigned", - "unk07": "unsigned", + "position": "base::math::CVector3D", + "rotation": "base::math::CVector3D", "components": "base::global::CRntVector" } }, @@ -1409,5 +1405,9 @@ "unsigned": { "kind": "primitive", "primitive_kind": "uint" + }, + "base::math::CVector3D": { + "kind": "primitive", + "primitive_kind": "float_vec3" } }