From b7eee723cf1e658561c04ee6fe905fda8c891094 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sat, 27 Apr 2024 17:03:05 -0400 Subject: [PATCH] Refactor Custom Pickups --- .../pickups/custom_pickups.py | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/open_samus_returns_rando/pickups/custom_pickups.py b/src/open_samus_returns_rando/pickups/custom_pickups.py index fb3704ce..842fe7bd 100644 --- a/src/open_samus_returns_rando/pickups/custom_pickups.py +++ b/src/open_samus_returns_rando/pickups/custom_pickups.py @@ -1,47 +1,48 @@ +import typing + from construct import Container, ListContainer from mercury_engine_data_structures.formats import Bmsmsd from open_samus_returns_rando.patcher_editor import PatcherEditor -BABY_ICON = Container({ - "actor_name": "LE_Baby_Hatchling", - "clear_condition": "", - "icon": "itemenabled", - "icon_priority": 0, - "coordinates": ListContainer([ - -3400.0, - 11225.0, - 0.0 - ]), -}) - - -def _get_actor(editor: PatcherEditor): - actor_to_copy = { - "scenario": "s000_surface", - "layer": "9", - "actor": "LE_PowerUP_Morphball", - } - reference_actor = editor.resolve_actor_reference(actor_to_copy) - return reference_actor - - -def _create_baby_pickup(editor: PatcherEditor): - name_of_scenario = "s100_area10" - scenario_10 = editor.get_scenario(name_of_scenario) - name_of_pickup = "LE_Baby_Hatchling" - - reference_actor = _get_actor(editor) - - editor.copy_actor( - name_of_scenario, (-3400.0, 11225.0, 0.0), reference_actor, name_of_pickup, 9, + +class NewPickups(typing.NamedTuple): + scenario: str + name: str + position: list[float] + tile_index: int + entity_groups: list[str] + + +new_pickups = [ + NewPickups( + "s100_area10", "LE_Baby_Hatchling", [-3400.0, 11225.0, 0.0], 252, ["collision_camera_022"] ) +] + + +def add_pickups(editor: PatcherEditor, new_pickup: NewPickups): + template_pickup = editor.get_scenario("s000_surface").raw.actors[9]["LE_PowerUP_Morphball"] + + PICKUP_ICON = Container({ + "actor_name": new_pickup.name, + "clear_condition": "", + "icon": "itemenabled", + "icon_priority": 0, + "coordinates": ListContainer(new_pickup.position), + }) + + scenario_name = new_pickup.scenario + scenario_file = editor.get_scenario(scenario_name) + + editor.copy_actor(scenario_name, new_pickup.position, template_pickup, new_pickup.name, 9) - scenario_10.add_actor_to_entity_groups("collision_camera_022", name_of_pickup) + scenario_map = editor.get_file(f"gui/minimaps/c10_samus/{scenario_name}.bmsmsd", Bmsmsd) + scenario_map.raw["tiles"][new_pickup.tile_index]["icons"] = ListContainer([PICKUP_ICON]) - area10 = editor.get_file("gui/minimaps/c10_samus/s100_area10.bmsmsd", Bmsmsd) - mapicon = area10.raw["tiles"][252] - mapicon["icons"] = ListContainer([BABY_ICON]) + for entity_group in new_pickup.entity_groups: + scenario_file.add_actor_to_entity_groups(entity_group, new_pickup.name, True) def patch_custom_pickups(editor: PatcherEditor): - _create_baby_pickup(editor) + for new_pickup in new_pickups: + add_pickups(editor, new_pickup)