Skip to content

Commit

Permalink
Merge pull request #321 from randovania/elevator-shuffle
Browse files Browse the repository at this point in the history
Support Elevator Shuffle
  • Loading branch information
ThanatosGit authored Apr 17, 2024
2 parents 0bde1b3 + 6a79238 commit 25fb71f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
7 changes: 7 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,10 @@ 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]
Game.AddGUISF(0.5, GUI.ElevatorStartUseActionStep2InterArea, "")
Elevator.Use("c10_samus", destination.scenario, destination.actor, _ARG_2_)
end
41 changes: 26 additions & 15 deletions src/open_samus_returns_rando/files/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,33 @@
}
},
"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"
]
}
}
},
"default": {}
},
"door_patches": {
"type": "array",
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")
28 changes: 28 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,28 @@
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):
for scenario_name, elevators in configuration["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
14 changes: 14 additions & 0 deletions tests/test_files/starter_preset_patcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,20 @@
}
}
],
"elevators": {
"s010_area1": {
"LE_Platform_Elevator_FromArea02": {
"scenario": "s028_area2c",
"actor": "ST_FromArea01"
}
},
"s028_area2c": {
"LE_Platform_Elevator_FromArea01": {
"scenario": "s010_area1",
"actor": "ST_FromArea02"
}
}
},
"energy_per_tank": 100,
"reserves_per_tank": {
"life_tank_size": 299,
Expand Down

0 comments on commit 25fb71f

Please sign in to comment.