Skip to content

Commit

Permalink
Merge pull request #256 from ThanatosGit/bmssd-fixes
Browse files Browse the repository at this point in the history
Fix BMSSD API
  • Loading branch information
henriquegemignani authored Dec 23, 2024
2 parents 688cc5f + 6889608 commit 5e2c65d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/mercury_engine_data_structures/formats/bmssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ def scene_groups_for_item(self, item: str | construct.Container, item_type: Item
if isinstance(item, str):
item = self.get_item(item, item_type)

return [sg_name for sg_name, sg_val in self.raw.scene_groups.items() if item in sg_val[item_type]]
return [
sg_name
for sg_name, sg_val in self.raw.scene_groups.items()
if sg_val.get(item_type) and item in sg_val[item_type]
]

def add_item(self, item: construct.Container, item_type: ItemType, scene_groups: list[str] = None):
if item_type == ItemType.OBJECT:
Expand All @@ -267,4 +271,10 @@ def remove_item(self, item: construct.Container, item_type: ItemType):
for sg in groups:
self.remove_item_from_group(item, item_type, sg)

self.raw[f"_{item_type}"].remove(item)
raw_object = self.raw[f"_{item_type}"]
if isinstance(raw_object, dict):
self.raw[f"_{item_type}"] = {
iter_key: iter_item for iter_key, iter_item in raw_object.items() if iter_item != item
}
elif isinstance(raw_object, list):
raw_object.remove(item)
9 changes: 9 additions & 0 deletions tests/formats/test_bmssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ def test_bmssd_dread_functions(dread_tree_100):
assert roof not in bmssd.get_scene_group("sg_SubArea_collision_camera_003")[ItemType.OBJECT]
assert roof not in bmssd.get_scene_group("sg_SubArea_collision_camera_002")[ItemType.OBJECT]

# remove from an ItemType which uses a dict
random_obj = bmssd.get_item("part001_jp6_mapmodel04", ItemType.SCENE_BLOCK)
assert bmssd.scene_groups_for_item(random_obj, ItemType.SCENE_BLOCK) == ["sg_SubArea_collision_camera_002"]
bmssd.remove_item(random_obj, ItemType.SCENE_BLOCK)
assert bmssd.scene_groups_for_item(random_obj, ItemType.SCENE_BLOCK) == []

# try to get a non-existent object
assert bmssd.scene_groups_for_item("foo", ItemType.LIGHT) == []

# PART 4: make sure it can actually build and parse lol
con = Bmssd.construct_class(target_game=Game.DREAD)
built = con.build(bmssd.raw, target_game=Game.DREAD)
Expand Down

0 comments on commit 5e2c65d

Please sign in to comment.