Skip to content
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

Rename unknown, add all_actors method #84

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/mercury_engine_data_structures/formats/bmsld.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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

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
Expand Down Expand Up @@ -52,13 +52,8 @@
ProperActor = Struct(
type=StrId,

x=Float,
y=Float,
z=Float,
unk05=Hex(Int32ul),
unk06=Hex(Int32ul),
unk07=Hex(Int32ul),

position=CVector3D,
rotation=CVector3D,
components=make_vector(Struct(
component_type=StrId,
command=StrId,
Expand Down Expand Up @@ -149,6 +144,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
Expand Down
12 changes: 6 additions & 6 deletions src/mercury_engine_data_structures/samus_returns_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component>"
}
},
Expand Down Expand Up @@ -1409,5 +1405,9 @@
"unsigned": {
"kind": "primitive",
"primitive_kind": "uint"
},
"base::math::CVector3D": {
"kind": "primitive",
"primitive_kind": "float_vec3"
}
}
4 changes: 4 additions & 0 deletions tests/formats/test_bmsld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == [
Expand Down