From f4bc0aff86bae5b7da6c7ff823fc9a276c459486 Mon Sep 17 00:00:00 2001 From: threeandthreee Date: Sat, 30 Nov 2024 13:53:42 -0500 Subject: [PATCH] making things nicer --- worlds/ladx/LADXR/generator.py | 48 +++++++++++------------- worlds/ladx/LADXR/patches/titleScreen.py | 10 ++--- worlds/ladx/Rom.py | 6 ++- worlds/ladx/__init__.py | 4 +- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/worlds/ladx/LADXR/generator.py b/worlds/ladx/LADXR/generator.py index 91548fed82fc..82ef972431fa 100644 --- a/worlds/ladx/LADXR/generator.py +++ b/worlds/ladx/LADXR/generator.py @@ -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 _ @@ -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: @@ -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) @@ -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"]: @@ -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) @@ -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"]) @@ -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): @@ -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 @@ -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 @@ -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() @@ -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 diff --git a/worlds/ladx/LADXR/patches/titleScreen.py b/worlds/ladx/LADXR/patches/titleScreen.py index 398b3a4b5baa..b7b1b4c14df2 100644 --- a/worlds/ladx/LADXR/patches/titleScreen.py +++ b/worlds/ladx/LADXR/patches/titleScreen.py @@ -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) @@ -37,7 +37,7 @@ 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) @@ -45,9 +45,9 @@ def setRomInfo(rom, data, ladxr_settings, player, player_name): 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 diff --git a/worlds/ladx/Rom.py b/worlds/ladx/Rom.py index 19ec6b4053c4..256bb982d367 100644 --- a/worlds/ladx/Rom.py +++ b/worlds/ladx/Rom.py @@ -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: @@ -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": { diff --git a/worlds/ladx/__init__.py b/worlds/ladx/__init__.py index 5cfbc3f474e8..63f30aa4144e 100644 --- a/worlds/ladx/__init__.py +++ b/worlds/ladx/__init__.py @@ -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 @@ -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): """