Skip to content

Commit

Permalink
making things nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
threeandthreee committed Nov 30, 2024
1 parent d5b0bb6 commit f4bc0af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
48 changes: 21 additions & 27 deletions worlds/ladx/LADXR/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .romTables import ROMWithTables
from . import assembler
from . import mapgen
from . import patches
from .patches import overworld as _
from .patches import dungeon as _
Expand Down Expand Up @@ -58,27 +57,23 @@
from . import hints

from .patches import bank34
from .utils import formatText
from ..Options import TrendyGame, Palette
from .roomEditor import RoomEditor, Object
from .patches.aesthetics import rgb_to_bin, bin_to_rgb

from .locations.keyLocation import KeyLocation

from BaseClasses import ItemClassification
from ..Locations import LinksAwakeningLocation
from ..Options import TrendyGame, Palette, MusicChangeCondition, BootsControls
from ..Options import TrendyGame, Palette, MusicChangeCondition


# Function to generate a final rom, this patches the rom with all required patches
def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
random.seed(data["seed"] + player)
def generateRom(base_rom: bytes, args, data: Dict):
random.seed(data["seed"] + data["player"])
multi_key = binascii.unhexlify(data["multi_key"].encode())
item_list = pickle.loads(binascii.unhexlify(data["item_list"].encode()))
ladxr_settings = {x["key"]: x["value"] for x in data["ladxr_settings"]}
ap_options = data["ap_options"]
rom_patches = []
rom = ROMWithTables(base_rom, rom_patches)
rom.player_names = data["player_names"]
rom.player_names = data["other_player_names"]
pymods = []
if args.pymod:
for pymod in args.pymod:
Expand Down Expand Up @@ -133,7 +128,7 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
patches.core.easyColorDungeonAccess(rom)
patches.owl.removeOwlEvents(rom)
patches.enemies.fixArmosKnightAsMiniboss(rom)
patches.bank3e.addBank3E(rom, multi_key, player, data["player_names"])
patches.bank3e.addBank3E(rom, multi_key, data["player"], data["other_player_names"])
patches.bank3f.addBank3F(rom)
patches.bank34.addBank34(rom, item_list)
patches.core.removeGhost(rom)
Expand All @@ -143,9 +138,8 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
patches.core.injectMainLoop(rom)

from ..Options import ShuffleSmallKeys, ShuffleNightmareKeys
# TODO probably cant compare this way
if data["ap_options"]["shuffle_small_keys"] != ShuffleSmallKeys.option_original_dungeon or\
data["ap_options"]["shuffle_nightmare_keys"] != ShuffleNightmareKeys.option_original_dungeon:
if ap_options["shuffle_small_keys"] != ShuffleSmallKeys.option_original_dungeon or\
ap_options["shuffle_nightmare_keys"] != ShuffleNightmareKeys.option_original_dungeon:
patches.inventory.advancedInventorySubscreen(rom)
patches.inventory.moreSlots(rom)
if ladxr_settings["witch"]:
Expand Down Expand Up @@ -196,7 +190,7 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
# patches.reduceRNG.slowdownThreeOfAKind(rom)
patches.reduceRNG.fixHorseHeads(rom)
patches.bomb.onlyDropBombsWhenHaveBombs(rom)
if data["ap_options"]["music_change_condition"] == MusicChangeCondition.option_always:
if ap_options["music_change_condition"] == MusicChangeCondition.option_always:
patches.aesthetics.noSwordMusic(rom)
patches.aesthetics.reduceMessageLengths(rom, random)
patches.aesthetics.allowColorDungeonSpritesEverywhere(rom)
Expand Down Expand Up @@ -248,7 +242,7 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
elif ladxr_settings["quickswap"] == 'b':
patches.core.quickswap(rom, 0)

patches.core.addBootsControls(rom, data["ap_options"]["boots_controls"])
patches.core.addBootsControls(rom, ap_options["boots_controls"])

hints.addHints(rom, random, data["hint_texts"])

Expand Down Expand Up @@ -282,15 +276,15 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
patches.core.addFrameCounter(rom, len(item_list))

patches.core.warpHome(rom) # Needs to be done after setting the start location.
patches.titleScreen.setRomInfo(rom, data, ladxr_settings, player, player_name)
if data["ap_options"]["ap_title_screen"]:
patches.titleScreen.setRomInfo(rom, data, ladxr_settings)
if ap_options["ap_title_screen"]:
patches.titleScreen.setTitleGraphics(rom)
patches.endscreen.updateEndScreen(rom)
patches.aesthetics.updateSpriteData(rom)
if args.doubletrouble:
patches.enemies.doubleTrouble(rom)

if data["ap_options"]["text_shuffle"]:
if ap_options["text_shuffle"]:
buckets = defaultdict(list)
# For each ROM bank, shuffle text within the bank
for n, data in enumerate(rom.texts._PointerTable__data):
Expand All @@ -306,14 +300,14 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
rom.texts[shuffled[bucket_idx][0]] = data


if data["ap_options"]["trendy_game"] != TrendyGame.option_normal:
if ap_options["trendy_game"] != TrendyGame.option_normal:

# TODO: if 0 or 4, 5, remove inaccurate conveyor tiles


room_editor = RoomEditor(rom, 0x2A0)

if data["ap_options"]["trendy_game"] == TrendyGame.option_easy:
if ap_options["trendy_game"] == TrendyGame.option_easy:
# Set physics flag on all objects
for i in range(0, 6):
rom.banks[0x4][0x6F1E + i -0x4000] = 0x4
Expand All @@ -324,7 +318,7 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
# Add new conveyor to "push" yoshi (it's only a visual)
room_editor.objects.append(Object(5, 3, 0xD0))

if data["ap_options"]["trendy_game"] >= TrendyGame.option_harder:
if ap_options["trendy_game"] >= TrendyGame.option_harder:
"""
Data_004_76A0::
db $FC, $00, $04, $00, $00
Expand All @@ -338,12 +332,12 @@ def generateRom(base_rom: bytes, args, data: Dict, player, player_name):
TrendyGame.option_impossible: (3, 16),
}
def speed():
return random.randint(*speeds[data["ap_options"]["trendy_game"]])
return random.randint(*speeds[ap_options["trendy_game"]])
rom.banks[0x4][0x76A0-0x4000] = 0xFF - speed()
rom.banks[0x4][0x76A2-0x4000] = speed()
rom.banks[0x4][0x76A6-0x4000] = speed()
rom.banks[0x4][0x76A8-0x4000] = 0xFF - speed()
if data["ap_options"]["trendy_game"] >= TrendyGame.option_hardest:
if ap_options["trendy_game"] >= TrendyGame.option_hardest:
rom.banks[0x4][0x76A1-0x4000] = 0xFF - speed()
rom.banks[0x4][0x76A3-0x4000] = speed()
rom.banks[0x4][0x76A5-0x4000] = speed()
Expand All @@ -367,10 +361,10 @@ def speed():
for channel in range(3):
color[channel] = color[channel] * 31 // 0xbc

if data["ap_options"]["warp_improvements"]:
patches.core.addWarpImprovements(rom, data["ap_options"]["additional_warp_points"])
if ap_options["warp_improvements"]:
patches.core.addWarpImprovements(rom, ap_options["additional_warp_points"])

palette = data["ap_options"]["palette"]
palette = ap_options["palette"]
if palette != Palette.option_normal:
ranges = {
# Object palettes
Expand Down
10 changes: 5 additions & 5 deletions worlds/ladx/LADXR/patches/titleScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _encode(s):
return result


def setRomInfo(rom, data, ladxr_settings, player, player_name):
def setRomInfo(rom, data, ladxr_settings):
seed_name = data["seed_name"]
try:
seednr = int(data["seed"], 16)
Expand All @@ -37,17 +37,17 @@ def setRomInfo(rom, data, ladxr_settings, player, player_name):
#line_2_hex = _encode(seed[16:])
BASE_DRAWING_AREA = 0x98a0
LINE_WIDTH = 0x20
player_id_text = f"Player {player}:"
player_id_text = f"Player {data['player']}:"
for n in (3, 4):
be = BackgroundEditor(rom, n)
ba = BackgroundEditor(rom, n, attributes=True)

for n, v in enumerate(_encode(player_id_text)):
be.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 5 + 2 + n] = v
ba.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 5 + 2 + n] = 0x00
for n, v in enumerate(_encode(player_name)):
be.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 6 + 0x13 - len(player_name) + n] = v
ba.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 6 + 0x13 - len(player_name) + n] = 0x00
for n, v in enumerate(_encode(data['player_name'])):
be.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 6 + 0x13 - len(data['player_name']) + n] = v
ba.tiles[BASE_DRAWING_AREA + LINE_WIDTH * 6 + 0x13 - len(data['player_name']) + n] = 0x00
for n, v in enumerate(line_1_hex):
be.tiles[0x9a20 + n] = v
ba.tiles[0x9a20 + n] = 0x00
Expand Down
6 changes: 4 additions & 2 deletions worlds/ladx/Rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def generate_rom(caller: worlds.Files.APProcedurePatch, rom: bytes, data_file: s
out_name = f"{data['out_base']}{caller.result_file_ending}"
parser = get_parser()
args = parser.parse_args([rom_name, "-o", out_name, "--dump"])
return generator.generateRom(rom, args, data, caller.player, caller.player_name)
return generator.generateRom(rom, args, data)

@staticmethod
def patch_title_screen(caller: worlds.Files.APProcedurePatch, rom: bytes, data_file: str) -> bytes:
Expand Down Expand Up @@ -63,7 +63,9 @@ def write_patch_data(world: "LinksAwakeningWorld", patch: LADXProcedurePatch):
"seed": world.multiworld.seed,
"seed_name": world.multiworld.seed_name,
"multi_key": binascii.hexlify(world.multi_key).decode(),
"player_names": list(world.multiworld.player_name.values()),
"player": patch.player,
"player_name": patch.player_name,
"other_player_names": list(world.multiworld.player_name.values()),
"item_list": binascii.hexlify(item_list).decode(),
"hint_texts": generate_hint_texts(world),
"world_setup": {
Expand Down
4 changes: 2 additions & 2 deletions worlds/ladx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .Locations import (LinksAwakeningLocation, LinksAwakeningRegion,
create_regions_from_ladxr, get_locations_to_id)
from .Options import DungeonItemShuffle, ShuffleInstruments, LinksAwakeningOptions, ladx_option_groups
from .Rom import LADXProcedurePatch, write_patch_data, LADX_HASH
from .Rom import LADXProcedurePatch, write_patch_data

DEVELOPER_MODE = False

Expand All @@ -29,7 +29,7 @@ class RomFile(settings.UserFilePath):
"""File name of the Link's Awakening DX rom"""
copy_to = "Legend of Zelda, The - Link's Awakening DX (USA, Europe) (SGB Enhanced).gbc"
description = "LADX ROM File"
md5s = [LADX_HASH]
md5s = [LADXProcedurePatch.hash]

class RomStart(str):
"""
Expand Down

0 comments on commit f4bc0af

Please sign in to comment.