diff --git a/open_samus_returns_rando/bmsld_add.py b/open_samus_returns_rando/bmsld_add.py deleted file mode 100644 index 7b773fd..0000000 --- a/open_samus_returns_rando/bmsld_add.py +++ /dev/null @@ -1,57 +0,0 @@ -# FIXME: Can be moved later to MEDS as methods of Bmsld! -import logging -from collections.abc import Iterator - -from construct import Container -from mercury_engine_data_structures.formats.bmsld import Bmsld - -LOG = logging.getLogger("bmsld_add") - -def all_actor_groups(scenario: Bmsld) -> Iterator[tuple[str, Container]]: - for sub_area in scenario.raw.sub_areas: - yield sub_area.name, sub_area - -def add_actor_to_group(group: Container, actor_name: str, pos: int = -1): - group.names.insert(pos, actor_name) - -def get_actor_group(scenario: Bmsld, group_name: str) -> Container: - group = next( - (sub_area for sub_area_name, sub_area in all_actor_groups(scenario) - if sub_area_name == group_name), - None - ) - if group is None: - raise Exception(f"No group found with name for {group_name}") - return group - -def add_actor_to_entity_groups(scenario: Bmsld, collision_camera_name: str, actor_name: str, all_groups: bool = False): - def compare_func(first: str, second: str) -> bool: - if all_groups: - return first.startswith(f"eg_SubArea_{second}") - else: - return first == f"eg_SubArea_{second}" - - collision_camera_groups = [group for group_name, group in all_actor_groups(scenario) - if compare_func(group_name, collision_camera_name)] - if len(collision_camera_groups) == 0: - raise Exception(f"No entity group found for {collision_camera_name}") - for group in collision_camera_groups: - LOG.debug("Add actor %s to group %s", actor_name, group.name) - add_actor_to_group(group, actor_name) - -def all_actor_group_names_for_actor(scenario: Bmsld, actor_name: str) -> list[str]: - return [ - actor_group_name - for actor_group_name, actor_group in all_actor_groups(scenario) - if actor_name in actor_group.names - ] - -def remove_actor_from_group(scenario: Bmsld, group_name: str, actor_name: str): - LOG.debug("Remove actor %s from group %s", actor_name, group_name) - group = get_actor_group(scenario, group_name) - group.names.remove(actor_name) - -def remove_actor_from_all_groups(scenario: Bmsld, actor_name: str): - group_names = all_actor_group_names_for_actor(scenario, actor_name) - for group_name in group_names: - remove_actor_from_group(scenario, group_name, actor_name) diff --git a/open_samus_returns_rando/patcher_editor.py b/open_samus_returns_rando/patcher_editor.py index f51d284..dc7ee86 100644 --- a/open_samus_returns_rando/patcher_editor.py +++ b/open_samus_returns_rando/patcher_editor.py @@ -7,7 +7,6 @@ from mercury_engine_data_structures.formats import BaseResource, Bmsld from mercury_engine_data_structures.game_check import Game -from open_samus_returns_rando.bmsld_add import remove_actor_from_all_groups from open_samus_returns_rando.constants import ALL_AREAS T = typing.TypeVar("T") @@ -73,4 +72,4 @@ def remove_entity(self, reference: dict): actor_name = reference["actor"] scenario.raw.actors[layer].pop(actor_name) - remove_actor_from_all_groups(scenario, actor_name) + scenario.remove_actor_from_all_groups(actor_name) diff --git a/open_samus_returns_rando/samus_returns_patcher.py b/open_samus_returns_rando/samus_returns_patcher.py index ec2aa4f..cf54ebf 100644 --- a/open_samus_returns_rando/samus_returns_patcher.py +++ b/open_samus_returns_rando/samus_returns_patcher.py @@ -6,7 +6,6 @@ from mercury_engine_data_structures.file_tree_editor import OutputFormat -from open_samus_returns_rando.bmsld_add import add_actor_to_entity_groups from open_samus_returns_rando.lua_editor import LuaEditor from open_samus_returns_rando.misc_patches import lua_util from open_samus_returns_rando.misc_patches.exefs import DSPatch @@ -32,7 +31,7 @@ def create_custom_init(configuration: dict) -> str: energy_per_tank = configuration["energy_per_tank"] max_life = inventory.pop("ITEM_MAX_LIFE") - + aeion_per_tank = configuration["aeion_per_tank"] max_aeion = inventory.pop("ITEM_MAX_SPECIAL_ENERGY") @@ -85,7 +84,7 @@ def patch_spawn_points(editor: PatcherEditor, spawn_config: list[dict]): scenario_name, new_actor_name, collision_camera_name, new_spawn_pos = unpack_new_actor(new_spawn) scenario = editor.get_scenario(scenario_name) editor.copy_actor(scenario_name, new_spawn_pos, base_actor, new_actor_name, 5) - add_actor_to_entity_groups(scenario, collision_camera_name, new_actor_name) + scenario.add_actor_to_entity_groups(collision_camera_name, new_actor_name) def patch_custom_pickups(editor: PatcherEditor, pickup_config: list[dict]): # create custom pickup @@ -95,7 +94,7 @@ def patch_custom_pickups(editor: PatcherEditor, pickup_config: list[dict]): scenario_name, new_actor_name, collision_camera_name, new_pos = unpack_new_actor(new_pickup) scenario = editor.get_scenario(scenario_name) editor.copy_actor(scenario_name, new_pos, base_actor, new_actor_name, 9) - add_actor_to_entity_groups(scenario, collision_camera_name, new_actor_name) + scenario.add_actor_to_entity_groups(collision_camera_name, new_actor_name) def patch_extracted(input_path: Path, output_path: Path, configuration: dict): LOG.info("Will patch files from %s", input_path) diff --git a/open_samus_returns_rando/specific_patches/heat_room_patches.py b/open_samus_returns_rando/specific_patches/heat_room_patches.py index af26ff0..5336627 100644 --- a/open_samus_returns_rando/specific_patches/heat_room_patches.py +++ b/open_samus_returns_rando/specific_patches/heat_room_patches.py @@ -2,7 +2,6 @@ from construct import Container, ListContainer -from open_samus_returns_rando.bmsld_add import add_actor_to_entity_groups, add_actor_to_group, get_actor_group from open_samus_returns_rando.patcher_editor import PatcherEditor @@ -26,7 +25,7 @@ def _patch_area_2b(editor: PatcherEditor): # area2b => shape is already correct but ms forgot to add one room heat_trigger_2b = {"scenario": "s025_area2b", "layer": "2", "actor": "TG_SP_Heat_001"} scenario_2b = editor.get_scenario(heat_trigger_2b["scenario"]) - add_actor_to_entity_groups(scenario_2b, "collision_camera013", heat_trigger_2b["actor"]) + scenario_2b.add_actor_to_entity_groups("collision_camera013", heat_trigger_2b["actor"]) def _patch_area_3b(editor: PatcherEditor): name_of_scenario = "s033_area3b" @@ -53,9 +52,8 @@ def _patch_area_3b(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (1000.0, 5000.0, 0.0), heat_actor, "TG_Heat_003", 2) - group_cc36 = get_actor_group(scenario_3b, "eg_SubArea_collision_camera_036") - - add_actor_to_group(group_cc36, "TG_Heat_003", -1) + group_cc36 = scenario_3b.get_actor_group("eg_SubArea_collision_camera_036") + group_cc36.names.insert(-1, "TG_Heat_003") def _patch_area_3c(editor: PatcherEditor): name_of_scenario = "s036_area3c" @@ -82,11 +80,11 @@ def _patch_area_3c(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (19269.0, 3669.0, 0.0), heat_actor, "TG_Heat_003", 2) - group_cc22 = get_actor_group(scenario_3c, "eg_SubArea_collision_camera_022") - group_cc26 = get_actor_group(scenario_3c, "eg_SubArea_collision_camera_026") + group_cc22 = scenario_3c.get_actor_group("eg_SubArea_collision_camera_022") + group_cc26 = scenario_3c.get_actor_group("eg_SubArea_collision_camera_026") - add_actor_to_group(group_cc22, "TG_Heat_003", -1) - add_actor_to_group(group_cc26, "TG_Heat_003", -1) + group_cc22.names.insert(-1, "TG_Heat_003") + group_cc26.names.insert(-1, "TG_Heat_003") def _patch_area_4(editor: PatcherEditor): name_of_scenario = "s040_area4" @@ -113,7 +111,7 @@ def _patch_area_4(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (1000.0, 1000.0, 0.0), heat_actor, "TG_Heat_003", 2) - add_actor_to_entity_groups(scenario_4, "collision_camera_005", "TG_Heat_003", True) + scenario_4.add_actor_to_entity_groups("collision_camera_005", "TG_Heat_003", True) def _patch_area_5_1(editor: PatcherEditor): name_of_scenario = "s050_area5" @@ -140,7 +138,7 @@ def _patch_area_5_1(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (-2000.0, 5000.0, 0.0), heat_actor, "TG_Heat_003", 2) - add_actor_to_entity_groups(scenario_5, "collision_camera_006", "TG_Heat_003", True) + scenario_5.add_actor_to_entity_groups("collision_camera_006", "TG_Heat_003", True) def _patch_area_5_2(editor: PatcherEditor): @@ -169,9 +167,9 @@ def _patch_area_5_2(editor: PatcherEditor): new_actor = editor.copy_actor(name_of_scenario, (5600.0, 16000.0, 0.0), heat_actor, "TG_Heat_004", 2) new_actor["components"][0]["arguments"][16]["value"] = "LS_Heat_002" - add_actor_to_entity_groups(scenario_5, "collision_camera_009", "TG_Heat_004", True) - add_actor_to_entity_groups(scenario_5, "collision_camera_015", "TG_Heat_004", True) - add_actor_to_entity_groups(scenario_5, "collision_camera_017", "TG_Heat_004", True) + scenario_5.add_actor_to_entity_groups("collision_camera_009", "TG_Heat_004", True) + scenario_5.add_actor_to_entity_groups("collision_camera_015", "TG_Heat_004", True) + scenario_5.add_actor_to_entity_groups("collision_camera_017", "TG_Heat_004", True) def _patch_area_6_b(editor: PatcherEditor): name_of_scenario = "s065_area6b" @@ -198,9 +196,9 @@ def _patch_area_6_b(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (6000.0, 9000.0, 0.0), heat_actor, "TG_Heat_003", 2) - add_actor_to_entity_groups(scenario_6b, "collision_camera_014", "TG_Heat_003", True) - add_actor_to_entity_groups(scenario_6b, "collision_camera_017", "TG_Heat_003", True) - add_actor_to_entity_groups(scenario_6b, "collision_camera_018", "TG_Heat_003", True) + scenario_6b.add_actor_to_entity_groups("collision_camera_014", "TG_Heat_003", True) + scenario_6b.add_actor_to_entity_groups("collision_camera_017", "TG_Heat_003", True) + scenario_6b.add_actor_to_entity_groups("collision_camera_018", "TG_Heat_003", True) def _patch_area_6_c(editor: PatcherEditor): @@ -228,7 +226,7 @@ def _patch_area_6_c(editor: PatcherEditor): heat_actor = _get_heat_trigger(editor) editor.copy_actor(name_of_scenario, (1000.0, 2000.0, 0.0), heat_actor, "TG_Heat_003", 2) - add_actor_to_entity_groups(scenario_6c, "collision_camera_022", "TG_Heat_003", True) + scenario_6c.add_actor_to_entity_groups("collision_camera_022", "TG_Heat_003", True) def patch_heat_rooms(editor: PatcherEditor): _patch_area_2b(editor)