Skip to content

Commit

Permalink
Support Elevator Shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
dyceron committed Apr 14, 2024
1 parent f16dee6 commit e1e9afe
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/open_samus_returns_rando/files/custom/scenario.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Game.ImportLibrary("system/scripts/guilib.lua", false)
Game.ImportLibrary("system/scripts/cosmetics.lua", false)

Game.DoFile("system/scripts/room_names.lua")
Game.DoFile("system/scripts/elevators.lua")

Scenario = Scenario or {}
setmetatable(Scenario, {__index = _G})
Expand Down Expand Up @@ -142,4 +143,14 @@ end

function Scenario.UpdateRoomName(new_subarea)
Game.AddSF(0.0, "RoomNameGui.Update", "s", new_subarea)
end

function Scenario.RandoOnElevatorUse(from_actor, _ARG_1_, _ARG_2_)
local destination = ElevatorDestinations[Scenario.CurrentScenarioID][from_actor.sName]
if Scenario.CurrentScenario == destination.scenario then
Game.AddGUISF(0.5, GUI.ElevatorStartUseActionStep2InnerArea, "")
else
Game.AddGUISF(0.5, GUI.ElevatorStartUseActionStep2InterArea, "")
end
Elevator.Use("c10_samus", destination.scenario, destination.actor, _ARG_2_)
end
38 changes: 24 additions & 14 deletions src/open_samus_returns_rando/files/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,31 @@
}
},
"elevators": {
"type": "array",
"items": {
"type": "object",
"properties": {
"teleporter": {
"$ref": "#/$defs/actor_reference_with_layer"
},
"destination": {
"$ref": "#/$defs/actor_reference"
"type": "object",
"description": "A dictionary of dictionaries mapping scenario and elevator actor to a connecting elevator",
"patternProperties": {
".*": {
"type": "object",
"additionalProperties": false,
"default": {},
"patternProperties": {
".*": {
"type": "object",
"properties": {
"scenario": {
"$ref": "#/$defs/scenario_name"
},
"actor": {
"type": "string"
}
},
"required": [
"scenario",
"actor"
]
}
}
},
"required": [
"teleporter",
"destination"
]
}
}
},
"door_patches": {
Expand Down
1 change: 1 addition & 0 deletions src/open_samus_returns_rando/files/templates/elevators.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ElevatorDestinations = TEMPLATE("elevator_dict")
97 changes: 97 additions & 0 deletions src/open_samus_returns_rando/misc_patches/elevators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from construct import Container
from mercury_engine_data_structures.formats.lua import Lua
from open_samus_returns_rando.misc_patches import lua_util
from open_samus_returns_rando.patcher_editor import PatcherEditor


def create_elevator_table(editor: PatcherEditor, configuration: dict):
py_dict: dict = configuration["elevators"]

file = lua_util.replace_lua_template("elevators.lua", {"elevator_dict": py_dict}, True)
editor.add_new_asset(
"system/scripts/elevators.lc",
Lua(Container(lua_text=file), editor.target_game),
[]
)


def update_elevators(editor: PatcherEditor, configuration: dict):
ELEVATORS = {
"s000_surface": ["LE_Platform_Elevator_FromArea01"],
"s010_area1": [
"LE_Platform_Elevator_FromArea00",
"LE_Platform_Elevator_FromArea02",
],
"s020_area2": [
"LE_Platform_Elevator_FromArea02B",
"LE_Platform_Elevator_FromArea02C",
],
"s025_area2b": ["LE_Platform_Elevator_FromArea02A"],
"s028_area2c": [
"LE_Platform_Elevator_FromArea01",
"LE_Platform_Elevator_FromArea02A",
"LE_Platform_Elevator_FromArea03",
],
"s030_area3": [
"LE_Platform_Elevator_FromArea02",
"LE_Platform_Elevator_FromArea03B_01",
"LE_Platform_Elevator_FromArea03B_02",
"LE_Platform_Elevator_FromArea03C",
"LE_Platform_Elevator_FromArea04",
],
"s033_area3b": [
"LE_Platform_Elevator_FromArea03A_01",
"LE_Platform_Elevator_FromArea03A_02",
"LE_Platform_Elevator_FromArea03C",
],
"s036_area3c": [
"LE_Platform_Elevator_FromArea03A",
"LE_Platform_Elevator_FromArea03B",
],
"s040_area4": [
"LE_Platform_Elevator_FromArea03",
"LE_Platform_Elevator_FromArea05",
"LE_Platform_Elevator_FromArea06",
],
"s050_area5": ["LE_Platform_Elevator_FromArea04"],
"s060_area6": [
"LE_Platform_Elevator_FromArea04",
"LE_Platform_Elevator_FromArea06C_01",
"LE_Platform_Elevator_FromArea06C_02",
"LE_Platform_Elevator_FromArea07",
],
"s065_area6b": [
"LE_Platform_Elevator_FromArea06C_01",
"LE_Platform_Elevator_FromArea06C_02",
],
"s067_area6c": [
"LE_Platform_Elevator_FromArea06A_01",
"LE_Platform_Elevator_FromArea06A_02",
"LE_Platform_Elevator_FromArea06B_01",
"LE_Platform_Elevator_FromArea06B_02",
],
"s070_area7": [
"LE_Platform_Elevator_FromArea06",
"LE_Platform_Elevator_FromArea09",
],
"s090_area9": [
"LE_Platform_Elevator_FromArea07",
"LE_Platform_Elevator_FromArea10",
],
"s100_area10": [
"LE_Platform_Elevator_FromArea09",
"LE_Platform_Elevator_FromAreaSurfaceB",
],
"s110_surfaceb": ["LE_Platform_Elevator_FromArea10"],
}

for scenario_name, elevators in ELEVATORS.items():
scenario = editor.get_scenario(scenario_name)
for elevator in elevators:
platform = scenario.raw.actors[10][elevator]["components"][0]
platform["arguments"][1]["value"] = "Scenario.RandoOnElevatorUse"


def patch_elevators(editor: PatcherEditor, configuration: dict):
create_elevator_table(editor, configuration)
update_elevators(editor, configuration)
4 changes: 4 additions & 0 deletions src/open_samus_returns_rando/samus_returns_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from open_samus_returns_rando.lua_editor import LuaEditor
from open_samus_returns_rando.misc_patches.collision_camera_table import create_collision_camera_table
from open_samus_returns_rando.misc_patches.credits import patch_credits
from open_samus_returns_rando.misc_patches.elevators import patch_elevators
from open_samus_returns_rando.misc_patches.exefs import DSPatch
from open_samus_returns_rando.misc_patches.spawn_points import patch_custom_spawn_points
from open_samus_returns_rando.misc_patches.text_patches import add_spiderboost_status, apply_text_patches
Expand Down Expand Up @@ -116,6 +117,9 @@ def patch_extracted(input_path: Path, output_path: Path, configuration: dict):
# Update cc_to_room_name.lua
create_collision_camera_table(editor, configuration)

# Patch elevator destinations
patch_elevators(editor, configuration)

out_romfs = output_path.joinpath("romfs")
out_exefs = output_path.joinpath("exefs")
shutil.rmtree(out_romfs, ignore_errors=True)
Expand Down

0 comments on commit e1e9afe

Please sign in to comment.