From 07df9b9e80d859892fba00afe10dfa717993af96 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 2 Jan 2021 16:44:58 +0100 Subject: [PATCH] Text Plando Support --- BaseClasses.py | 1 + EntranceRandomizer.py | 5 +++-- Main.py | 1 + Mystery.py | 7 +++++++ Rom.py | 7 +++++++ Text.py | 4 ++++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 458bf46e..db0ab667 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -136,6 +136,7 @@ class World(object): set_player_attr('dark_room_logic', "lamp") set_player_attr('restrict_dungeon_item_on_boss', False) set_player_attr('plando_items', []) + set_player_attr('plando_texts', {}) def secure(self): self.random = secrets.SystemRandom() diff --git a/EntranceRandomizer.py b/EntranceRandomizer.py index 6c94351e..f06bb7ad 100755 --- a/EntranceRandomizer.py +++ b/EntranceRandomizer.py @@ -357,7 +357,8 @@ def parse_arguments(argv, no_defaults=False): ret = parser.parse_args(argv) # cannot be set through CLI currently - ret.plando_items = {} + ret.plando_items = [] + ret.plando_texts = {} ret.glitch_boots = not ret.disable_glitch_boots if ret.timer == "none": @@ -386,7 +387,7 @@ def parse_arguments(argv, no_defaults=False): 'shufflebosses', 'enemy_shuffle', 'enemy_health', 'enemy_damage', 'shufflepots', 'ow_palettes', 'uw_palettes', 'sprite', 'disablemusic', 'quickswap', 'fastmenu', 'heartcolor', 'heartbeep', "skip_progression_balancing", "triforce_pieces_available", - "triforce_pieces_required", "shop_shuffle", "plando_items", + "triforce_pieces_required", "shop_shuffle", "plando_items", "plando_texts", 'remote_items', 'progressive', 'dungeon_counters', 'glitch_boots', 'killable_thieves', 'tile_shuffle', 'bush_shuffle', 'shuffle_prizes', 'sprite_pool', 'dark_room_logic', 'restrict_dungeon_item_on_boss', diff --git a/Main.py b/Main.py index 28218982..1f80f754 100644 --- a/Main.py +++ b/Main.py @@ -88,6 +88,7 @@ def main(args, seed=None): world.sprite_pool = args.sprite_pool.copy() world.dark_room_logic = args.dark_room_logic.copy() world.plando_items = args.plando_items.copy() + world.plando_texts = args.plando_texts.copy() world.restrict_dungeon_item_on_boss = args.restrict_dungeon_item_on_boss.copy() world.rom_seeds = {player: random.Random(world.random.randint(0, 999999999)) for player in range(1, world.players + 1)} diff --git a/Mystery.py b/Mystery.py index 3e7ab91c..474067e2 100644 --- a/Mystery.py +++ b/Mystery.py @@ -559,6 +559,13 @@ def roll_settings(weights, plando_options: typing.Set[str] = frozenset(("bosses" location_world = get_choice("world", placement, False) ret.plando_items.append(PlandoItem(item, location, location_world, from_pool)) + ret.plando_texts = {} + if "texts" in plando_options: + options = weights.get("plando_texts", []) + for placement in options: + if roll_percentage(get_choice("percentage", placement, 100)): + ret.plando_texts[str(get_choice("at", placement))] = str(get_choice("text", placement)) + if 'rom' in weights: romweights = weights['rom'] diff --git a/Rom.py b/Rom.py index 1245557e..0927fc6c 100644 --- a/Rom.py +++ b/Rom.py @@ -2208,6 +2208,13 @@ def write_strings(rom, world, player, team): tt['menu_start_2'] = "{MENU}\n{SPEED0}\n≥@'s house\n Dark Chapel\n{CHOICE3}" tt['menu_start_3'] = "{MENU}\n{SPEED0}\n≥@'s house\n Dark Chapel\n Mountain Cave\n{CHOICE2}" + for at, text in world.plando_texts[player].items(): + + if at not in tt: + raise Exception(f"No text target \"{at}\" found.") + else: + tt[at] = text + rom.write_bytes(0xE0000, tt.getBytes()) credits = Credits() diff --git a/Text.py b/Text.py index fc36506a..a2fd674c 100644 --- a/Text.py +++ b/Text.py @@ -1286,6 +1286,7 @@ class LargeCreditBottomMapper(CharTextMapper): class TextTable(object): SIZE = 0x7355 + def __init__(self): self._text = OrderedDict() self.setDefaultText() @@ -1293,6 +1294,9 @@ class TextTable(object): def __getitem__(self, key): return self._text[key] + def __contains__(self, key): + return key in self._text + def __setitem__(self, key, value): if not key in self._text: raise KeyError(key)