Skip to content

Commit

Permalink
Address Review
Browse files Browse the repository at this point in the history
  • Loading branch information
dyceron committed Jan 23, 2025
1 parent 890ad66 commit 8448b97
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
from pathlib import Path

from open_samus_returns_rando.files import files_path
from open_samus_returns_rando.lua_editor import get_parent_for
from open_samus_returns_rando.misc_patches.lua_util import lua_convert


def get_lua_for_item(progression: list[list[dict[str, str | int]]], region_name: str) -> str:
generic_pickup = """
Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false)
MultiworldPickup = MultiworldPickup or {}
function MultiworldPickup.main()
end
function MultiworldPickup.OnPickedUp(progression, actorOrName, regionName)
RandomizerPowerup.OnPickedUp(progression, actorOrName, regionName)
end
"""

main_item_id = str(progression[0][0]["item_id"])
parent = get_parent_for(main_item_id)
if parent == "RandomizerPowerup":
parent_content = generic_pickup
else:
parent_lower = parent.lower()
parent_content = files_path().joinpath("pickups", f"{parent_lower}.lua").read_text()
parent_content = parent_content.replace(parent, "MultiworldPickup")

progression_as_lua = lua_convert(progression, True)
return (f'{parent_content}\nMultiworldPickup.OnPickedUp({progression_as_lua},nil,{region_name})'
.replace("\n", "\\\n").replace("'", "\\'")
)


def create_exefs_patches(
Expand Down
6 changes: 5 additions & 1 deletion src/open_samus_returns_rando/files/custom/randoapi.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false)

RandoApi = RandoApi or {}
RandoApi = RandoApi or {
ChangeSuitValues = function(hasVaria, hasGravity) end,
ChangeBeams = function(hasWave, hasSpazer, hasPlasma, dmgSpazer, dmgPlasma, dmgPlasmaWave, dmgPlasmaSpazer) end
}

function RandoApi.main()
end

Expand Down
4 changes: 2 additions & 2 deletions src/open_samus_returns_rando/files/custom/scenario.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ function Scenario.InitGUI()
Cosmetics.UpdateGUI()
GUILib.InitCustomUI()
GUILib.UpdateTotalDNAColor()
RandoApi.CheckSuits()
RandoApi.CheckBeams()
Scenario.UpdateDNACounter()

if Init.bEnableRoomIds then
Expand Down Expand Up @@ -119,6 +117,8 @@ function Scenario.InitScenario(_ARG_0_, _ARG_1_, _ARG_2_, _ARG_3_)
Scenario.ShowText()
end

RandoApi.CheckSuits()
RandoApi.CheckBeams()
Scenario.UpdateProgressiveItemModels()
Scenario.UpdateBlastShields()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ function RandomizerPowerup.OnPickedUp(resources, actorOrName, regionName)

for _, resource in ipairs(granted) do
RandomizerPowerup.IncreaseAmmo(resource)
if resource.item_id == "ITEM_WEAPON_WAVE_BEAM" or resource.item_id == "ITEM_WEAPON_SPAZER_BEAM" or resource.item_id == "ITEM_WEAPON_PLASMA_BEAM" then
RandoApi.CheckBeams()
end
RandoApi.CheckBeams()
end

Scenario.UpdateProgressiveItemModels()
Expand Down
31 changes: 31 additions & 0 deletions src/open_samus_returns_rando/pickups/multiworld_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

from open_samus_returns_rando.files import files_path
from open_samus_returns_rando.lua_editor import get_parent_for
from open_samus_returns_rando.misc_patches.lua_util import lua_convert


def get_lua_for_item(progression: list[list[dict[str, str | int]]], region_name: str) -> str:
generic_pickup = """
Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false)
MultiworldPickup = MultiworldPickup or {}
function MultiworldPickup.main()
end
function MultiworldPickup.OnPickedUp(progression, actorOrName, regionName)
RandomizerPowerup.OnPickedUp(progression, actorOrName, regionName)
end
"""

main_item_id = str(progression[0][0]["item_id"])
parent = get_parent_for(main_item_id)
if parent == "RandomizerPowerup":
parent_content = generic_pickup
else:
parent_lower = parent.lower()
parent_content = files_path().joinpath("pickups", f"{parent_lower}.lua").read_text()
parent_content = parent_content.replace(parent, "MultiworldPickup")

progression_as_lua = lua_convert(progression, True)
return (f'{parent_content}\nMultiworldPickup.OnPickedUp({progression_as_lua},nil,{region_name})'
.replace("\n", "\\\n").replace("'", "\\'")
)
4 changes: 2 additions & 2 deletions src/open_samus_returns_rando/samus_returns_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mercury_engine_data_structures.file_tree_editor import OutputFormat

from open_samus_returns_rando.debug import debug_custom_pickups, debug_spawn_points
from open_samus_returns_rando.exefs_patches import create_exefs_patches
from open_samus_returns_rando.files import files_path
from open_samus_returns_rando.logger import LOG
from open_samus_returns_rando.lua_editor import LuaEditor
Expand All @@ -17,7 +18,6 @@
from open_samus_returns_rando.misc_patches.final_boss import patch_final_boss
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
from open_samus_returns_rando.multiworld_integration import create_exefs_patches
from open_samus_returns_rando.patcher_editor import PatcherEditor
from open_samus_returns_rando.pickups.custom_pickups import patch_custom_pickups
from open_samus_returns_rando.pickups.pickup import patch_pickups
Expand Down Expand Up @@ -153,7 +153,7 @@ def patch_extracted(input_path: Path, output_path: Path, configuration: dict) ->
out_code = output_path.joinpath("code.bin")
out_exheader = output_path.joinpath("exheader.bin")

# Create Exefs patches for multiworld
# Create Exefs patches for multiworld and other binary modifications
LOG.info("Creating exefs patches")
create_exefs_patches(
out_code, out_exheader,
Expand Down

0 comments on commit 8448b97

Please sign in to comment.