Skip to content

Commit b662d2b

Browse files
committed
add type property to Component
1 parent 371463a commit b662d2b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/mercury_engine_data_structures/formats/bmsad.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,21 @@ def raw(self) -> Container:
569569
return self._raw
570570

571571
def get_component_type(self) -> str:
572+
return find_charclass_for_type(self.type)
573+
574+
@property
575+
def type(self) -> str:
576+
if self.target_game == Game.SAMUS_RETURNS:
577+
raise AttributeError(name="type", obj=self)
578+
if self.target_game == Game.DREAD:
579+
return self.raw.type
580+
581+
@type.setter
582+
def type(self, value: str):
572583
if self.target_game == Game.SAMUS_RETURNS:
573-
raise AttributeError(name="_get_component_type", obj=self)
584+
raise AttributeError(name="type", obj=self)
574585
if self.target_game == Game.DREAD:
575-
return find_charclass_for_type(self.raw.type)
586+
self.raw.type = value
576587

577588
def get_component_type_class(self) -> type_lib.StructType:
578589
return get_type_lib_for_game(self.target_game).get_type(self.get_component_type())

tests/formats/test_bmsad.py

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ def test_api_dread_charclass(dread_file_tree: FileTreeEditor):
114114

115115
navmesh = bmsad.components["NAVMESHITEM"]
116116

117+
# type
118+
assert navmesh.type == "CNavMeshItemComponent"
119+
assert navmesh.get_component_type() == "CCharClassNavMeshItemComponent"
120+
navmesh.type = "CPowerBombBlockLifeComponent"
121+
assert navmesh.type == "CPowerBombBlockLifeComponent"
122+
assert navmesh.get_component_type() == "CCharClassLifeComponent"
123+
navmesh.type = "CNavMeshItemComponent"
124+
117125
# extra_fields
118126
assert navmesh.fields.sInitialStage == "closed"
119127
navmesh.fields.sInitialStage = "opened"

0 commit comments

Comments
 (0)