From 05209e3501d5a5c1041cd9c8b43266d001ea0a0b Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Wed, 15 Jul 2026 11:59:41 +0100 Subject: [PATCH 01/15] First commit to making a client menu --- worlds/portal2/client/P2Context.py | 103 +++++++++++++++++++++++++ worlds/portal2/client/Portal2Client.py | 7 +- 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 worlds/portal2/client/P2Context.py diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py new file mode 100644 index 00000000000..41fe23ef818 --- /dev/null +++ b/worlds/portal2/client/P2Context.py @@ -0,0 +1,103 @@ +tracker_loaded = False +try: + from worlds.tracker.TrackerClient import TrackerGameContext as CommonContext, TrackerCommandProcessor as ClientCommandProcessor + tracker_loaded = True +except ModuleNotFoundError: + from CommonClient import CommonContext, ClientCommandProcessor +from kvui import GameManager, ScrollBox +from kivymd.uix.gridlayout import MDGridLayout +from kivymd.uix.button import MDButton, MDButtonText +from kivy.metrics import dp + +class P2ClientCommandProcessor(ClientCommandProcessor): + + def __init__(self, context: "P2CommonContext"): + super().__init__(context) + + +class MenuLayout(MDGridLayout): + + def __init__(self): + super().__init__(rows=1, cols=2) + self.build() + + def set_map_data(self, map_data: dict): + """ + - Set the map data + - Update the menu + """ + + def build(self): + """ + - List of chapter buttons on the left side + - Add a dynamic list of map buttons on the right side of the grid that updates based on the selected chapter + """ + + self.clear_widgets() + self.chapter_area = MDGridLayout(rows=8, cols=1) + self.map_area = ScrollBox() + self.map_area.layout.orientation = "vertical" + self.map_area.layout.spacing = dp(3) + self.map_area.scroll_type = ["bars"] + self.map_area.do_scroll_x = False + self.add_widget(self.chapter_area) + self.add_widget(self.map_area) + + for chapter in range(1, 9): + chapter_button = MDButton( + MDButtonText(text=f"Chapter {chapter}"), + on_release=lambda btn, chapter=chapter: self.select_chapter(f"Chapter {chapter}"), + ) + self.chapter_area.add_widget(chapter_button) + + def select_chapter(self, chapter_name: str): + """ + - Remove the old map buttons + - Add the list of new map buttons + """ + + for child in self.map_area.layout.children[:]: + self.map_area.layout.remove_widget(child) + + # Test code + for map_name in range(1, 21): + map_button = MDButton( + MDButtonText(text=f"{chapter_name} - Map {map_name}"), + on_release=lambda btn, map_name=map_name: self.select_map(f"{chapter_name} - Map {map_name}"), + ) + self.map_area.layout.add_widget(map_button) + + def select_map(self, map_name: str): + """ + - Handle the selection of a map button + - Send map command to the game to load the selected map + """ + + +class P2GameManager(GameManager): + def build(self): + container = super().build() + + game_menu = self.add_client_tab("Maps", MenuLayout()) + self.log_panels["Maps"] = game_menu.content + + return container + + +class P2CommonContext(CommonContext): + + def make_gui(self) -> "type[kvui.GameManager]": + """ + To return the Kivy `App` class needed for `run_gui` so it can be overridden before being built + + Common changes are changing `base_title` to update the window title of the client and + updating `logging_pairs` to automatically make new tabs that can be filled with their respective logger. + + ex. `logging_pairs.append(("Foo", "Bar"))` + will add a "Bar" tab which follows the logger returned from `logging.getLogger("Foo")` + """ + + class TextManager(P2GameManager): + base_title = "Portal 2 Text Client" + + return TextManager \ No newline at end of file diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index eddc04d688d..a5676181642 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -5,12 +5,7 @@ import time import typing -tracker_loaded = False -try: - from worlds.tracker.TrackerClient import TrackerGameContext as CommonContext, TrackerCommandProcessor as ClientCommandProcessor - tracker_loaded = True -except ModuleNotFoundError: - from CommonClient import CommonContext, ClientCommandProcessor +from .P2Context import P2CommonContext as CommonContext, P2ClientCommandProcessor as ClientCommandProcessor, tracker_loaded from CommonClient import server_loop, logger, gui_enabled from NetUtils import ClientStatus, NetworkItem From e8d023b0bf030afe82cc72eca45331f1d49cc5bb Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Mon, 27 Jul 2026 10:13:59 +0100 Subject: [PATCH 02/15] updated client map menu --- worlds/portal2/client/P2Context.py | 163 +++++++++++++++--- worlds/portal2/client/Portal2Client.py | 45 ++--- worlds/portal2/mod_helpers/MapMenu.py | 37 +++- worlds/portal2/test/test_base_menu.py | 6 +- .../test/test_menu_additional_checks.py | 6 +- 5 files changed, 203 insertions(+), 54 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 41fe23ef818..a860abbcf0f 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -1,40 +1,129 @@ tracker_loaded = False try: - from worlds.tracker.TrackerClient import TrackerGameContext as CommonContext, TrackerCommandProcessor as ClientCommandProcessor + from worlds.tracker.TrackerClient import ( + TrackerGameContext as CommonContext, + TrackerCommandProcessor as ClientCommandProcessor, + ) + tracker_loaded = True except ModuleNotFoundError: from CommonClient import CommonContext, ClientCommandProcessor +import asyncio +import logging + +from Utils import async_start from kvui import GameManager, ScrollBox +from kivy.metrics import dp from kivymd.uix.gridlayout import MDGridLayout from kivymd.uix.button import MDButton, MDButtonText -from kivy.metrics import dp +from kivymd.uix.label import MDLabel + +from .. import Portal2World + +HOST = "localhost" +PORT = int(Portal2World.settings.default_portal2_port) + +logger = logging.getLogger("Portal2Client") + +async def send_instant_command(command: str): + try: + _, writer = await asyncio.open_connection(HOST, PORT) + writer.write((command + "\n").encode()) + await writer.drain() + writer.close() + await writer.wait_closed() + except: + logger.error(f"Connection to portal 2 failed for instant command") + class P2ClientCommandProcessor(ClientCommandProcessor): def __init__(self, context: "P2CommonContext"): super().__init__(context) +class MapInfo(MDGridLayout): + + def __init__(self, map_data: dict): + super().__init__(rows=2, cols=1, padding=[0, 50]) + self.map_data = map_data + self.build() + + def build(self): + chapter_info_string = f"{self.map_data["title"]}\n\nRequired Items:\n" + + if self.map_data["required_items"]: + chapter_info_string += ', '.join(self.map_data["required_items"]) + else: + chapter_info_string += "All required items acquired" + + chapter_info_string += "\n\n" + + if self.map_data["sub_locations"]: + chapter_info_string += "Sublocations:\n" + sub_locations_incomplete = [name for name, complete in self.map_data["sub_locations"].items() if not complete] + if sub_locations_incomplete: + chapter_info_string += ', '.join(sub_locations_incomplete) + else: + chapter_info_string += "All sublocations completed" + + self.chapter_info = MDLabel(text=chapter_info_string) + + if self.map_data["disabled"]: + self.play_map_button = MDButton( + MDButtonText(text="Map not yet available"), + disabled=True + ) + else: + self.play_map_button = MDButton( + MDButtonText(text="Play Map"), + on_release=lambda btn: self.select_map() + ) + + + # Add all these to the layout + self.add_widget(self.chapter_info) + self.add_widget(self.play_map_button) + + + def select_map(self): + """ + Send map command to the game to load the selected map + """ + + async_start(send_instant_command(f"{self.map_data['command']}"), "send_map_command") + class MenuLayout(MDGridLayout): def __init__(self): - super().__init__(rows=1, cols=2) - self.build() + super().__init__(rows=1, cols=3) + self.menu_info = [] + self.current_chapter = None + self.map_area = None + self.map_info = None - def set_map_data(self, map_data: dict): + def update_menu(self, menu_data: dict[str, dict]): """ - Set the map data - Update the menu """ + self.menu_info = menu_data + + selected_chapter = self.current_chapter or list(self.menu_info.keys())[0] + if self.map_area is not None: + self.select_chapter(selected_chapter) def build(self): """ - List of chapter buttons on the left side - Add a dynamic list of map buttons on the right side of the grid that updates based on the selected chapter """ + + if self.menu_info is None: + raise Exception("Menu data not set. Call update_menu() once before build().") self.clear_widgets() - self.chapter_area = MDGridLayout(rows=8, cols=1) + self.chapter_area = MDGridLayout(rows=9, cols=1) self.map_area = ScrollBox() self.map_area.layout.orientation = "vertical" self.map_area.layout.spacing = dp(3) @@ -43,10 +132,12 @@ def build(self): self.add_widget(self.chapter_area) self.add_widget(self.map_area) - for chapter in range(1, 9): + for chapter_name in self.menu_info.keys(): chapter_button = MDButton( - MDButtonText(text=f"Chapter {chapter}"), - on_release=lambda btn, chapter=chapter: self.select_chapter(f"Chapter {chapter}"), + MDButtonText(text=chapter_name), + on_release=lambda btn, chapter=chapter_name: self.select_chapter( + chapter + ), ) self.chapter_area.add_widget(chapter_button) @@ -55,23 +146,54 @@ def select_chapter(self, chapter_name: str): - Remove the old map buttons - Add the list of new map buttons """ + + if self.map_area is None: + raise Exception("Map area not initialized. Call build() before select_chapter().") + + self.current_chapter = chapter_name for child in self.map_area.layout.children[:]: self.map_area.layout.remove_widget(child) + + if not self.menu_info: + no_maps_label = MDButton( + MDButtonText(text="No maps available for this chapter"), + disabled=True, + ) + self.map_area.layout.add_widget(no_maps_label) + return - # Test code - for map_name in range(1, 21): + map_data = self.menu_info[chapter_name] + disable_map = False + for map in map_data: map_button = MDButton( - MDButtonText(text=f"{chapter_name} - Map {map_name}"), - on_release=lambda btn, map_name=map_name: self.select_map(f"{chapter_name} - Map {map_name}"), + MDButtonText(text=map['title']), + on_release=lambda btn, _map_name=map['title']: self.select_map( + _map_name, + ) ) self.map_area.layout.add_widget(map_button) + map["disabled"] = disable_map + disable_map = not map["completed"] def select_map(self, map_name: str): """ - Handle the selection of a map button - Send map command to the game to load the selected map """ + maps = self.menu_info[self.current_chapter] + map_data = next((map for map in maps if map["title"] == map_name), None) + + if not map_data: + print(f"Map '{map_name}' not found in chapter '{self.current_chapter}'") + return + + # Replace the map info area + if self.map_info: + self.remove_widget(self.map_info) + + self.map_info = MapInfo(map_data) + self.add_widget(self.map_info) class P2GameManager(GameManager): @@ -87,17 +209,10 @@ def build(self): class P2CommonContext(CommonContext): def make_gui(self) -> "type[kvui.GameManager]": - """ - To return the Kivy `App` class needed for `run_gui` so it can be overridden before being built - - Common changes are changing `base_title` to update the window title of the client and - updating `logging_pairs` to automatically make new tabs that can be filled with their respective logger. - - ex. `logging_pairs.append(("Foo", "Bar"))` - will add a "Bar" tab which follows the logger returned from `logging.getLogger("Foo")` - """ - class TextManager(P2GameManager): base_title = "Portal 2 Text Client" - return TextManager \ No newline at end of file + return TextManager + + def get_menu(self) -> "MenuLayout": + return self.ui.log_panels["Maps"] diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index a5676181642..7e0b8d3e08b 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -5,14 +5,14 @@ import time import typing -from .P2Context import P2CommonContext as CommonContext, P2ClientCommandProcessor as ClientCommandProcessor, tracker_loaded +from .P2Context import MenuLayout, P2CommonContext as CommonContext, P2ClientCommandProcessor as ClientCommandProcessor, tracker_loaded, HOST, PORT, send_instant_command from CommonClient import server_loop, logger, gui_enabled from NetUtils import ClientStatus, NetworkItem from Utils import async_start, init_logging from ..mod_helpers.ItemHandling import add_ratman_commands, handle_item, handle_map_start, handle_trap, portal_gun_upgrade_not_inplace, potatos_not_inplace -from ..mod_helpers.MapMenu import Menu +from ..mod_helpers.MapMenu import GameMapMenu from .DeathMessages import get_death_message from ..Locations import location_names_to_map_codes, map_codes_to_location_names, wheatley_maps_to_monitor_names, all_locations_table, wheatley_monitor_table, ratman_den_locations_table from .. import Portal2World @@ -31,7 +31,7 @@ def _cmd_check_connection(self): def _cmd_command(self, *command): """Sends a command to the game. Should not be used unless you get softlocked""" - self.ctx.command_queue.append(' '.join(command) + "\n") + async_start(send_instant_command(' '.join(command)), "send_command") def _cmd_deathlink(self): """Toggles death link for this client""" @@ -85,9 +85,6 @@ class Portal2Context(CommonContext): tags = {"AP"} items_handling = 0b111 # receive all items for /received - HOST = "localhost" - PORT = int(Portal2World.settings.default_portal2_port) - death_link_active = False goal_map_code = "" @@ -101,7 +98,8 @@ class Portal2Context(CommonContext): location_name_to_id: dict[str, int] = None - menu: Menu = None + game_map_menu: GameMapMenu = None + client_map_menu: MenuLayout = None def alert_game_connection(self): if self.check_game_connection(): @@ -116,14 +114,16 @@ def create_level_begin_command(self): def update_menu(self, location_id: int = None): menu_file = Portal2World.settings.menu_file if location_id is not None: - self.menu.complete_check(location_id) + self.game_map_menu.complete_check(location_id) # Write the menu to that file with open(menu_file, "w", encoding='utf-8') as f: - f.write(str(self.menu)) + f.write(str(self.game_map_menu)) + + self.client_map_menu.update_menu(self.game_map_menu.get_menu_info()) def refresh_menu(self): for location_id in self.checked_locations: - self.menu.complete_check(location_id) + self.game_map_menu.complete_check(location_id) self.update_menu() def add_to_in_game_message_queue(self, message: str, color_string: str = None) -> None: @@ -134,7 +134,7 @@ async def p2_message_listener(self): try: while True: try: - reader, writer = await asyncio.open_connection(self.HOST, self.PORT) + reader, writer = await asyncio.open_connection(HOST, PORT) except ConnectionRefusedError: self.listener_active = False await asyncio.sleep(self.current_reconnect_delay) @@ -173,7 +173,7 @@ async def p2_command_sender(self): try: while True: try: - _, writer = await asyncio.open_connection(self.HOST, self.PORT) + _, writer = await asyncio.open_connection(HOST, PORT) except ConnectionRefusedError: self.sender_active = False await asyncio.sleep(self.current_reconnect_delay) @@ -227,7 +227,7 @@ async def p2_command_sender(self): async def is_player_in_map(self): try: - reader, writer = await asyncio.open_connection(self.HOST, self.PORT) + reader, writer = await asyncio.open_connection(HOST, PORT) ping = 'script printl("Pong")\n' writer.write(ping.encode()) await writer.drain() @@ -360,27 +360,28 @@ def handle_slot_data(self, slot_data: dict): if "chapter_dict" in slot_data: if "logic_difficulty" in slot_data: - self.menu = Menu(slot_data["chapter_dict"], self, logic_difficulty=slot_data["logic_difficulty"]) + self.game_map_menu = GameMapMenu(slot_data["chapter_dict"], self, logic_difficulty=slot_data["logic_difficulty"]) else: - self.menu = Menu(slot_data["chapter_dict"], self) + self.game_map_menu = GameMapMenu(slot_data["chapter_dict"], self) + else: raise Exception("chapter_dict not found in slot data") if "game_mode" in slot_data: - self.menu.is_open_world = slot_data["game_mode"] == GameModeOption.OPEN_WORLD + self.game_map_menu.is_open_world = slot_data["game_mode"] == GameModeOption.OPEN_WORLD if "wheatley_monitors" in slot_data: if slot_data["wheatley_monitors"]: - self.menu.has_wheatley_monitors = True + self.game_map_menu.has_wheatley_monitors = True if "ratman_dens" in slot_data: if slot_data["ratman_dens"]: add_ratman_commands() - self.menu.has_ratman_dens = True + self.game_map_menu.has_ratman_dens = True if "vitrified_doors" in slot_data: if slot_data["vitrified_doors"]: - self.menu.has_vitrified_doors = True + self.game_map_menu.has_vitrified_doors = True # Don't remove the portal gun upgrade after pickup if "portal_gun_upgrade_inplace" not in slot_data: @@ -390,8 +391,10 @@ def handle_slot_data(self, slot_data: dict): if "potatos_inplace" not in slot_data: potatos_not_inplace() - self.menu.generate_menu() + self.game_map_menu.generate_menu() + self.client_map_menu = self.get_menu() self.refresh_menu() + self.client_map_menu.build() def on_package(self, cmd, args): super().on_package(cmd, args) @@ -461,7 +464,7 @@ def update_item_remove_commands(self): def make_gui(self): from kvui import GameManager ui = super().make_gui() - ui.base_title = "Portal 2 Text Client" + ui.base_title = "Portal 2 Client" ui.icon = r"worlds/portal2/data/Portalpelago.png" return ui diff --git a/worlds/portal2/mod_helpers/MapMenu.py b/worlds/portal2/mod_helpers/MapMenu.py index 30b845ab2ba..0adf636c2f1 100644 --- a/worlds/portal2/mod_helpers/MapMenu.py +++ b/worlds/portal2/mod_helpers/MapMenu.py @@ -131,6 +131,17 @@ def get_string(self, previous_completed: bool): text = text + self.next_map.get_string(self.completed) return text + + def get_chapter_info(self): + info = { + "completed": self.completed, + "sub_locations": self.sub_location_completion, + "required_items": [item for item in self.required_items if item in self.parent.parent.client.item_list], + "location_id": self.location_id, + "title": self.title[2:], + "command": self.command + } + return info def complete_map(self, map_id: int) -> bool: if self.location_id == map_id: @@ -240,9 +251,22 @@ def complete_sub_location_check(self, sub_location: str): def complete_check(self, location_id: int): if self.first_map: self.first_map.complete_check(location_id) - - -class Menu: + + def get_chapter_info(self): + maps = [] + current_map = self.first_map + while current_map: + maps.append(current_map.get_chapter_info()) + current_map = current_map.next_map + + info = { + "chapter_name": self.title, + "maps": maps + } + return info + + +class GameMapMenu: chapters: list[ChapterMenuElement] = [] def __init__( @@ -284,3 +308,10 @@ def complete_sub_location_check(self, sub_location: str): def complete_check(self, location_id: int): for chapter in self.chapters: chapter.complete_check(location_id) + + def get_menu_info(self) -> dict[str, dict]: + menu_info = {} + for chapter in self.chapters: + chapter_info = chapter.get_chapter_info() + menu_info[chapter_info["chapter_name"]] = chapter_info["maps"] + return menu_info \ No newline at end of file diff --git a/worlds/portal2/test/test_base_menu.py b/worlds/portal2/test/test_base_menu.py index 78dafaf737e..565c6809e96 100644 --- a/worlds/portal2/test/test_base_menu.py +++ b/worlds/portal2/test/test_base_menu.py @@ -2,7 +2,7 @@ from .bases import Portal2TestBase from ..Options import GameModeOption -from ..mod_helpers.MapMenu import Menu +from ..mod_helpers.MapMenu import GameMapMenu from ..Locations import all_locations_table class FakeClient: @@ -28,7 +28,7 @@ def test_menu_generation(self) -> None: slot_data = self.world.fill_slot_data() - menu = Menu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"]) + menu = GameMapMenu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"]) menu.generate_menu() # Check menu is generated where the first map of each chapter says "command" and the rest say "command_deactivated" menu_string = str(menu) @@ -36,7 +36,7 @@ def test_menu_generation(self) -> None: self.assertEqual(menu_string.count('"command"'), 18) def test_menu_no_maps(self) -> None: - menu = Menu({1: [], 2: [], 3: []}, self.client) + menu = GameMapMenu({1: [], 2: [], 3: []}, self.client) menu.generate_menu() menu_string = str(menu) # Check menu is generated where the first map of each chapter says "No Maps In This Chapter" diff --git a/worlds/portal2/test/test_menu_additional_checks.py b/worlds/portal2/test/test_menu_additional_checks.py index 314f4ff1350..c143b37c6ad 100644 --- a/worlds/portal2/test/test_menu_additional_checks.py +++ b/worlds/portal2/test/test_menu_additional_checks.py @@ -3,7 +3,7 @@ from .test_base_menu import FakeClient from .bases import Portal2TestBase from ..Options import GameModeOption -from ..mod_helpers.MapMenu import Menu +from ..mod_helpers.MapMenu import GameMapMenu from ..ItemNames import portal_gun_1, portal_gun_2, potatos from ..mod_helpers.MapMenu import indicator_characters @@ -29,7 +29,7 @@ def test_title_generation(self) -> None: slot_data = self.world.fill_slot_data() - menu = Menu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"], vitrified_doors=slot_data["vitrified_doors"]) + menu = GameMapMenu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"], vitrified_doors=slot_data["vitrified_doors"]) menu.generate_menu() menu_string = str(menu) # Find map that includes Wheatley Monitors in the title and check it is correct @@ -51,7 +51,7 @@ def test_sub_location_completion(self) -> None: slot_data = self.world.fill_slot_data() - menu = Menu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"]) + menu = GameMapMenu(slot_data["chapter_dict"], self.client, is_open_world=slot_data["game_mode"] == GameModeOption.OPEN_WORLD, logic_difficulty=slot_data["logic_difficulty"], wheatley_monitors=slot_data["wheatley_monitors"], ratman_dens=slot_data["ratman_dens"]) menu.generate_menu() # Complete a map with a sub location and check the title updates menu.complete_map(slot_data["location_name_to_id"]["Portal Gun Completion"]) From 970e1adb0252bb0b95d16e6d56e0c055dbff0bae Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Mon, 27 Jul 2026 10:32:32 +0100 Subject: [PATCH 03/15] Fix for open world --- worlds/portal2/client/P2Context.py | 7 ++++++- worlds/portal2/client/Portal2Client.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index a860abbcf0f..fc21dfcd50e 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -101,6 +101,7 @@ def __init__(self): self.current_chapter = None self.map_area = None self.map_info = None + self.is_open_world = False def update_menu(self, menu_data: dict[str, dict]): """ @@ -112,6 +113,9 @@ def update_menu(self, menu_data: dict[str, dict]): selected_chapter = self.current_chapter or list(self.menu_info.keys())[0] if self.map_area is not None: self.select_chapter(selected_chapter) + + def set_open_world(self): + self.is_open_world = True def build(self): """ @@ -174,7 +178,8 @@ def select_chapter(self, chapter_name: str): ) self.map_area.layout.add_widget(map_button) map["disabled"] = disable_map - disable_map = not map["completed"] + if not self.is_open_world: + disable_map = not map["completed"] def select_map(self, map_name: str): """ diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 7e0b8d3e08b..4dbdc8d5cdc 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -368,7 +368,9 @@ def handle_slot_data(self, slot_data: dict): raise Exception("chapter_dict not found in slot data") if "game_mode" in slot_data: - self.game_map_menu.is_open_world = slot_data["game_mode"] == GameModeOption.OPEN_WORLD + if slot_data["game_mode"] == GameModeOption.OPEN_WORLD: + self.game_map_menu.is_open_world = True + self.get_menu().set_open_world() if "wheatley_monitors" in slot_data: if slot_data["wheatley_monitors"]: From 29102d4651c2064bb3a3c3bff08799323dd76396 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Thu, 30 Jul 2026 19:48:34 +0100 Subject: [PATCH 04/15] Added auto go to next map feature --- worlds/portal2/client/P2Context.py | 31 ++++++++++++++++---- worlds/portal2/client/Portal2Client.py | 20 ++++++++++--- worlds/portal2/mod_helpers/MapMenu.py | 40 +++++++++++++++++--------- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index fc21dfcd50e..dfbee193955 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -15,7 +15,7 @@ from kvui import GameManager, ScrollBox from kivy.metrics import dp from kivymd.uix.gridlayout import MDGridLayout -from kivymd.uix.button import MDButton, MDButtonText +from kivymd.uix.button import MDButton, MDButtonText, MDIconButton from kivymd.uix.label import MDLabel from .. import Portal2World @@ -76,7 +76,7 @@ def build(self): else: self.play_map_button = MDButton( MDButtonText(text="Play Map"), - on_release=lambda btn: self.select_map() + on_release=lambda btn: self.play_map() ) @@ -85,7 +85,7 @@ def build(self): self.add_widget(self.play_map_button) - def select_map(self): + def play_map(self): """ Send map command to the game to load the selected map """ @@ -96,12 +96,13 @@ def select_map(self): class MenuLayout(MDGridLayout): def __init__(self): - super().__init__(rows=1, cols=3) + super().__init__(rows=1, cols=3, padding=[40, 10]) self.menu_info = [] self.current_chapter = None self.map_area = None self.map_info = None self.is_open_world = False + self.return_to_menu = False def update_menu(self, menu_data: dict[str, dict]): """ @@ -127,7 +128,7 @@ def build(self): raise Exception("Menu data not set. Call update_menu() once before build().") self.clear_widgets() - self.chapter_area = MDGridLayout(rows=9, cols=1) + self.chapter_area = MDGridLayout(rows=10, cols=1) self.map_area = ScrollBox() self.map_area.layout.orientation = "vertical" self.map_area.layout.spacing = dp(3) @@ -141,9 +142,17 @@ def build(self): MDButtonText(text=chapter_name), on_release=lambda btn, chapter=chapter_name: self.select_chapter( chapter - ), + ) ) self.chapter_area.add_widget(chapter_button) + + menu_toggle_box = MDGridLayout(cols=2, row_default_height=40, row_force_default=True, padding=10) + self.auto_next_map_button = MDIconButton(icon = "checkbox-blank-outline", on_release=self.toggle_switch) + button_label = MDLabel(text="Return to menu on map finish: ") + menu_toggle_box.add_widget(button_label) + menu_toggle_box.add_widget(self.auto_next_map_button) + self.chapter_area.add_widget(menu_toggle_box) + def select_chapter(self, chapter_name: str): """ @@ -199,9 +208,19 @@ def select_map(self, map_name: str): self.map_info = MapInfo(map_data) self.add_widget(self.map_info) + + def toggle_switch(self, instance): + self.return_to_menu = not self.return_to_menu + if self.return_to_menu: + self.auto_next_map_button.icon = "checkbox-outline" + else: + self.auto_next_map_button.icon = "checkbox-blank-outline" + + logger.info(self.return_to_menu) class P2GameManager(GameManager): + def build(self): container = super().build() diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 4dbdc8d5cdc..880f039e1c3 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -113,13 +113,15 @@ def create_level_begin_command(self): def update_menu(self, location_id: int = None): menu_file = Portal2World.settings.menu_file + check_completed = False if location_id is not None: - self.game_map_menu.complete_check(location_id) + check_completed = self.game_map_menu.complete_check(location_id) # Write the menu to that file with open(menu_file, "w", encoding='utf-8') as f: f.write(str(self.game_map_menu)) self.client_map_menu.update_menu(self.game_map_menu.get_menu_info()) + return check_completed def refresh_menu(self): for location_id in self.checked_locations: @@ -239,6 +241,8 @@ async def is_player_in_map(self): if pong and pong[0] == "Pong": return True return False + except asyncio.CancelledError: + raise except: return False @@ -253,13 +257,21 @@ async def handle_message(self, message: str): # For map complete checks elif message.startswith("map_complete:"): done_map = message.split(':', 1)[1] - if done_map == self.goal_map_code: - await self.handle_goal_completion() map_id = self.map_code_to_location_id(done_map) if map_id: await self.check_locations([map_id]) - self.update_menu(map_id) + next_map = self.update_menu(map_id) + + if done_map == self.goal_map_code: + await self.handle_goal_completion() + else: + logger.info(self.client_map_menu.return_to_menu) + logger.info(next_map) + if not self.client_map_menu.return_to_menu and type(next_map) == str: + await send_instant_command(f"changelevel {next_map}") + else: + await send_instant_command("disconnect;startupmenu force") # All other checks # Item checks e.g. portal gun upgrade, potatos diff --git a/worlds/portal2/mod_helpers/MapMenu.py b/worlds/portal2/mod_helpers/MapMenu.py index 0adf636c2f1..8fee0a756cc 100644 --- a/worlds/portal2/mod_helpers/MapMenu.py +++ b/worlds/portal2/mod_helpers/MapMenu.py @@ -94,6 +94,7 @@ class MapMenuElement(MenuElement): def __init__(self, parent, chapter_number, map_number, title, map_code, location_id, required_items, pic): self.location_id = location_id self.required_items = required_items + self.map_code = map_code self.sub_location_completion = get_sub_locations( title, parent.parent.has_wheatley_monitors, parent.parent.has_ratman_dens, parent.parent.has_vitrified_doors ) @@ -143,14 +144,13 @@ def get_chapter_info(self): } return info - def complete_map(self, map_id: int) -> bool: + def complete_map(self, map_id: int) -> str | bool: if self.location_id == map_id: - if self.completed: - return True self.completed = True self.refresh_title() if self.next_map: self.next_map.command = self.next_map.command.replace("command_deactivated", "command") + return self.next_map.map_code return True else: if self.next_map: @@ -162,14 +162,21 @@ def complete_sub_location_check(self, sub_location: str): if sub_location in self.sub_location_completion: self.sub_location_completion[sub_location] = True self.refresh_title() + return True elif self.next_map: - self.next_map.complete_sub_location_check(sub_location) + return self.next_map.complete_sub_location_check(sub_location) + return False + + def complete_check(self, location_id: int) -> str | bool: + map_complete = self.complete_map(location_id) + if map_complete: + return map_complete + + location_name = self.parent.parent.client.location_names.lookup_in_game(location_id) + if "Complete" not in location_name: + return self.complete_sub_location_check(location_name) + return False - def complete_check(self, location_id: int): - if not self.complete_map(location_id): - location_name = self.parent.parent.client.location_names.lookup_in_game(location_id) - if "Complete" not in location_name: - self.complete_sub_location_check(location_name) blank_map_element = lambda parent, chapter_number: MapMenuElement(parent, chapter_number, 0, "No Maps In This Chapter", "", -1, [], "") @@ -248,9 +255,10 @@ def complete_sub_location_check(self, sub_location: str): if self.first_map: self.first_map.complete_sub_location_check(sub_location) - def complete_check(self, location_id: int): + def complete_check(self, location_id: int) -> str | bool: if self.first_map: - self.first_map.complete_check(location_id) + return self.first_map.complete_check(location_id) + return False def get_chapter_info(self): maps = [] @@ -305,13 +313,17 @@ def complete_sub_location_check(self, sub_location: str): for chapter in self.chapters: chapter.complete_sub_location_check(sub_location) - def complete_check(self, location_id: int): + def complete_check(self, location_id: int) -> str | bool: for chapter in self.chapters: - chapter.complete_check(location_id) + found_check = chapter.complete_check(location_id) + if found_check: + return found_check + return False def get_menu_info(self) -> dict[str, dict]: menu_info = {} for chapter in self.chapters: chapter_info = chapter.get_chapter_info() menu_info[chapter_info["chapter_name"]] = chapter_info["maps"] - return menu_info \ No newline at end of file + return menu_info + \ No newline at end of file From 7d02c08c859fca70683441486b8707bace4ed761 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Fri, 31 Jul 2026 21:12:07 +0100 Subject: [PATCH 05/15] Updated sub location names --- worlds/portal2/Locations.py | 94 ++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/worlds/portal2/Locations.py b/worlds/portal2/Locations.py index 43b68f4c79c..8cd07b72b48 100644 --- a/worlds/portal2/Locations.py +++ b/worlds/portal2/Locations.py @@ -145,18 +145,18 @@ class Portal2Location(Location): achievements_table: dict[str, Portal2LocationData] = {} wheatley_monitor_table: dict[str, Portal2LocationData] = { - "Wheatley Monitor 1": Portal2LocationData("sp_a4_tb_intro", LocationType.WHEATLY_MONITOR, [portal_gun_2, funnel, frankenturret]), - "Wheatley Monitor 2": Portal2LocationData("sp_a4_tb_trust_drop", LocationType.WHEATLY_MONITOR, [portal_gun_2, button, funnel, frankenturret]), - "Wheatley Monitor 3": Portal2LocationData("sp_a4_tb_wall_button", LocationType.WHEATLY_MONITOR, [portal_gun_2]), - "Wheatley Monitor 4": Portal2LocationData("sp_a4_tb_polarity", LocationType.WHEATLY_MONITOR, [turrets]), - "Wheatley Monitor 5": Portal2LocationData("sp_a4_tb_catch 1", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor1 - "Wheatley Monitor 6": Portal2LocationData("sp_a4_tb_catch 2", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor2 - "Wheatley Monitor 7": Portal2LocationData("sp_a4_stop_the_box", LocationType.WHEATLY_MONITOR, [faith_plate]), - "Wheatley Monitor 8": Portal2LocationData("sp_a4_laser_catapult", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, faith_plate, funnel, reflection_cube, laser, laser_catcher]), - "Wheatley Monitor 9": Portal2LocationData("sp_a4_laser_platform", LocationType.WHEATLY_MONITOR, [portal_gun_2, laser, laser_catcher, reflection_cube, button]), - "Wheatley Monitor 10": Portal2LocationData("sp_a4_speed_tb_catch", LocationType.WHEATLY_MONITOR, [portal_gun_2]), - "Wheatley Monitor 11": Portal2LocationData("sp_a4_jump_polarity", LocationType.WHEATLY_MONITOR, [portal_gun_2, blue_gel, white_gel, funnel, turrets, floor_button, button]), - "Wheatley Monitor 12": Portal2LocationData("sp_a4_finale3", LocationType.WHEATLY_MONITOR, [portal_gun_2, white_gel]), + "Wheatley Monitor 1 (Funnel Intro)": Portal2LocationData("sp_a4_tb_intro", LocationType.WHEATLY_MONITOR, [portal_gun_2, funnel, frankenturret]), + "Wheatley Monitor 2 (Ceiling Button)": Portal2LocationData("sp_a4_tb_trust_drop", LocationType.WHEATLY_MONITOR, [portal_gun_2, button, funnel, frankenturret]), + "Wheatley Monitor 3 (Wall Button)": Portal2LocationData("sp_a4_tb_wall_button", LocationType.WHEATLY_MONITOR, [portal_gun_2]), + "Wheatley Monitor 4 (Polarity)": Portal2LocationData("sp_a4_tb_polarity", LocationType.WHEATLY_MONITOR, [turrets]), + "Wheatley Monitor 5 (Funnel Catch)": Portal2LocationData("sp_a4_tb_catch 1", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor1 + "Wheatley Monitor 6 (Funnel Catch)": Portal2LocationData("sp_a4_tb_catch 2", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor2 + "Wheatley Monitor 7 (Stop The Box)": Portal2LocationData("sp_a4_stop_the_box", LocationType.WHEATLY_MONITOR, [faith_plate]), + "Wheatley Monitor 8 (Laser Catapult)": Portal2LocationData("sp_a4_laser_catapult", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, faith_plate, funnel, reflection_cube, laser, laser_catcher]), + "Wheatley Monitor 9 (Laser Platform)": Portal2LocationData("sp_a4_laser_platform", LocationType.WHEATLY_MONITOR, [portal_gun_2, laser, laser_catcher, reflection_cube, button]), + "Wheatley Monitor 10 (Propulsion Catch)": Portal2LocationData("sp_a4_speed_tb_catch", LocationType.WHEATLY_MONITOR, [portal_gun_2]), + "Wheatley Monitor 11 (Repulsion Polarity)": Portal2LocationData("sp_a4_jump_polarity", LocationType.WHEATLY_MONITOR, [portal_gun_2, blue_gel, white_gel, funnel, turrets, floor_button, button]), + "Wheatley Monitor 12 (Finale 3)": Portal2LocationData("sp_a4_finale3", LocationType.WHEATLY_MONITOR, [portal_gun_2, white_gel]), } # Note: these are the names used in game to identify the monitors @@ -172,29 +172,29 @@ class Portal2Location(Location): item_maps_to_item_location : dict[str, str] = {value.map_name:key for key, value in item_location_table.items()} ratman_den_locations_table: dict[str, Portal2LocationData] = { - "Ratman Den 1": Portal2LocationData("sp_a1_intro4", LocationType.RATMAN_DEN, [weighted_cube, floor_button]), - "Ratman Den 2": Portal2LocationData("sp_a2_dual_lasers", LocationType.RATMAN_DEN), - "Ratman Den 3": Portal2LocationData("sp_a2_trust_fling", LocationType.RATMAN_DEN, [portal_gun_2, faith_plate]), - "Ratman Den 4": Portal2LocationData("sp_a2_bridge_intro", LocationType.RATMAN_DEN), - "Ratman Den 5": Portal2LocationData("sp_a2_bridge_the_gap", LocationType.RATMAN_DEN, [portal_gun_2, bridge]), - "Ratman Den 6": Portal2LocationData("sp_a2_laser_vs_turret", LocationType.RATMAN_DEN, [portal_gun_2, laser, floor_button, reflection_cube]), - "Ratman Den 7": Portal2LocationData("sp_a2_pull_the_rug", LocationType.RATMAN_DEN, [portal_gun_2, bridge]) + "Ratman Den 1 (Smooth Jazz)": Portal2LocationData("sp_a1_intro4", LocationType.RATMAN_DEN, [weighted_cube, floor_button]), + "Ratman Den 2 (Dual Lasers)": Portal2LocationData("sp_a2_dual_lasers", LocationType.RATMAN_DEN), + "Ratman Den 3 (Trust Fling)": Portal2LocationData("sp_a2_trust_fling", LocationType.RATMAN_DEN, [portal_gun_2, faith_plate]), + "Ratman Den 4 (Bridge Intro)": Portal2LocationData("sp_a2_bridge_intro", LocationType.RATMAN_DEN), + "Ratman Den 5 (Bridge the Gap)": Portal2LocationData("sp_a2_bridge_the_gap", LocationType.RATMAN_DEN, [portal_gun_2, bridge]), + "Ratman Den 6 (Laser Vs. Turret)": Portal2LocationData("sp_a2_laser_vs_turret", LocationType.RATMAN_DEN, [portal_gun_2, laser, floor_button, reflection_cube]), + "Ratman Den 7 (Pull The Rug)": Portal2LocationData("sp_a2_pull_the_rug", LocationType.RATMAN_DEN, [portal_gun_2, bridge]) } ratman_map_to_ratman_den: dict[str, str] = {value.map_name: key for key, value in ratman_den_locations_table.items()} vitrified_door_locations_table: dict[str, Portal2LocationData] = { - "Vitrified Door 1": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 2": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 3": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 4": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 5": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 6": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 1 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 2 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 3 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 4 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 5 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + "Vitrified Door 6 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), } vitrified_map_to_vitrified_door: dict[str, list[str]] = { - "sp_a3_03": ["Vitrified Door 1", "Vitrified Door 2", "Vitrified Door 3"], - "sp_a3_transition01": ["Vitrified Door 4", "Vitrified Door 5", "Vitrified Door 6"] + "sp_a3_03": ["Vitrified Door 1 (Cave Johnson)", "Vitrified Door 2 (Cave Johnson)", "Vitrified Door 3 (Cave Johnson)"], + "sp_a3_transition01": ["Vitrified Door 4 (PotatOS)", "Vitrified Door 5 (PotatOS)", "Vitrified Door 6 (PotatOS)"] } all_locations_table: dict[str, Portal2LocationData] = map_complete_table.copy() @@ -284,24 +284,24 @@ class Portal2Location(Location): sub_locations_in_maps: dict[str, list[str]] = { "Portal Gun Completion": [portal_gun_1], "Incinerator Completion": [portal_gun_2], - "PotatOS Completion": [potatos, "Vitrified Door 4", "Vitrified Door 5", "Vitrified Door 6"], - "Funnel Intro Completion": ["Wheatley Monitor 1"], - "Ceiling Button Completion": ["Wheatley Monitor 2"], - "Wall Button Completion": ["Wheatley Monitor 3"], - "Polarity Completion": ["Wheatley Monitor 4"], - "Funnel Catch Completion": ["Wheatley Monitor 5", "Wheatley Monitor 6"], - "Stop The Box Completion": ["Wheatley Monitor 7"], - "Laser Catapult Completion": ["Wheatley Monitor 8"], - "Laser Platform Completion": ["Wheatley Monitor 9"], - "Propulsion Catch Completion": ["Wheatley Monitor 10"], - "Repulsion Polarity Completion": ["Wheatley Monitor 11"], - "Finale 3 Completion": ["Wheatley Monitor 12"], - "Smooth Jazz Completion": ["Ratman Den 1"], - "Dual Lasers Completion": ["Ratman Den 2"], - "Trust Fling Completion": ["Ratman Den 3"], - "Bridge Intro Completion": ["Ratman Den 4"], - "Bridge the Gap Completion": ["Ratman Den 5"], - "Laser Vs. Turret Completion": ["Ratman Den 6"], - "Pull The Rug Completion": ["Ratman Den 7"], - "Cave Johnson Completion": ["Vitrified Door 1", "Vitrified Door 2", "Vitrified Door 3"], + "PotatOS Completion": [potatos, "Vitrified Door 4 (PotatOS)", "Vitrified Door 5 (PotatOS)", "Vitrified Door 6 (PotatOS)"], + "Funnel Intro Completion": ["Wheatley Monitor 1 (Funnel Intro)"], + "Ceiling Button Completion": ["Wheatley Monitor 2 (Ceiling Button)"], + "Wall Button Completion": ["Wheatley Monitor 3 (Wall Button)"], + "Polarity Completion": ["Wheatley Monitor 4 (Polarity)"], + "Funnel Catch Completion": ["Wheatley Monitor 5 (Funnel Catch)", "Wheatley Monitor 6 (Funnel Catch)"], + "Stop The Box Completion": ["Wheatley Monitor 7 (Stop The Box)"], + "Laser Catapult Completion": ["Wheatley Monitor 8 (Laser Catapult)"], + "Laser Platform Completion": ["Wheatley Monitor 9 (Laser Platform)"], + "Propulsion Catch Completion": ["Wheatley Monitor 10 (Propulsion Catch)"], + "Repulsion Polarity Completion": ["Wheatley Monitor 11 (Repulsion Polarity)"], + "Finale 3 Completion": ["Wheatley Monitor 12 (Finale 3)"], + "Smooth Jazz Completion": ["Ratman Den 1 (Smooth Jazz)"], + "Dual Lasers Completion": ["Ratman Den 2 (Dual Lasers)"], + "Trust Fling Completion": ["Ratman Den 3 (Trust Fling)"], + "Bridge Intro Completion": ["Ratman Den 4 (Bridge Intro)"], + "Bridge the Gap Completion": ["Ratman Den 5 (Bridge the Gap)"], + "Laser Vs. Turret Completion": ["Ratman Den 6 (Laser Vs. Turret)"], + "Pull The Rug Completion": ["Ratman Den 7 (Pull The Rug)"], + "Cave Johnson Completion": ["Vitrified Door 1 (Cave Johnson)", "Vitrified Door 2 (Cave Johnson)", "Vitrified Door 3 (Cave Johnson)"], } From d0af243ca371ddd7a3f2a6bb172f07c8b8138202 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Fri, 31 Jul 2026 21:16:10 +0100 Subject: [PATCH 06/15] Exception handling and proper closing of pinger --- worlds/portal2/client/P2Context.py | 2 +- worlds/portal2/client/Portal2Client.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index dfbee193955..0c266f8e066 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -59,7 +59,7 @@ def build(self): chapter_info_string += "\n\n" if self.map_data["sub_locations"]: - chapter_info_string += "Sublocations:\n" + chapter_info_string += "Sub locations:\n" sub_locations_incomplete = [name for name, complete in self.map_data["sub_locations"].items() if not complete] if sub_locations_incomplete: chapter_info_string += ', '.join(sub_locations_incomplete) diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 880f039e1c3..82efdbff6c0 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -236,15 +236,17 @@ async def is_player_in_map(self): data = await asyncio.wait_for(reader.read(1000), timeout=0.5) pong = data.decode(errors="ignore").replace("\'", "").split('\r\n') - writer.close() - await writer.wait_closed() if pong and pong[0] == "Pong": return True return False except asyncio.CancelledError: + logger.info("Game pinger closed from cancellation") raise except: return False + finally: + writer.close() + await writer.wait_closed() async def handle_message(self, message: str): if message.startswith("map_name:"): From 8d76337fb8664a2da7e40c81eeec588b716064a2 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Fri, 31 Jul 2026 22:30:37 +0100 Subject: [PATCH 07/15] Added check counts to chapters and maps --- worlds/portal2/client/P2Context.py | 12 +++++++++--- worlds/portal2/mod_helpers/MapMenu.py | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 0c266f8e066..a22302d670d 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -137,9 +137,15 @@ def build(self): self.add_widget(self.chapter_area) self.add_widget(self.map_area) - for chapter_name in self.menu_info.keys(): + for chapter_name, maps in self.menu_info.items(): + total_checks = 0 + finished_checks = 0 + for map in maps: + total_checks += map["total_locations"] + finished_checks += map["finished_locations"] + chapter_button = MDButton( - MDButtonText(text=chapter_name), + MDButtonText(text=f"{chapter_name} {finished_checks}/{total_checks}"), on_release=lambda btn, chapter=chapter_name: self.select_chapter( chapter ) @@ -180,7 +186,7 @@ def select_chapter(self, chapter_name: str): disable_map = False for map in map_data: map_button = MDButton( - MDButtonText(text=map['title']), + MDButtonText(text=f"{map['title']} {map["finished_locations"]}/{map["total_locations"]}"), on_release=lambda btn, _map_name=map['title']: self.select_map( _map_name, ) diff --git a/worlds/portal2/mod_helpers/MapMenu.py b/worlds/portal2/mod_helpers/MapMenu.py index 8fee0a756cc..9b8e2d17ba0 100644 --- a/worlds/portal2/mod_helpers/MapMenu.py +++ b/worlds/portal2/mod_helpers/MapMenu.py @@ -102,6 +102,7 @@ def __init__(self, parent, chapter_number, map_number, title, map_code, location new_title = title.removesuffix(" Completion") super().__init__(parent, f"chapter {chapter_number}.{map_number}", new_title, subtitle, f"map {map_code}", pic) self.info_text = indicator_characters["map"] + parse_sub_locations(self.sub_location_completion) + self.total_locations = len(self.sub_location_completion) + 1 def refresh_title(self, blocked: bool = False): self.info_text = indicator_characters["completed"] if self.completed else indicator_characters["map"] @@ -140,7 +141,9 @@ def get_chapter_info(self): "required_items": [item for item in self.required_items if item in self.parent.parent.client.item_list], "location_id": self.location_id, "title": self.title[2:], - "command": self.command + "command": self.command, + "total_locations": self.total_locations, + "finished_locations": (1 if self.completed else 0) + len([name for name, complete in self.sub_location_completion.items() if complete]) } return info From fdaed365824aabcf27f5d47937ddc66354cfcdc1 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 00:24:04 +0100 Subject: [PATCH 08/15] Formalised location names, update client menu on check --- worlds/portal2/LocationNames.py | 96 ++++++ worlds/portal2/Locations.py | 341 +++++++++++---------- worlds/portal2/client/P2Context.py | 67 ++-- worlds/portal2/mod_helpers/ItemHandling.py | 15 +- 4 files changed, 324 insertions(+), 195 deletions(-) create mode 100644 worlds/portal2/LocationNames.py diff --git a/worlds/portal2/LocationNames.py b/worlds/portal2/LocationNames.py new file mode 100644 index 00000000000..761b4b4e31a --- /dev/null +++ b/worlds/portal2/LocationNames.py @@ -0,0 +1,96 @@ +# map completion checks +container_ride_completion = "Container Ride Completion" +portal_carousel_completion = "Portal Carousel Completion" +portal_gun_completion = "Portal Gun Completion" +smooth_jazz_completion = "Smooth Jazz Completion" +cube_momentum_completion = "Cube Momentum Completion" +future_starter_completion = "Future Starter Completion" +secret_panel_completion = "Secret Panel Completion" +wake_up_completion = "Wake Up Completion" +incinerator_completion = "Incinerator Completion" +laser_intro_completion = "Laser Intro Completion" +laser_stairs_completion = "Laser Stairs Completion" +dual_lasers_completion = "Dual Lasers Completion" +laser_over_goo_completion = "Laser Over Goo Completion" +catapult_intro_completion = "Catapult Intro Completion" +trust_fling_completion = "Trust Fling Completion" +pit_flings_completion = "Pit Flings Completion" +fizzler_intro_completion = "Fizzler Intro Completion" +ceiling_catapult_completion = "Ceiling Catapult Completion" +ricochet_completion = "Ricochet Completion" +bridge_intro_completion = "Bridge Intro Completion" +bridge_the_gap_completion = "Bridge the Gap Completion" +turret_intro_completion = "Turret Intro Completion" +laser_relays_completion = "Laser Relays Completion" +turret_blocker_completion = "Turret Blocker Completion" +laser_vs_turret_completion = "Laser Vs. Turret Completion" +pull_the_rug_completion = "Pull The Rug Completion" +column_blocker_completion = "Column Blocker Completion" +laser_chaining_completion = "Laser Chaining Completion" +triple_laser_completion = "Triple Laser Completion" +jailbreak_completion = "Jailbreak Completion" +escape_completion = "Escape Completion" +turret_factory_completion = "Turret Factory Completion" +turret_sabotage_completion = "Turret Sabotage Completion" +neurotoxin_sabotage_completion = "Neurotoxin Sabotage Completion" +core_completion = "Core Completion" +underground_completion = "Underground Completion" +cave_johnson_completion = "Cave Johnson Completion" +repulsion_intro_completion = "Repulsion Intro Completion" +bomb_flings_completion = "Bomb Flings Completion" +crazy_box_completion = "Crazy Box Completion" +potatos_completion = "PotatOS Completion" +propulsion_intro_completion = "Propulsion Intro Completion" +propulsion_flings_completion = "Propulsion Flings Completion" +conversion_intro_completion = "Conversion Intro Completion" +three_gels_completion = "Three Gels Completion" +test_completion = "Test Completion" +funnel_intro_completion = "Funnel Intro Completion" +ceiling_button_completion = "Ceiling Button Completion" +wall_button_completion = "Wall Button Completion" +polarity_completion = "Polarity Completion" +funnel_catch_completion = "Funnel Catch Completion" +stop_the_box_completion = "Stop The Box Completion" +laser_catapult_completion = "Laser Catapult Completion" +laser_platform_completion = "Laser Platform Completion" +propulsion_catch_completion = "Propulsion Catch Completion" +repulsion_polarity_completion = "Repulsion Polarity Completion" +finale_1_completion = "Finale 1 Completion" +finale_2_completion = "Finale 2 Completion" +finale_3_completion = "Finale 3 Completion" +finale_4_completion = "Finale 4 Completion" + +# optional checks +tube_ride_completion = "Tube Ride Completion" +long_fall_completion = "Long Fall Completion" + +# wheatley monitors +wheatley_monitor_1_funnel_intro = "Wheatley Monitor 1 (Funnel Intro)" +wheatley_monitor_2_ceiling_button = "Wheatley Monitor 2 (Ceiling Button)" +wheatley_monitor_3_wall_button = "Wheatley Monitor 3 (Wall Button)" +wheatley_monitor_4_polarity = "Wheatley Monitor 4 (Polarity)" +wheatley_monitor_5_funnel_catch = "Wheatley Monitor 5 (Funnel Catch)" +wheatley_monitor_6_funnel_catch = "Wheatley Monitor 6 (Funnel Catch)" +wheatley_monitor_7_stop_the_box = "Wheatley Monitor 7 (Stop The Box)" +wheatley_monitor_8_laser_catapult = "Wheatley Monitor 8 (Laser Catapult)" +wheatley_monitor_9_laser_platform = "Wheatley Monitor 9 (Laser Platform)" +wheatley_monitor_10_propulsion_catch = "Wheatley Monitor 10 (Propulsion Catch)" +wheatley_monitor_11_repulsion_polarity = "Wheatley Monitor 11 (Repulsion Polarity)" +wheatley_monitor_12_finale_3 = "Wheatley Monitor 12 (Finale 3)" + +# ratman dens +ratman_den_1_smooth_jazz = "Ratman Den 1 (Smooth Jazz)" +ratman_den_2_dual_lasers = "Ratman Den 2 (Dual Lasers)" +ratman_den_3_trust_fling = "Ratman Den 3 (Trust Fling)" +ratman_den_4_bridge_intro = "Ratman Den 4 (Bridge Intro)" +ratman_den_5_bridge_the_gap = "Ratman Den 5 (Bridge the Gap)" +ratman_den_6_laser_vs_turret = "Ratman Den 6 (Laser Vs. Turret)" +ratman_den_7_pull_the_rug = "Ratman Den 7 (Pull The Rug)" + +# vitrified doors +vitrified_door_1_cave_johnson = "Vitrified Door 1 (Cave Johnson)" +vitrified_door_2_cave_johnson = "Vitrified Door 2 (Cave Johnson)" +vitrified_door_3_cave_johnson = "Vitrified Door 3 (Cave Johnson)" +vitrified_door_4_potatos = "Vitrified Door 4 (PotatOS)" +vitrified_door_5_potatos = "Vitrified Door 5 (PotatOS)" +vitrified_door_6_potatos = "Vitrified Door 6 (PotatOS)" diff --git a/worlds/portal2/Locations.py b/worlds/portal2/Locations.py index 8cd07b72b48..137d832cfa9 100644 --- a/worlds/portal2/Locations.py +++ b/worlds/portal2/Locations.py @@ -3,6 +3,7 @@ from attr import dataclass from BaseClasses import Location from .ItemNames import * +from .LocationNames import * portal_2_base_id = 98275000 offset_index = 0 @@ -34,93 +35,93 @@ class Portal2Location(Location): map_complete_table: dict[str, Portal2LocationData] = { # Chapter 1 - "Container Ride Completion": Portal2LocationData("sp_a1_intro1", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), - "Portal Carousel Completion": Portal2LocationData("sp_a1_intro2", LocationType.MAP_COMPLETION, [button, weighted_cube, floor_button], 1), - "Portal Gun Completion": Portal2LocationData("sp_a1_intro3", LocationType.MAP_COMPLETION, [], 1), - "Smooth Jazz Completion": Portal2LocationData("sp_a1_intro4", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), - "Cube Momentum Completion": Portal2LocationData("sp_a1_intro5", LocationType.MAP_COMPLETION, [button, weighted_cube, floor_button], 1), - "Future Starter Completion": Portal2LocationData("sp_a1_intro6", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), - "Secret Panel Completion": Portal2LocationData("sp_a1_intro7", LocationType.MAP_COMPLETION, [], 1), - "Wake Up Completion": Portal2LocationData("sp_a1_wakeup", LocationType.MAP_COMPLETION, [], 1), - "Incinerator Completion": Portal2LocationData("sp_a2_intro", LocationType.MAP_COMPLETION, [portal_gun_2], 1), + container_ride_completion: Portal2LocationData("sp_a1_intro1", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), + portal_carousel_completion: Portal2LocationData("sp_a1_intro2", LocationType.MAP_COMPLETION, [button, weighted_cube, floor_button], 1), + portal_gun_completion: Portal2LocationData("sp_a1_intro3", LocationType.MAP_COMPLETION, [], 1), + smooth_jazz_completion: Portal2LocationData("sp_a1_intro4", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), + cube_momentum_completion: Portal2LocationData("sp_a1_intro5", LocationType.MAP_COMPLETION, [button, weighted_cube, floor_button], 1), + future_starter_completion: Portal2LocationData("sp_a1_intro6", LocationType.MAP_COMPLETION, [weighted_cube, floor_button], 1), + secret_panel_completion: Portal2LocationData("sp_a1_intro7", LocationType.MAP_COMPLETION, [], 1), + wake_up_completion: Portal2LocationData("sp_a1_wakeup", LocationType.MAP_COMPLETION, [], 1), + incinerator_completion: Portal2LocationData("sp_a2_intro", LocationType.MAP_COMPLETION, [portal_gun_2], 1), # Chapter 2 - "Laser Intro Completion": Portal2LocationData("sp_a2_laser_intro", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher], 2), - "Laser Stairs Completion": Portal2LocationData("sp_a2_laser_stairs", LocationType.MAP_COMPLETION, [portal_gun_2, reflection_cube, floor_button, laser, laser_catcher], 2), - "Dual Lasers Completion": Portal2LocationData("sp_a2_dual_lasers", LocationType.MAP_COMPLETION, [portal_gun_2, reflection_cube, laser, laser_catcher], 2), - "Laser Over Goo Completion": Portal2LocationData("sp_a2_laser_over_goo", LocationType.MAP_COMPLETION, [button, floor_button, weighted_cube, portal_gun_2, laser, laser_catcher], 2), - "Catapult Intro Completion": Portal2LocationData("sp_a2_catapult_intro", LocationType.MAP_COMPLETION, [faith_plate, button, weighted_cube, floor_button], 2), - "Trust Fling Completion": Portal2LocationData("sp_a2_trust_fling", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, button, weighted_cube, floor_button], 2), - "Pit Flings Completion": Portal2LocationData("sp_a2_pit_flings", LocationType.MAP_COMPLETION, [portal_gun_2, weighted_cube, laser, laser_catcher, floor_button], 2), - "Fizzler Intro Completion": Portal2LocationData("sp_a2_fizzler_intro", LocationType.MAP_COMPLETION, [portal_gun_2, laser, reflection_cube, laser_catcher, button], 2), + laser_intro_completion: Portal2LocationData("sp_a2_laser_intro", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher], 2), + laser_stairs_completion: Portal2LocationData("sp_a2_laser_stairs", LocationType.MAP_COMPLETION, [portal_gun_2, reflection_cube, floor_button, laser, laser_catcher], 2), + dual_lasers_completion: Portal2LocationData("sp_a2_dual_lasers", LocationType.MAP_COMPLETION, [portal_gun_2, reflection_cube, laser, laser_catcher], 2), + laser_over_goo_completion: Portal2LocationData("sp_a2_laser_over_goo", LocationType.MAP_COMPLETION, [button, floor_button, weighted_cube, portal_gun_2, laser, laser_catcher], 2), + catapult_intro_completion: Portal2LocationData("sp_a2_catapult_intro", LocationType.MAP_COMPLETION, [faith_plate, button, weighted_cube, floor_button], 2), + trust_fling_completion: Portal2LocationData("sp_a2_trust_fling", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, button, weighted_cube, floor_button], 2), + pit_flings_completion: Portal2LocationData("sp_a2_pit_flings", LocationType.MAP_COMPLETION, [portal_gun_2, weighted_cube, laser, laser_catcher, floor_button], 2), + fizzler_intro_completion: Portal2LocationData("sp_a2_fizzler_intro", LocationType.MAP_COMPLETION, [portal_gun_2, laser, reflection_cube, laser_catcher, button], 2), # Chapter 3 - "Ceiling Catapult Completion": Portal2LocationData("sp_a2_sphere_peek", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, button, reflection_cube, laser, laser_catcher], 3), - "Ricochet Completion": Portal2LocationData("sp_a2_ricochet", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, weighted_cube, laser, laser_catcher, reflection_cube, floor_button, button], 3), - "Bridge Intro Completion": Portal2LocationData("sp_a2_bridge_intro", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, floor_button, button, weighted_cube], 3), - "Bridge the Gap Completion": Portal2LocationData("sp_a2_bridge_the_gap", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, floor_button, button, weighted_cube], 3), - "Turret Intro Completion": Portal2LocationData("sp_a2_turret_intro", LocationType.MAP_COMPLETION, [portal_gun_2, weighted_cube, floor_button, turrets], 3), - "Laser Relays Completion": Portal2LocationData("sp_a2_laser_relays", LocationType.MAP_COMPLETION, [portal_gun_2, laser, reflection_cube, laser_relays], 3), - "Turret Blocker Completion": Portal2LocationData("sp_a2_turret_blocker", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, faith_plate, floor_button, weighted_cube], 3), - "Laser Vs. Turret Completion": Portal2LocationData("sp_a2_laser_vs_turret", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, weighted_cube, reflection_cube, floor_button], 3), - "Pull The Rug Completion": Portal2LocationData("sp_a2_pull_the_rug", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, weighted_cube, floor_button, laser, laser_catcher], 3), + ceiling_catapult_completion: Portal2LocationData("sp_a2_sphere_peek", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, button, reflection_cube, laser, laser_catcher], 3), + ricochet_completion: Portal2LocationData("sp_a2_ricochet", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, weighted_cube, laser, laser_catcher, reflection_cube, floor_button, button], 3), + bridge_intro_completion: Portal2LocationData("sp_a2_bridge_intro", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, floor_button, button, weighted_cube], 3), + bridge_the_gap_completion: Portal2LocationData("sp_a2_bridge_the_gap", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, floor_button, button, weighted_cube], 3), + turret_intro_completion: Portal2LocationData("sp_a2_turret_intro", LocationType.MAP_COMPLETION, [portal_gun_2, weighted_cube, floor_button, turrets], 3), + laser_relays_completion: Portal2LocationData("sp_a2_laser_relays", LocationType.MAP_COMPLETION, [portal_gun_2, laser, reflection_cube, laser_relays], 3), + turret_blocker_completion: Portal2LocationData("sp_a2_turret_blocker", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, faith_plate, floor_button, weighted_cube], 3), + laser_vs_turret_completion: Portal2LocationData("sp_a2_laser_vs_turret", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, weighted_cube, reflection_cube, floor_button], 3), + pull_the_rug_completion: Portal2LocationData("sp_a2_pull_the_rug", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, weighted_cube, floor_button, laser, laser_catcher], 3), # Chapter 4 - "Column Blocker Completion": Portal2LocationData("sp_a2_column_blocker", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, laser, laser_catcher, laser_relays, button, reflection_cube, faith_plate], 4), - "Laser Chaining Completion": Portal2LocationData("sp_a2_laser_chaining", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, laser_relays, reflection_cube, faith_plate], 4), - "Triple Laser Completion": Portal2LocationData("sp_a2_triple_laser", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, reflection_cube], 4), - "Jailbreak Completion": Portal2LocationData("sp_a2_bts1", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, button, weighted_cube], 4), - "Escape Completion": Portal2LocationData("sp_a2_bts2", LocationType.MAP_COMPLETION, [portal_gun_2, turrets], 4), + column_blocker_completion: Portal2LocationData("sp_a2_column_blocker", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, laser, laser_catcher, laser_relays, button, reflection_cube, faith_plate], 4), + laser_chaining_completion: Portal2LocationData("sp_a2_laser_chaining", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, laser_relays, reflection_cube, faith_plate], 4), + triple_laser_completion: Portal2LocationData("sp_a2_triple_laser", LocationType.MAP_COMPLETION, [portal_gun_2, laser, laser_catcher, reflection_cube], 4), + jailbreak_completion: Portal2LocationData("sp_a2_bts1", LocationType.MAP_COMPLETION, [portal_gun_2, bridge, button, weighted_cube], 4), + escape_completion: Portal2LocationData("sp_a2_bts2", LocationType.MAP_COMPLETION, [portal_gun_2, turrets], 4), # Chapter 5 - "Turret Factory Completion": Portal2LocationData("sp_a2_bts3", LocationType.MAP_COMPLETION, [portal_gun_2], 5), - "Turret Sabotage Completion": Portal2LocationData("sp_a2_bts4", LocationType.MAP_COMPLETION, [portal_gun_2, turrets], 5), - "Neurotoxin Sabotage Completion": Portal2LocationData("sp_a2_bts5", LocationType.MAP_COMPLETION, [portal_gun_2, laser], 5), - "Core Completion": Portal2LocationData("sp_a2_core", LocationType.MAP_COMPLETION, [portal_gun_2, button, turrets], 5), + turret_factory_completion: Portal2LocationData("sp_a2_bts3", LocationType.MAP_COMPLETION, [portal_gun_2], 5), + turret_sabotage_completion: Portal2LocationData("sp_a2_bts4", LocationType.MAP_COMPLETION, [portal_gun_2, turrets], 5), + neurotoxin_sabotage_completion: Portal2LocationData("sp_a2_bts5", LocationType.MAP_COMPLETION, [portal_gun_2, laser], 5), + core_completion: Portal2LocationData("sp_a2_core", LocationType.MAP_COMPLETION, [portal_gun_2, button, turrets], 5), # Chapter 6 - "Underground Completion": Portal2LocationData("sp_a3_01", LocationType.MAP_COMPLETION, [portal_gun_2], 6), - "Cave Johnson Completion": Portal2LocationData("sp_a3_03", LocationType.MAP_COMPLETION, [portal_gun_2], 6), - "Repulsion Intro Completion": Portal2LocationData("sp_a3_jump_intro", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, old_button, old_floor_button, antique_cube], 6), - "Bomb Flings Completion": Portal2LocationData("sp_a3_bomb_flings", LocationType.MAP_COMPLETION, [portal_gun_2, old_button, blue_gel], 6), - "Crazy Box Completion": Portal2LocationData("sp_a3_crazy_box", LocationType.MAP_COMPLETION, [portal_gun_2, old_button, blue_gel, antique_cube, old_floor_button], 6), - "PotatOS Completion": Portal2LocationData("sp_a3_transition01", LocationType.MAP_COMPLETION, [portal_gun_2, potatos], 6), + underground_completion: Portal2LocationData("sp_a3_01", LocationType.MAP_COMPLETION, [portal_gun_2], 6), + cave_johnson_completion: Portal2LocationData("sp_a3_03", LocationType.MAP_COMPLETION, [portal_gun_2], 6), + repulsion_intro_completion: Portal2LocationData("sp_a3_jump_intro", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, old_button, old_floor_button, antique_cube], 6), + bomb_flings_completion: Portal2LocationData("sp_a3_bomb_flings", LocationType.MAP_COMPLETION, [portal_gun_2, old_button, blue_gel], 6), + crazy_box_completion: Portal2LocationData("sp_a3_crazy_box", LocationType.MAP_COMPLETION, [portal_gun_2, old_button, blue_gel, antique_cube, old_floor_button], 6), + potatos_completion: Portal2LocationData("sp_a3_transition01", LocationType.MAP_COMPLETION, [portal_gun_2, potatos], 6), # Chapter 7 - "Propulsion Intro Completion": Portal2LocationData("sp_a3_speed_ramp", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, antique_cube, old_floor_button, old_button], 7), - "Propulsion Flings Completion": Portal2LocationData("sp_a3_speed_flings", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, antique_cube, old_floor_button], 7), - "Conversion Intro Completion": Portal2LocationData("sp_a3_portal_intro", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, white_gel], 7), - "Three Gels Completion": Portal2LocationData("sp_a3_end", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, white_gel], 7), + propulsion_intro_completion: Portal2LocationData("sp_a3_speed_ramp", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, antique_cube, old_floor_button, old_button], 7), + propulsion_flings_completion: Portal2LocationData("sp_a3_speed_flings", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, antique_cube, old_floor_button], 7), + conversion_intro_completion: Portal2LocationData("sp_a3_portal_intro", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, white_gel], 7), + three_gels_completion: Portal2LocationData("sp_a3_end", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, orange_gel, white_gel], 7), # Chapter 8 - "Test Completion": Portal2LocationData("sp_a4_intro", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, button], 8), - "Funnel Intro Completion": Portal2LocationData("sp_a4_tb_intro", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button], 8), - "Ceiling Button Completion": Portal2LocationData("sp_a4_tb_trust_drop", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button], 8), - "Wall Button Completion": Portal2LocationData("sp_a4_tb_wall_button", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button, faith_plate], 8), - "Polarity Completion": Portal2LocationData("sp_a4_tb_polarity", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button], 8), - "Funnel Catch Completion": Portal2LocationData("sp_a4_tb_catch", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button, faith_plate], 8), - "Stop The Box Completion": Portal2LocationData("sp_a4_stop_the_box", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, button, faith_plate, bridge], 8), - "Laser Catapult Completion": Portal2LocationData("sp_a4_laser_catapult", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, faith_plate, reflection_cube, laser, laser_catcher, funnel], 8), - "Laser Platform Completion": Portal2LocationData("sp_a4_laser_platform", LocationType.MAP_COMPLETION, [portal_gun_2, button, reflection_cube, laser, laser_catcher, funnel], 8), - "Propulsion Catch Completion": Portal2LocationData("sp_a4_speed_tb_catch", LocationType.MAP_COMPLETION, [portal_gun_2, floor_button, funnel, button, frankenturret, orange_gel], 8), - "Repulsion Polarity Completion": Portal2LocationData("sp_a4_jump_polarity", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, white_gel, funnel, floor_button, button], 8), + test_completion: Portal2LocationData("sp_a4_intro", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, button], 8), + funnel_intro_completion: Portal2LocationData("sp_a4_tb_intro", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button], 8), + ceiling_button_completion: Portal2LocationData("sp_a4_tb_trust_drop", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button], 8), + wall_button_completion: Portal2LocationData("sp_a4_tb_wall_button", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button, faith_plate], 8), + polarity_completion: Portal2LocationData("sp_a4_tb_polarity", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button], 8), + funnel_catch_completion: Portal2LocationData("sp_a4_tb_catch", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, frankenturret, floor_button, button, faith_plate], 8), + stop_the_box_completion: Portal2LocationData("sp_a4_stop_the_box", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, button, faith_plate, bridge], 8), + laser_catapult_completion: Portal2LocationData("sp_a4_laser_catapult", LocationType.MAP_COMPLETION, [portal_gun_2, frankenturret, floor_button, faith_plate, reflection_cube, laser, laser_catcher, funnel], 8), + laser_platform_completion: Portal2LocationData("sp_a4_laser_platform", LocationType.MAP_COMPLETION, [portal_gun_2, button, reflection_cube, laser, laser_catcher, funnel], 8), + propulsion_catch_completion: Portal2LocationData("sp_a4_speed_tb_catch", LocationType.MAP_COMPLETION, [portal_gun_2, floor_button, funnel, button, frankenturret, orange_gel], 8), + repulsion_polarity_completion: Portal2LocationData("sp_a4_jump_polarity", LocationType.MAP_COMPLETION, [portal_gun_2, blue_gel, white_gel, funnel, floor_button, button], 8), # Chapter 9 - "Finale 1 Completion": Portal2LocationData("sp_a4_finale1", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, funnel, white_gel], 9), - "Finale 2 Completion": Portal2LocationData("sp_a4_finale2", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, blue_gel, floor_button, turrets], 9), - "Finale 3 Completion": Portal2LocationData("sp_a4_finale3", LocationType.MAP_COMPLETION, [portal_gun_2, orange_gel, white_gel, funnel], 9), - "Finale 4 Completion": Portal2LocationData("sp_a4_finale4", LocationType.MAP_COMPLETION, [portal_gun_2, potatos, blue_gel, orange_gel, white_gel, adventure_core, space_core, fact_core], 9), + finale_1_completion: Portal2LocationData("sp_a4_finale1", LocationType.MAP_COMPLETION, [portal_gun_2, faith_plate, funnel, white_gel], 9), + finale_2_completion: Portal2LocationData("sp_a4_finale2", LocationType.MAP_COMPLETION, [portal_gun_2, funnel, blue_gel, floor_button, turrets], 9), + finale_3_completion: Portal2LocationData("sp_a4_finale3", LocationType.MAP_COMPLETION, [portal_gun_2, orange_gel, white_gel, funnel], 9), + finale_4_completion: Portal2LocationData("sp_a4_finale4", LocationType.MAP_COMPLETION, [portal_gun_2, potatos, blue_gel, orange_gel, white_gel, adventure_core, space_core, fact_core], 9), } # Optional Checks cutscene_completion_table: dict[str, Portal2LocationData] = { - "Tube Ride Completion": Portal2LocationData("sp_a2_bts6", LocationType.CUTSCENE_COMPLETION, [], 5), - "Long Fall Completion": Portal2LocationData("sp_a3_00", LocationType.CUTSCENE_COMPLETION, [], 6), + tube_ride_completion: Portal2LocationData("sp_a2_bts6", LocationType.CUTSCENE_COMPLETION, [], 5), + long_fall_completion: Portal2LocationData("sp_a3_00", LocationType.CUTSCENE_COMPLETION, [], 6), } maps_in_chapters: dict[str, list[str]] = { - "Chapter 1": ["Container Ride Completion", "Portal Carousel Completion", "Portal Gun Completion", "Smooth Jazz Completion", "Cube Momentum Completion", "Future Starter Completion", "Secret Panel Completion", "Wake Up Completion", "Incinerator Completion"], - "Chapter 2": ["Laser Intro Completion", "Laser Stairs Completion", "Dual Lasers Completion", "Laser Over Goo Completion", "Catapult Intro Completion", "Trust Fling Completion", "Pit Flings Completion", "Fizzler Intro Completion"], - "Chapter 3": ["Ceiling Catapult Completion", "Ricochet Completion", "Bridge Intro Completion", "Bridge the Gap Completion", "Turret Intro Completion", "Laser Relays Completion", "Turret Blocker Completion", "Laser Vs. Turret Completion", "Pull The Rug Completion"], - "Chapter 4": ["Column Blocker Completion", "Laser Chaining Completion", "Triple Laser Completion", "Jailbreak Completion", "Escape Completion"], - "Chapter 5": ["Turret Factory Completion", "Turret Sabotage Completion", "Neurotoxin Sabotage Completion", "Core Completion", "Tube Ride Completion"], - "Chapter 6": ["Long Fall Completion","Underground Completion", "Cave Johnson Completion", "Repulsion Intro Completion", "Bomb Flings Completion", "Crazy Box Completion", "PotatOS Completion"], - "Chapter 7": ["Propulsion Intro Completion", "Propulsion Flings Completion", "Conversion Intro Completion", "Three Gels Completion"], - "Chapter 8": ["Test Completion", "Funnel Intro Completion", "Ceiling Button Completion", "Wall Button Completion", "Polarity Completion", "Funnel Catch Completion", "Stop The Box Completion", "Laser Catapult Completion", "Laser Platform Completion", "Propulsion Catch Completion", "Repulsion Polarity Completion"], - "Chapter 9": ["Finale 1 Completion", "Finale 2 Completion", "Finale 3 Completion", "Finale 4 Completion"] + "Chapter 1": [container_ride_completion, portal_carousel_completion, portal_gun_completion, smooth_jazz_completion, cube_momentum_completion, future_starter_completion, secret_panel_completion, wake_up_completion, incinerator_completion], + "Chapter 2": [laser_intro_completion, laser_stairs_completion, dual_lasers_completion, laser_over_goo_completion, catapult_intro_completion, trust_fling_completion, pit_flings_completion, fizzler_intro_completion], + "Chapter 3": [ceiling_catapult_completion, ricochet_completion, bridge_intro_completion, bridge_the_gap_completion, turret_intro_completion, laser_relays_completion, turret_blocker_completion, laser_vs_turret_completion, pull_the_rug_completion], + "Chapter 4": [column_blocker_completion, laser_chaining_completion, triple_laser_completion, jailbreak_completion, escape_completion], + "Chapter 5": [turret_factory_completion, turret_sabotage_completion, neurotoxin_sabotage_completion, core_completion, tube_ride_completion], + "Chapter 6": [long_fall_completion, underground_completion, cave_johnson_completion, repulsion_intro_completion, bomb_flings_completion, crazy_box_completion, potatos_completion], + "Chapter 7": [propulsion_intro_completion, propulsion_flings_completion, conversion_intro_completion, three_gels_completion], + "Chapter 8": [test_completion, funnel_intro_completion, ceiling_button_completion, wall_button_completion, polarity_completion, funnel_catch_completion, stop_the_box_completion, laser_catapult_completion, laser_platform_completion, propulsion_catch_completion, repulsion_polarity_completion], + "Chapter 9": [finale_1_completion, finale_2_completion, finale_3_completion, finale_4_completion] } @@ -145,18 +146,18 @@ class Portal2Location(Location): achievements_table: dict[str, Portal2LocationData] = {} wheatley_monitor_table: dict[str, Portal2LocationData] = { - "Wheatley Monitor 1 (Funnel Intro)": Portal2LocationData("sp_a4_tb_intro", LocationType.WHEATLY_MONITOR, [portal_gun_2, funnel, frankenturret]), - "Wheatley Monitor 2 (Ceiling Button)": Portal2LocationData("sp_a4_tb_trust_drop", LocationType.WHEATLY_MONITOR, [portal_gun_2, button, funnel, frankenturret]), - "Wheatley Monitor 3 (Wall Button)": Portal2LocationData("sp_a4_tb_wall_button", LocationType.WHEATLY_MONITOR, [portal_gun_2]), - "Wheatley Monitor 4 (Polarity)": Portal2LocationData("sp_a4_tb_polarity", LocationType.WHEATLY_MONITOR, [turrets]), - "Wheatley Monitor 5 (Funnel Catch)": Portal2LocationData("sp_a4_tb_catch 1", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor1 - "Wheatley Monitor 6 (Funnel Catch)": Portal2LocationData("sp_a4_tb_catch 2", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor2 - "Wheatley Monitor 7 (Stop The Box)": Portal2LocationData("sp_a4_stop_the_box", LocationType.WHEATLY_MONITOR, [faith_plate]), - "Wheatley Monitor 8 (Laser Catapult)": Portal2LocationData("sp_a4_laser_catapult", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, faith_plate, funnel, reflection_cube, laser, laser_catcher]), - "Wheatley Monitor 9 (Laser Platform)": Portal2LocationData("sp_a4_laser_platform", LocationType.WHEATLY_MONITOR, [portal_gun_2, laser, laser_catcher, reflection_cube, button]), - "Wheatley Monitor 10 (Propulsion Catch)": Portal2LocationData("sp_a4_speed_tb_catch", LocationType.WHEATLY_MONITOR, [portal_gun_2]), - "Wheatley Monitor 11 (Repulsion Polarity)": Portal2LocationData("sp_a4_jump_polarity", LocationType.WHEATLY_MONITOR, [portal_gun_2, blue_gel, white_gel, funnel, turrets, floor_button, button]), - "Wheatley Monitor 12 (Finale 3)": Portal2LocationData("sp_a4_finale3", LocationType.WHEATLY_MONITOR, [portal_gun_2, white_gel]), + wheatley_monitor_1_funnel_intro: Portal2LocationData("sp_a4_tb_intro", LocationType.WHEATLY_MONITOR, [portal_gun_2, funnel, frankenturret]), + wheatley_monitor_2_ceiling_button: Portal2LocationData("sp_a4_tb_trust_drop", LocationType.WHEATLY_MONITOR, [portal_gun_2, button, funnel, frankenturret]), + wheatley_monitor_3_wall_button: Portal2LocationData("sp_a4_tb_wall_button", LocationType.WHEATLY_MONITOR, [portal_gun_2]), + wheatley_monitor_4_polarity: Portal2LocationData("sp_a4_tb_polarity", LocationType.WHEATLY_MONITOR, [turrets]), + wheatley_monitor_5_funnel_catch: Portal2LocationData("sp_a4_tb_catch 1", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor1 + wheatley_monitor_6_funnel_catch: Portal2LocationData("sp_a4_tb_catch 2", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, funnel, faith_plate, button]), #monitor2 + wheatley_monitor_7_stop_the_box: Portal2LocationData("sp_a4_stop_the_box", LocationType.WHEATLY_MONITOR, [faith_plate]), + wheatley_monitor_8_laser_catapult: Portal2LocationData("sp_a4_laser_catapult", LocationType.WHEATLY_MONITOR, [portal_gun_2, frankenturret, faith_plate, funnel, reflection_cube, laser, laser_catcher]), + wheatley_monitor_9_laser_platform: Portal2LocationData("sp_a4_laser_platform", LocationType.WHEATLY_MONITOR, [portal_gun_2, laser, laser_catcher, reflection_cube, button]), + wheatley_monitor_10_propulsion_catch: Portal2LocationData("sp_a4_speed_tb_catch", LocationType.WHEATLY_MONITOR, [portal_gun_2]), + wheatley_monitor_11_repulsion_polarity: Portal2LocationData("sp_a4_jump_polarity", LocationType.WHEATLY_MONITOR, [portal_gun_2, blue_gel, white_gel, funnel, turrets, floor_button, button]), + wheatley_monitor_12_finale_3: Portal2LocationData("sp_a4_finale3", LocationType.WHEATLY_MONITOR, [portal_gun_2, white_gel]), } # Note: these are the names used in game to identify the monitors @@ -172,29 +173,29 @@ class Portal2Location(Location): item_maps_to_item_location : dict[str, str] = {value.map_name:key for key, value in item_location_table.items()} ratman_den_locations_table: dict[str, Portal2LocationData] = { - "Ratman Den 1 (Smooth Jazz)": Portal2LocationData("sp_a1_intro4", LocationType.RATMAN_DEN, [weighted_cube, floor_button]), - "Ratman Den 2 (Dual Lasers)": Portal2LocationData("sp_a2_dual_lasers", LocationType.RATMAN_DEN), - "Ratman Den 3 (Trust Fling)": Portal2LocationData("sp_a2_trust_fling", LocationType.RATMAN_DEN, [portal_gun_2, faith_plate]), - "Ratman Den 4 (Bridge Intro)": Portal2LocationData("sp_a2_bridge_intro", LocationType.RATMAN_DEN), - "Ratman Den 5 (Bridge the Gap)": Portal2LocationData("sp_a2_bridge_the_gap", LocationType.RATMAN_DEN, [portal_gun_2, bridge]), - "Ratman Den 6 (Laser Vs. Turret)": Portal2LocationData("sp_a2_laser_vs_turret", LocationType.RATMAN_DEN, [portal_gun_2, laser, floor_button, reflection_cube]), - "Ratman Den 7 (Pull The Rug)": Portal2LocationData("sp_a2_pull_the_rug", LocationType.RATMAN_DEN, [portal_gun_2, bridge]) + ratman_den_1_smooth_jazz: Portal2LocationData("sp_a1_intro4", LocationType.RATMAN_DEN, [weighted_cube, floor_button]), + ratman_den_2_dual_lasers: Portal2LocationData("sp_a2_dual_lasers", LocationType.RATMAN_DEN), + ratman_den_3_trust_fling: Portal2LocationData("sp_a2_trust_fling", LocationType.RATMAN_DEN, [portal_gun_2, faith_plate]), + ratman_den_4_bridge_intro: Portal2LocationData("sp_a2_bridge_intro", LocationType.RATMAN_DEN), + ratman_den_5_bridge_the_gap: Portal2LocationData("sp_a2_bridge_the_gap", LocationType.RATMAN_DEN, [portal_gun_2, bridge]), + ratman_den_6_laser_vs_turret: Portal2LocationData("sp_a2_laser_vs_turret", LocationType.RATMAN_DEN, [portal_gun_2, laser, floor_button, reflection_cube]), + ratman_den_7_pull_the_rug: Portal2LocationData("sp_a2_pull_the_rug", LocationType.RATMAN_DEN, [portal_gun_2, bridge]) } ratman_map_to_ratman_den: dict[str, str] = {value.map_name: key for key, value in ratman_den_locations_table.items()} vitrified_door_locations_table: dict[str, Portal2LocationData] = { - "Vitrified Door 1 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 2 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 3 (Cave Johnson)": Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 4 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 5 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), - "Vitrified Door 6 (PotatOS)": Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_1_cave_johnson: Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_2_cave_johnson: Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_3_cave_johnson: Portal2LocationData("sp_a3_03", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_4_potatos: Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_5_potatos: Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), + vitrified_door_6_potatos: Portal2LocationData("sp_a3_transition01", LocationType.OTHER, [portal_gun_2], 6), } vitrified_map_to_vitrified_door: dict[str, list[str]] = { - "sp_a3_03": ["Vitrified Door 1 (Cave Johnson)", "Vitrified Door 2 (Cave Johnson)", "Vitrified Door 3 (Cave Johnson)"], - "sp_a3_transition01": ["Vitrified Door 4 (PotatOS)", "Vitrified Door 5 (PotatOS)", "Vitrified Door 6 (PotatOS)"] + "sp_a3_03": [vitrified_door_1_cave_johnson, vitrified_door_2_cave_johnson, vitrified_door_3_cave_johnson], + "sp_a3_transition01": [vitrified_door_4_potatos, vitrified_door_5_potatos, vitrified_door_6_potatos] } all_locations_table: dict[str, Portal2LocationData] = map_complete_table.copy() @@ -221,87 +222,87 @@ class Portal2Location(Location): # Alternate logic for speedrunners speedrun_logic_table: dict[str, list[str]] = { # Chapter 1 - "Portal Carousel Completion": [button, floor_button], - "Smooth Jazz Completion": [floor_button], - "Cube Momentum Completion": [floor_button], - "Future Starter Completion": [floor_button], - "Incinerator Completion": [weighted_cube], + portal_carousel_completion: [button, floor_button], + smooth_jazz_completion: [floor_button], + cube_momentum_completion: [floor_button], + future_starter_completion: [floor_button], + incinerator_completion: [weighted_cube], # Chapter 2 - "Laser Intro Completion": [portal_gun_2], - "Laser Stairs Completion": [portal_gun_2, floor_button], - "Dual Lasers Completion": [portal_gun_2, laser, laser_catcher], - "Laser Over Goo Completion": [portal_gun_2, floor_button], - "Catapult Intro Completion": [portal_gun_2, floor_button], - "Trust Fling Completion": [portal_gun_2, faith_plate, floor_button], - "Pit Flings Completion": [portal_gun_2], - "Fizzler Intro Completion": [portal_gun_2, laser, laser_catcher], + laser_intro_completion: [portal_gun_2], + laser_stairs_completion: [portal_gun_2, floor_button], + dual_lasers_completion: [portal_gun_2, laser, laser_catcher], + laser_over_goo_completion: [portal_gun_2, floor_button], + catapult_intro_completion: [portal_gun_2, floor_button], + trust_fling_completion: [portal_gun_2, faith_plate, floor_button], + pit_flings_completion: [portal_gun_2], + fizzler_intro_completion: [portal_gun_2, laser, laser_catcher], # Chapter 3 - "Ricochet Completion": [portal_gun_2, weighted_cube, floor_button], - "Bridge Intro Completion": [portal_gun_2, floor_button], - "Bridge the Gap Completion": [weighted_cube, button, floor_button], - "Turret Intro Completion": [floor_button], - "Laser Relays Completion": [laser_relays, laser, reflection_cube], - "Turret Blocker Completion": [floor_button], - "Laser Vs. Turret Completion": [portal_gun_2], - "Pull The Rug Completion": [floor_button, weighted_cube, bridge, portal_gun_2], + ricochet_completion: [portal_gun_2, weighted_cube, floor_button], + bridge_intro_completion: [portal_gun_2, floor_button], + bridge_the_gap_completion: [weighted_cube, button, floor_button], + turret_intro_completion: [floor_button], + laser_relays_completion: [laser_relays, laser, reflection_cube], + turret_blocker_completion: [floor_button], + laser_vs_turret_completion: [portal_gun_2], + pull_the_rug_completion: [floor_button, weighted_cube, bridge, portal_gun_2], # Chapter 4 - "Column Blocker Completion": [portal_gun_2], - "Laser Chaining Completion": [reflection_cube, laser, laser_relays], - "Triple Laser Completion": [reflection_cube, portal_gun_2], - "Jailbreak Completion": [portal_gun_2, button, weighted_cube], - "Escape Completion": [], + column_blocker_completion: [portal_gun_2], + laser_chaining_completion: [reflection_cube, laser, laser_relays], + triple_laser_completion: [reflection_cube, portal_gun_2], + jailbreak_completion: [portal_gun_2, button, weighted_cube], + escape_completion: [], # Chapter 5 - "Turret Sabotage Completion": [portal_gun_2], - "Neurotoxin Sabotage Completion": [portal_gun_2], - "Core Completion": [turrets], + turret_sabotage_completion: [portal_gun_2], + neurotoxin_sabotage_completion: [portal_gun_2], + core_completion: [turrets], # Chapter 6 - "Repulsion Intro Completion": [blue_gel, old_floor_button, portal_gun_2], - "Bomb Flings Completion": [portal_gun_2, blue_gel, old_button], - "Crazy Box Completion": [portal_gun_2, old_floor_button], + repulsion_intro_completion: [blue_gel, old_floor_button, portal_gun_2], + bomb_flings_completion: [portal_gun_2, blue_gel, old_button], + crazy_box_completion: [portal_gun_2, old_floor_button], # Chapter 7 - "Propulsion Intro Completion": [portal_gun_2], - "Propulsion Flings Completion": [portal_gun_2, blue_gel], - "Conversion Intro Completion": [portal_gun_2], - "Three Gels Completion": [portal_gun_2, blue_gel], + propulsion_intro_completion: [portal_gun_2], + propulsion_flings_completion: [portal_gun_2, blue_gel], + conversion_intro_completion: [portal_gun_2], + three_gels_completion: [portal_gun_2, blue_gel], # Chapter 8 - "Funnel Intro Completion": [floor_button, funnel], - "Ceiling Button Completion": [floor_button, frankenturret, button, portal_gun_2], - "Wall Button Completion": [floor_button, funnel, portal_gun_2], - "Polarity Completion": [portal_gun_2, funnel], - "Funnel Catch Completion": [portal_gun_2], - "Stop The Box Completion": [floor_button, portal_gun_2], - "Laser Catapult Completion": [portal_gun_2], - "Laser Platform Completion": [portal_gun_2, funnel], - "Propulsion Catch Completion": [floor_button, funnel], - "Repulsion Polarity Completion": [turrets, button, blue_gel], + funnel_intro_completion: [floor_button, funnel], + ceiling_button_completion: [floor_button, frankenturret, button, portal_gun_2], + wall_button_completion: [floor_button, funnel, portal_gun_2], + polarity_completion: [portal_gun_2, funnel], + funnel_catch_completion: [portal_gun_2], + stop_the_box_completion: [floor_button, portal_gun_2], + laser_catapult_completion: [portal_gun_2], + laser_platform_completion: [portal_gun_2, funnel], + propulsion_catch_completion: [floor_button, funnel], + repulsion_polarity_completion: [turrets, button, blue_gel], # Chapter 9 - "Finale 1 Completion": [portal_gun_2, frankenturret, faith_plate], - "Finale 2 Completion": [portal_gun_2], - "Finale 3 Completion": [portal_gun_2, funnel], - "Finale 4 Completion": [portal_gun_2, potatos, white_gel, adventure_core, space_core, fact_core], + finale_1_completion: [portal_gun_2, frankenturret, faith_plate], + finale_2_completion: [portal_gun_2], + finale_3_completion: [portal_gun_2, funnel], + finale_4_completion: [portal_gun_2, potatos, white_gel, adventure_core, space_core, fact_core], } sub_locations_in_maps: dict[str, list[str]] = { - "Portal Gun Completion": [portal_gun_1], - "Incinerator Completion": [portal_gun_2], - "PotatOS Completion": [potatos, "Vitrified Door 4 (PotatOS)", "Vitrified Door 5 (PotatOS)", "Vitrified Door 6 (PotatOS)"], - "Funnel Intro Completion": ["Wheatley Monitor 1 (Funnel Intro)"], - "Ceiling Button Completion": ["Wheatley Monitor 2 (Ceiling Button)"], - "Wall Button Completion": ["Wheatley Monitor 3 (Wall Button)"], - "Polarity Completion": ["Wheatley Monitor 4 (Polarity)"], - "Funnel Catch Completion": ["Wheatley Monitor 5 (Funnel Catch)", "Wheatley Monitor 6 (Funnel Catch)"], - "Stop The Box Completion": ["Wheatley Monitor 7 (Stop The Box)"], - "Laser Catapult Completion": ["Wheatley Monitor 8 (Laser Catapult)"], - "Laser Platform Completion": ["Wheatley Monitor 9 (Laser Platform)"], - "Propulsion Catch Completion": ["Wheatley Monitor 10 (Propulsion Catch)"], - "Repulsion Polarity Completion": ["Wheatley Monitor 11 (Repulsion Polarity)"], - "Finale 3 Completion": ["Wheatley Monitor 12 (Finale 3)"], - "Smooth Jazz Completion": ["Ratman Den 1 (Smooth Jazz)"], - "Dual Lasers Completion": ["Ratman Den 2 (Dual Lasers)"], - "Trust Fling Completion": ["Ratman Den 3 (Trust Fling)"], - "Bridge Intro Completion": ["Ratman Den 4 (Bridge Intro)"], - "Bridge the Gap Completion": ["Ratman Den 5 (Bridge the Gap)"], - "Laser Vs. Turret Completion": ["Ratman Den 6 (Laser Vs. Turret)"], - "Pull The Rug Completion": ["Ratman Den 7 (Pull The Rug)"], - "Cave Johnson Completion": ["Vitrified Door 1 (Cave Johnson)", "Vitrified Door 2 (Cave Johnson)", "Vitrified Door 3 (Cave Johnson)"], + portal_gun_completion: [portal_gun_1], + incinerator_completion: [portal_gun_2], + potatos_completion: [potatos, vitrified_door_4_potatos, vitrified_door_5_potatos, vitrified_door_6_potatos], + funnel_intro_completion: [wheatley_monitor_1_funnel_intro], + ceiling_button_completion: [wheatley_monitor_2_ceiling_button], + wall_button_completion: [wheatley_monitor_3_wall_button], + polarity_completion: [wheatley_monitor_4_polarity], + funnel_catch_completion: [wheatley_monitor_5_funnel_catch, wheatley_monitor_6_funnel_catch], + stop_the_box_completion: [wheatley_monitor_7_stop_the_box], + laser_catapult_completion: [wheatley_monitor_8_laser_catapult], + laser_platform_completion: [wheatley_monitor_9_laser_platform], + propulsion_catch_completion: [wheatley_monitor_10_propulsion_catch], + repulsion_polarity_completion: [wheatley_monitor_11_repulsion_polarity], + finale_3_completion: [wheatley_monitor_12_finale_3], + smooth_jazz_completion: [ratman_den_1_smooth_jazz], + dual_lasers_completion: [ratman_den_2_dual_lasers], + trust_fling_completion: [ratman_den_3_trust_fling], + bridge_intro_completion: [ratman_den_4_bridge_intro], + bridge_the_gap_completion: [ratman_den_5_bridge_the_gap], + laser_vs_turret_completion: [ratman_den_6_laser_vs_turret], + pull_the_rug_completion: [ratman_den_7_pull_the_rug], + cave_johnson_completion: [vitrified_door_1_cave_johnson, vitrified_door_2_cave_johnson, vitrified_door_3_cave_johnson], } diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index a22302d670d..4afbb40913f 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -91,6 +91,34 @@ def play_map(self): """ async_start(send_instant_command(f"{self.map_data['command']}"), "send_map_command") + +class ChapterButton(MDButton): + + def __init__(self, chapter_name: str, chapter_maps: list, on_release): + self.chapter_name = chapter_name + self.chapter_maps = chapter_maps + finished_checks, total_checks = self.calculate_completeness() + + self.button_text = MDButtonText(text=f"{self.chapter_name} {finished_checks}/{total_checks}") + + super().__init__( + self.button_text, + on_release = on_release + ) + + def calculate_completeness(self) -> tuple: + total_checks = 0 + finished_checks = 0 + for map in self.chapter_maps: + total_checks += map["total_locations"] + finished_checks += map["finished_locations"] + + return finished_checks, total_checks + + def update_title(self, chapter_maps: dict): + self.chapter_maps = chapter_maps + finished_checks, total_checks = self.calculate_completeness() + self.button_text.text = f"{self.chapter_name} {finished_checks}/{total_checks}" class MenuLayout(MDGridLayout): @@ -98,11 +126,13 @@ class MenuLayout(MDGridLayout): def __init__(self): super().__init__(rows=1, cols=3, padding=[40, 10]) self.menu_info = [] - self.current_chapter = None + self.selected_chapter = None + self.selected_map = None self.map_area = None self.map_info = None self.is_open_world = False self.return_to_menu = False + self.chapter_buttons: list[ChapterButton] = [] def update_menu(self, menu_data: dict[str, dict]): """ @@ -111,10 +141,19 @@ def update_menu(self, menu_data: dict[str, dict]): """ self.menu_info = menu_data - selected_chapter = self.current_chapter or list(self.menu_info.keys())[0] + self.refresh_chapter_titles() + + selected_chapter = self.selected_chapter or list(self.menu_info.keys())[0] if self.map_area is not None: self.select_chapter(selected_chapter) + if self.selected_map: + self.select_map(self.selected_map) + + def refresh_chapter_titles(self): + for cb in self.chapter_buttons: + cb.update_title(self.menu_info[cb.chapter_name]) + def set_open_world(self): self.is_open_world = True @@ -137,19 +176,9 @@ def build(self): self.add_widget(self.chapter_area) self.add_widget(self.map_area) - for chapter_name, maps in self.menu_info.items(): - total_checks = 0 - finished_checks = 0 - for map in maps: - total_checks += map["total_locations"] - finished_checks += map["finished_locations"] - - chapter_button = MDButton( - MDButtonText(text=f"{chapter_name} {finished_checks}/{total_checks}"), - on_release=lambda btn, chapter=chapter_name: self.select_chapter( - chapter - ) - ) + for chapter_name, maps in self.menu_info.items(): + chapter_button = ChapterButton(chapter_name, maps, lambda btn, chapter=chapter_name: self.select_chapter(chapter)) + self.chapter_buttons.append(chapter_button) self.chapter_area.add_widget(chapter_button) menu_toggle_box = MDGridLayout(cols=2, row_default_height=40, row_force_default=True, padding=10) @@ -169,7 +198,7 @@ def select_chapter(self, chapter_name: str): if self.map_area is None: raise Exception("Map area not initialized. Call build() before select_chapter().") - self.current_chapter = chapter_name + self.selected_chapter = chapter_name for child in self.map_area.layout.children[:]: self.map_area.layout.remove_widget(child) @@ -201,13 +230,15 @@ def select_map(self, map_name: str): - Handle the selection of a map button - Send map command to the game to load the selected map """ - maps = self.menu_info[self.current_chapter] + maps = self.menu_info[self.selected_chapter] map_data = next((map for map in maps if map["title"] == map_name), None) if not map_data: - print(f"Map '{map_name}' not found in chapter '{self.current_chapter}'") + print(f"Map '{map_name}' not found in chapter '{self.selected_chapter}'") return + self.selected_map = map_data["title"] + # Replace the map info area if self.map_info: self.remove_widget(self.map_info) diff --git a/worlds/portal2/mod_helpers/ItemHandling.py b/worlds/portal2/mod_helpers/ItemHandling.py index cfe17512b53..961e1e56ccf 100644 --- a/worlds/portal2/mod_helpers/ItemHandling.py +++ b/worlds/portal2/mod_helpers/ItemHandling.py @@ -3,6 +3,7 @@ from ..ItemNames import motion_blur_trap, fizzle_portal_trap, butter_fingers_trap from .Gels import * from ..Locations import wheatley_monitor_table, LocationType +from ..LocationNames import * # Constants DELETE_CUBE = ItemTag.CUBE | ItemTag.DELETE @@ -161,13 +162,13 @@ def portal_gun_upgrade_not_inplace(): # Option based commands ratman_den_commands: list[MapCommand] = [ - MapCommand("sp_a1_intro4", None, ['script CreateAPButton("Ratman Den 1", Vector(847, -703, 320-65), Vector(0,-90,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_dual_lasers", None, ['script CreateAPButton("Ratman Den 2", Vector(438, -636, 827-65), Vector(0,135,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_trust_fling", None, ['script CreateAPButton("Ratman Den 3", Vector(2045, 82, 254-65), Vector(0,-135,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_bridge_intro", None, ['script CreateAPButton("Ratman Den 4", Vector(612, -618, 64-65), Vector(0,-135,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_bridge_the_gap", None, ['script CreateAPButton("Ratman Den 5", Vector(-128, -270, 1756-65), Vector(0,90,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_laser_vs_turret", None, ['script CreateAPButton("Ratman Den 6", Vector(850, -720, 222-65), Vector(0,180,0), 0.8)\n'], LocationType.RATMAN_DEN), - MapCommand("sp_a2_pull_the_rug", None, ['script CreateAPButton("Ratman Den 7", Vector(63, -1158, 550-65), Vector(0,45,0), 0.8)\n'], LocationType.RATMAN_DEN) + MapCommand("sp_a1_intro4", None, [f'script CreateAPButton("{ratman_den_1_smooth_jazz}", Vector(847, -703, 320-65), Vector(0,-90,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_dual_lasers", None, [f'script CreateAPButton("{ratman_den_2_dual_lasers}", Vector(438, -636, 827-65), Vector(0,135,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_trust_fling", None, [f'script CreateAPButton("{ratman_den_3_trust_fling}", Vector(2045, 82, 254-65), Vector(0,-135,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_bridge_intro", None, [f'script CreateAPButton("{ratman_den_4_bridge_intro}", Vector(612, -618, 64-65), Vector(0,-135,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_bridge_the_gap", None, [f'script CreateAPButton("{ratman_den_5_bridge_the_gap}", Vector(-128, -270, 1756-65), Vector(0,90,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_laser_vs_turret", None, [f'script CreateAPButton("{ratman_den_6_laser_vs_turret}", Vector(850, -720, 222-65), Vector(0,180,0), 0.8)\n'], LocationType.RATMAN_DEN), + MapCommand("sp_a2_pull_the_rug", None, [f'script CreateAPButton("{ratman_den_7_pull_the_rug}", Vector(63, -1158, 550-65), Vector(0,45,0), 0.8)\n'], LocationType.RATMAN_DEN) ] def add_ratman_commands(): From 3e806622af036e90dd866967d49ed03da0af5f92 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 08:53:28 +0100 Subject: [PATCH 09/15] Fixed Incinerator Upgrade Bug --- worlds/portal2/mod_helpers/ItemHandling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/portal2/mod_helpers/ItemHandling.py b/worlds/portal2/mod_helpers/ItemHandling.py index 961e1e56ccf..0c1ff6ac245 100644 --- a/worlds/portal2/mod_helpers/ItemHandling.py +++ b/worlds/portal2/mod_helpers/ItemHandling.py @@ -158,7 +158,7 @@ def potatos_not_inplace(): def portal_gun_upgrade_not_inplace(): global map_specific_commands - map_specific_commands.append(MapCommand("sp_a2_intro", portal_gun_2, ["script InciniratorDisablePortalGun()\n"])) + map_specific_commands.append(MapCommand("sp_a2_intro", portal_gun_2, ["script IncineratorDisablePortalGun()\n"])) # Option based commands ratman_den_commands: list[MapCommand] = [ From 539e14728b736a673124d9d9220c79c1ec332e39 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 18:10:52 +0100 Subject: [PATCH 10/15] Updated menu layout and autoformat --- worlds/portal2/client/P2Context.py | 174 +++++++++++++++++------------ 1 file changed, 102 insertions(+), 72 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 4afbb40913f..83dc61f8984 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -25,15 +25,16 @@ logger = logging.getLogger("Portal2Client") + async def send_instant_command(command: str): - try: - _, writer = await asyncio.open_connection(HOST, PORT) - writer.write((command + "\n").encode()) - await writer.drain() - writer.close() - await writer.wait_closed() - except: - logger.error(f"Connection to portal 2 failed for instant command") + try: + _, writer = await asyncio.open_connection(HOST, PORT) + writer.write((command + "\n").encode()) + await writer.drain() + writer.close() + await writer.wait_closed() + except: + logger.error(f"Connection to portal 2 failed for instant command") class P2ClientCommandProcessor(ClientCommandProcessor): @@ -41,6 +42,7 @@ class P2ClientCommandProcessor(ClientCommandProcessor): def __init__(self, context: "P2CommonContext"): super().__init__(context) + class MapInfo(MDGridLayout): def __init__(self, map_data: dict): @@ -50,71 +52,73 @@ def __init__(self, map_data: dict): def build(self): chapter_info_string = f"{self.map_data["title"]}\n\nRequired Items:\n" - + if self.map_data["required_items"]: - chapter_info_string += ', '.join(self.map_data["required_items"]) + chapter_info_string += ", ".join(self.map_data["required_items"]) else: chapter_info_string += "All required items acquired" - - chapter_info_string += "\n\n" - + + chapter_info_string += "\n\n" + if self.map_data["sub_locations"]: chapter_info_string += "Sub locations:\n" - sub_locations_incomplete = [name for name, complete in self.map_data["sub_locations"].items() if not complete] + sub_locations_incomplete = [ + name + for name, complete in self.map_data["sub_locations"].items() + if not complete + ] if sub_locations_incomplete: - chapter_info_string += ', '.join(sub_locations_incomplete) + chapter_info_string += ", ".join(sub_locations_incomplete) else: chapter_info_string += "All sublocations completed" - + self.chapter_info = MDLabel(text=chapter_info_string) if self.map_data["disabled"]: self.play_map_button = MDButton( - MDButtonText(text="Map not yet available"), - disabled=True - ) + MDButtonText(text="Map not yet available"), disabled=True + ) else: self.play_map_button = MDButton( - MDButtonText(text="Play Map"), - on_release=lambda btn: self.play_map() - ) - - + MDButtonText(text="Play Map"), on_release=lambda btn: self.play_map() + ) + # Add all these to the layout self.add_widget(self.chapter_info) self.add_widget(self.play_map_button) - - + def play_map(self): """ Send map command to the game to load the selected map """ - - async_start(send_instant_command(f"{self.map_data['command']}"), "send_map_command") - + + async_start( + send_instant_command(f"{self.map_data['command']}"), "send_map_command" + ) + + class ChapterButton(MDButton): - + def __init__(self, chapter_name: str, chapter_maps: list, on_release): self.chapter_name = chapter_name self.chapter_maps = chapter_maps finished_checks, total_checks = self.calculate_completeness() - - self.button_text = MDButtonText(text=f"{self.chapter_name} {finished_checks}/{total_checks}") - - super().__init__( - self.button_text, - on_release = on_release + + self.button_text = MDButtonText( + text=f"{self.chapter_name} {finished_checks}/{total_checks}" ) - + + super().__init__(self.button_text, on_release=on_release) + def calculate_completeness(self) -> tuple: total_checks = 0 finished_checks = 0 for map in self.chapter_maps: total_checks += map["total_locations"] finished_checks += map["finished_locations"] - + return finished_checks, total_checks - + def update_title(self, chapter_maps: dict): self.chapter_maps = chapter_maps finished_checks, total_checks = self.calculate_completeness() @@ -124,7 +128,7 @@ def update_title(self, chapter_maps: dict): class MenuLayout(MDGridLayout): def __init__(self): - super().__init__(rows=1, cols=3, padding=[40, 10]) + super().__init__(rows=1, cols=3, padding=[40, 10], spacing=dp(10)) self.menu_info = [] self.selected_chapter = None self.selected_map = None @@ -140,20 +144,20 @@ def update_menu(self, menu_data: dict[str, dict]): - Update the menu """ self.menu_info = menu_data - + self.refresh_chapter_titles() - + selected_chapter = self.selected_chapter or list(self.menu_info.keys())[0] if self.map_area is not None: self.select_chapter(selected_chapter) - + if self.selected_map: self.select_map(self.selected_map) - + def refresh_chapter_titles(self): for cb in self.chapter_buttons: cb.update_title(self.menu_info[cb.chapter_name]) - + def set_open_world(self): self.is_open_world = True @@ -162,47 +166,73 @@ def build(self): - List of chapter buttons on the left side - Add a dynamic list of map buttons on the right side of the grid that updates based on the selected chapter """ - + if self.menu_info is None: - raise Exception("Menu data not set. Call update_menu() once before build().") + raise Exception( + "Menu data not set. Call update_menu() once before build()." + ) self.clear_widgets() - self.chapter_area = MDGridLayout(rows=10, cols=1) + self.chapter_area = ScrollBox() + self.chapter_area.layout.orientation = "vertical" + self.chapter_area.layout.spacing = dp(3) + self.chapter_area.scroll_type = ["bars"] + self.chapter_area.do_scroll_x = False + self.add_widget(self.chapter_area) + self.map_area = ScrollBox() self.map_area.layout.orientation = "vertical" self.map_area.layout.spacing = dp(3) self.map_area.scroll_type = ["bars"] self.map_area.do_scroll_x = False - self.add_widget(self.chapter_area) self.add_widget(self.map_area) - for chapter_name, maps in self.menu_info.items(): - chapter_button = ChapterButton(chapter_name, maps, lambda btn, chapter=chapter_name: self.select_chapter(chapter)) + for chapter_name, maps in self.menu_info.items(): + chapter_button = ChapterButton( + chapter_name, + maps, + lambda btn, chapter=chapter_name: self.select_chapter(chapter), + ) self.chapter_buttons.append(chapter_button) - self.chapter_area.add_widget(chapter_button) - - menu_toggle_box = MDGridLayout(cols=2, row_default_height=40, row_force_default=True, padding=10) - self.auto_next_map_button = MDIconButton(icon = "checkbox-blank-outline", on_release=self.toggle_switch) + self.chapter_area.layout.add_widget(chapter_button) + + menu_toggle_box = MDGridLayout( + cols=2, + row_default_height=40, + row_force_default=True, + padding=dp(10), + md_bg_color=[1, 1, 1, 0.1], + width=dp(200), + size_hint_x=None, + height=dp(60), + size_hint_y=None, + line_color=[0, 0, 0, 0], + radius=dp(10), + ) + self.auto_next_map_button = MDIconButton( + icon="checkbox-blank-outline", on_release=self.toggle_switch + ) button_label = MDLabel(text="Return to menu on map finish: ") menu_toggle_box.add_widget(button_label) menu_toggle_box.add_widget(self.auto_next_map_button) - self.chapter_area.add_widget(menu_toggle_box) - + self.chapter_area.layout.add_widget(menu_toggle_box) def select_chapter(self, chapter_name: str): """ - Remove the old map buttons - Add the list of new map buttons """ - + if self.map_area is None: - raise Exception("Map area not initialized. Call build() before select_chapter().") - + raise Exception( + "Map area not initialized. Call build() before select_chapter()." + ) + self.selected_chapter = chapter_name for child in self.map_area.layout.children[:]: self.map_area.layout.remove_widget(child) - + if not self.menu_info: no_maps_label = MDButton( MDButtonText(text="No maps available for this chapter"), @@ -215,10 +245,12 @@ def select_chapter(self, chapter_name: str): disable_map = False for map in map_data: map_button = MDButton( - MDButtonText(text=f"{map['title']} {map["finished_locations"]}/{map["total_locations"]}"), - on_release=lambda btn, _map_name=map['title']: self.select_map( + MDButtonText( + text=f"{map['title']} {map["finished_locations"]}/{map["total_locations"]}" + ), + on_release=lambda btn, _map_name=map["title"]: self.select_map( _map_name, - ) + ), ) self.map_area.layout.add_widget(map_button) map["disabled"] = disable_map @@ -232,32 +264,30 @@ def select_map(self, map_name: str): """ maps = self.menu_info[self.selected_chapter] map_data = next((map for map in maps if map["title"] == map_name), None) - + if not map_data: print(f"Map '{map_name}' not found in chapter '{self.selected_chapter}'") return - + self.selected_map = map_data["title"] - + # Replace the map info area if self.map_info: self.remove_widget(self.map_info) - + self.map_info = MapInfo(map_data) self.add_widget(self.map_info) - + def toggle_switch(self, instance): self.return_to_menu = not self.return_to_menu if self.return_to_menu: self.auto_next_map_button.icon = "checkbox-outline" else: self.auto_next_map_button.icon = "checkbox-blank-outline" - - logger.info(self.return_to_menu) class P2GameManager(GameManager): - + def build(self): container = super().build() From 036764bd94420f5560672bba124520648f18b9fb Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 18:50:15 +0100 Subject: [PATCH 11/15] Fixed UT integration --- worlds/portal2/client/P2Context.py | 6 ++++-- worlds/portal2/client/Portal2Client.py | 9 +-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 83dc61f8984..5c39085c2da 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -2,7 +2,7 @@ try: from worlds.tracker.TrackerClient import ( TrackerGameContext as CommonContext, - TrackerCommandProcessor as ClientCommandProcessor, + TrackerCommandProcessor as ClientCommandProcessor ) tracker_loaded = True @@ -300,8 +300,10 @@ def build(self): class P2CommonContext(CommonContext): def make_gui(self) -> "type[kvui.GameManager]": - class TextManager(P2GameManager): + ui = super().make_gui() + class TextManager(ui, P2GameManager): base_title = "Portal 2 Text Client" + icon = r"worlds/portal2/data/Portalpelago.png" return TextManager diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 82efdbff6c0..51d9a86c585 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -477,14 +477,7 @@ def update_item_remove_commands(self): self.item_remove_commands = temp_commands - def make_gui(self): - from kvui import GameManager - ui = super().make_gui() - ui.base_title = "Portal 2 Client" - ui.icon = r"worlds/portal2/data/Portalpelago.png" - - return ui - + async def shutdown(self): self.server_address = "" self.username = None From b613a2ee3a140655384cf0cf1e2c9d66b822797c Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 19:47:05 +0100 Subject: [PATCH 12/15] Updated version number and removed test command --- worlds/portal2/archipelago.json | 2 +- worlds/portal2/client/Portal2Client.py | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/worlds/portal2/archipelago.json b/worlds/portal2/archipelago.json index 678c4945733..5053d4a887e 100644 --- a/worlds/portal2/archipelago.json +++ b/worlds/portal2/archipelago.json @@ -2,5 +2,5 @@ "game": "Portal 2", "authors": [ "GlassToadstool" ], "minimum_ap_version": "0.6.5", - "world_version": "0.7.3" + "world_version": "0.8.0" } \ No newline at end of file diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 51d9a86c585..be9caa71d33 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -69,13 +69,7 @@ def _cmd_needed(self, *location_name): f"{"All items acquired" if not requirements_not_collected else "Still needed: \n" + ", ".join(requirements_not_collected)}") break self.output(message) - - def _cmd_ping(self): - async def player_in_map(compro): - is_in_map = await compro.ctx.is_player_in_map() - compro.output("pong" if is_in_map else "no pong recieved from server") - loop = asyncio.get_event_loop() - loop.create_task(player_in_map(self)) + class Portal2Context(CommonContext): command_processor = Portal2CommandProcessor From d07755202dfce8b11c8228bd5efa561875bb85d5 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 20:34:25 +0100 Subject: [PATCH 13/15] visual change --- worlds/portal2/client/P2Context.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 5c39085c2da..082dc4d24db 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -46,7 +46,7 @@ def __init__(self, context: "P2CommonContext"): class MapInfo(MDGridLayout): def __init__(self, map_data: dict): - super().__init__(rows=2, cols=1, padding=[0, 50]) + super().__init__(rows=2, cols=1) self.map_data = map_data self.build() @@ -191,7 +191,7 @@ def build(self): chapter_button = ChapterButton( chapter_name, maps, - lambda btn, chapter=chapter_name: self.select_chapter(chapter), + lambda btn, chapter=chapter_name: self.select_chapter(chapter) ) self.chapter_buttons.append(chapter_button) self.chapter_area.layout.add_widget(chapter_button) @@ -202,11 +202,10 @@ def build(self): row_force_default=True, padding=dp(10), md_bg_color=[1, 1, 1, 0.1], - width=dp(200), + width=dp(220), size_hint_x=None, height=dp(60), size_hint_y=None, - line_color=[0, 0, 0, 0], radius=dp(10), ) self.auto_next_map_button = MDIconButton( From 185fdf72f1a82f76575464831af352772f3718ad Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 22:45:08 +0100 Subject: [PATCH 14/15] Structure refactoring --- worlds/portal2/client/P2Context.py | 128 ++++++++++++++++++------- worlds/portal2/client/Portal2Client.py | 3 +- worlds/portal2/mod_helpers/MapMenu.py | 2 + 3 files changed, 99 insertions(+), 34 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 082dc4d24db..74c8a179676 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -2,7 +2,7 @@ try: from worlds.tracker.TrackerClient import ( TrackerGameContext as CommonContext, - TrackerCommandProcessor as ClientCommandProcessor + TrackerCommandProcessor as ClientCommandProcessor, ) tracker_loaded = True @@ -14,6 +14,8 @@ from Utils import async_start from kvui import GameManager, ScrollBox from kivy.metrics import dp +from kivy.uix.behaviors import ButtonBehavior +from kivymd.uix.boxlayout import MDBoxLayout from kivymd.uix.gridlayout import MDGridLayout from kivymd.uix.button import MDButton, MDButtonText, MDIconButton from kivymd.uix.label import MDLabel @@ -97,18 +99,55 @@ def play_map(self): ) -class ChapterButton(MDButton): +class SelectableButton(ButtonBehavior, MDBoxLayout): + def __init__(self, name_text: str, count_text: str, on_release): + self.name = name_text + super().__init__( + orientation="horizontal", + padding=[dp(12), dp(8)], + spacing=dp(8), + size_hint_y=None, + height=dp(40), + width=dp(220), + size_hint_x=None, + md_bg_color=[1, 1, 1, 0.12], + radius=dp(6), + ) + + self.name_label = MDLabel( + text=name_text, + width=dp(150), + size_hint_x=None, + halign="left" + ) + self.count_label = MDLabel( + text=count_text, + halign="right", + ) + + self.add_widget(self.name_label) + self.add_widget(self.count_label) + + if on_release is not None: + self.bind(on_release=on_release) + + + def select(self): + self.md_bg_color = [1, 1, 1, 0.3] + + def deselect(self): + self.md_bg_color=[1, 1, 1, 0.12] + + +class ChapterButton(SelectableButton): def __init__(self, chapter_name: str, chapter_maps: list, on_release): self.chapter_name = chapter_name self.chapter_maps = chapter_maps finished_checks, total_checks = self.calculate_completeness() - - self.button_text = MDButtonText( - text=f"{self.chapter_name} {finished_checks}/{total_checks}" - ) - - super().__init__(self.button_text, on_release=on_release) + + super().__init__(self.chapter_name, f"{finished_checks}/{total_checks}", on_release) + def calculate_completeness(self) -> tuple: total_checks = 0 @@ -122,7 +161,7 @@ def calculate_completeness(self) -> tuple: def update_title(self, chapter_maps: dict): self.chapter_maps = chapter_maps finished_checks, total_checks = self.calculate_completeness() - self.button_text.text = f"{self.chapter_name} {finished_checks}/{total_checks}" + self.count_label.text = f"{finished_checks}/{total_checks}" class MenuLayout(MDGridLayout): @@ -130,13 +169,15 @@ class MenuLayout(MDGridLayout): def __init__(self): super().__init__(rows=1, cols=3, padding=[40, 10], spacing=dp(10)) self.menu_info = [] - self.selected_chapter = None - self.selected_map = None + self.selected_chapter_btn: ChapterButton = None + self.selected_map_btn: SelectableButton = None self.map_area = None self.map_info = None self.is_open_world = False self.return_to_menu = False self.chapter_buttons: list[ChapterButton] = [] + self.map_buttons: list[SelectableButton] = [] + self.built = False def update_menu(self, menu_data: dict[str, dict]): """ @@ -147,12 +188,11 @@ def update_menu(self, menu_data: dict[str, dict]): self.refresh_chapter_titles() - selected_chapter = self.selected_chapter or list(self.menu_info.keys())[0] - if self.map_area is not None: - self.select_chapter(selected_chapter) + if self.map_area and self.selected_chapter_btn: + self.select_chapter(self.selected_chapter_btn.name, self.selected_chapter_btn) - if self.selected_map: - self.select_map(self.selected_map) + if self.selected_map_btn: + self.select_map(self.selected_map_btn.name) def refresh_chapter_titles(self): for cb in self.chapter_buttons: @@ -166,6 +206,11 @@ def build(self): - List of chapter buttons on the left side - Add a dynamic list of map buttons on the right side of the grid that updates based on the selected chapter """ + + if self.built: + return + + self.built = True if self.menu_info is None: raise Exception( @@ -191,7 +236,7 @@ def build(self): chapter_button = ChapterButton( chapter_name, maps, - lambda btn, chapter=chapter_name: self.select_chapter(chapter) + lambda btn, chapter=chapter_name: self.select_chapter(chapter, btn), ) self.chapter_buttons.append(chapter_button) self.chapter_area.layout.add_widget(chapter_button) @@ -216,60 +261,76 @@ def build(self): menu_toggle_box.add_widget(self.auto_next_map_button) self.chapter_area.layout.add_widget(menu_toggle_box) - def select_chapter(self, chapter_name: str): + def select_chapter(self, chapter_name: str, btn: ChapterButton = None): """ - Remove the old map buttons - Add the list of new map buttons """ + + if self.selected_chapter_btn: + self.selected_chapter_btn.deselect() + + if btn: + self.selected_chapter_btn = btn + self.selected_chapter_btn.select() if self.map_area is None: raise Exception( "Map area not initialized. Call build() before select_chapter()." ) - self.selected_chapter = chapter_name for child in self.map_area.layout.children[:]: self.map_area.layout.remove_widget(child) if not self.menu_info: - no_maps_label = MDButton( - MDButtonText(text="No maps available for this chapter"), - disabled=True, - ) + no_maps_label = MDLabel(text="No maps available for this chapter") self.map_area.layout.add_widget(no_maps_label) return + self.map_buttons = [] map_data = self.menu_info[chapter_name] disable_map = False for map in map_data: - map_button = MDButton( - MDButtonText( - text=f"{map['title']} {map["finished_locations"]}/{map["total_locations"]}" - ), + map_button = SelectableButton( + map['title'], + f"{map["finished_locations"]}/{map["total_locations"]}", on_release=lambda btn, _map_name=map["title"]: self.select_map( - _map_name, + _map_name, btn ), ) + self.map_buttons.append(map_button) self.map_area.layout.add_widget(map_button) map["disabled"] = disable_map if not self.is_open_world: disable_map = not map["completed"] - def select_map(self, map_name: str): + def select_map(self, map_name: str, btn: SelectableButton = None): """ - Handle the selection of a map button - Send map command to the game to load the selected map """ - maps = self.menu_info[self.selected_chapter] + + if self.selected_map_btn: + self.selected_map_btn.deselect() + + if btn: + self.selected_map_btn = btn + else: + possible_buttons = [btn for btn in self.map_buttons if btn.name == map_name] + if len(possible_buttons) > 0: + self.selected_map_btn = possible_buttons[0] + + self.selected_map_btn.select() + + + maps = self.menu_info[self.selected_chapter_btn.chapter_name] map_data = next((map for map in maps if map["title"] == map_name), None) if not map_data: - print(f"Map '{map_name}' not found in chapter '{self.selected_chapter}'") + print(f"Map '{map_name}' not found in chapter '{self.selected_chapter_btn.chapter_name}'") return - self.selected_map = map_data["title"] - # Replace the map info area if self.map_info: self.remove_widget(self.map_info) @@ -300,6 +361,7 @@ class P2CommonContext(CommonContext): def make_gui(self) -> "type[kvui.GameManager]": ui = super().make_gui() + class TextManager(ui, P2GameManager): base_title = "Portal 2 Text Client" icon = r"worlds/portal2/data/Portalpelago.png" diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index be9caa71d33..5ad2880190e 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -402,7 +402,8 @@ def handle_slot_data(self, slot_data: dict): potatos_not_inplace() self.game_map_menu.generate_menu() - self.client_map_menu = self.get_menu() + if not self.client_map_menu: + self.client_map_menu = self.get_menu() self.refresh_menu() self.client_map_menu.build() diff --git a/worlds/portal2/mod_helpers/MapMenu.py b/worlds/portal2/mod_helpers/MapMenu.py index 9b8e2d17ba0..8b4fd7f3820 100644 --- a/worlds/portal2/mod_helpers/MapMenu.py +++ b/worlds/portal2/mod_helpers/MapMenu.py @@ -302,6 +302,8 @@ def __init__( self.chapter_dict = chapter_dict def generate_menu(self): + if self.chapters: + return for chapter_number, map_names in self.chapter_dict.items(): self.chapters.append(ChapterMenuElement(self, chapter_number, map_names)) From a6a327697a2e268d80c986b8b0e9e243f4040603 Mon Sep 17 00:00:00 2001 From: GlassToadstool Date: Sat, 1 Aug 2026 23:26:51 +0100 Subject: [PATCH 15/15] Transition menu to next map to mirror game --- worlds/portal2/client/P2Context.py | 16 ++++++++++++---- worlds/portal2/client/Portal2Client.py | 4 +--- worlds/portal2/mod_helpers/MapMenu.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/worlds/portal2/client/P2Context.py b/worlds/portal2/client/P2Context.py index 74c8a179676..d879b9b7de3 100644 --- a/worlds/portal2/client/P2Context.py +++ b/worlds/portal2/client/P2Context.py @@ -158,7 +158,7 @@ def calculate_completeness(self) -> tuple: return finished_checks, total_checks - def update_title(self, chapter_maps: dict): + def update_title(self, chapter_maps: list): self.chapter_maps = chapter_maps finished_checks, total_checks = self.calculate_completeness() self.count_label.text = f"{finished_checks}/{total_checks}" @@ -168,7 +168,7 @@ class MenuLayout(MDGridLayout): def __init__(self): super().__init__(rows=1, cols=3, padding=[40, 10], spacing=dp(10)) - self.menu_info = [] + self.menu_info = {} self.selected_chapter_btn: ChapterButton = None self.selected_map_btn: SelectableButton = None self.map_area = None @@ -179,7 +179,7 @@ def __init__(self): self.map_buttons: list[SelectableButton] = [] self.built = False - def update_menu(self, menu_data: dict[str, dict]): + def update_menu(self, menu_data: dict[str, list], map_finished: bool = False): """ - Set the map data - Update the menu @@ -192,7 +192,15 @@ def update_menu(self, menu_data: dict[str, dict]): self.select_chapter(self.selected_chapter_btn.name, self.selected_chapter_btn) if self.selected_map_btn: - self.select_map(self.selected_map_btn.name) + if not self.return_to_menu and map_finished: + # Try to select next map in chapter + current_chapter = next((m for m in self.map_buttons if m.name == self.selected_map_btn.name), None) + if current_chapter: + index = self.map_buttons.index(current_chapter) + if index + 1 < len(self.map_buttons): + self.select_map(self.map_buttons[index+1].name, self.map_buttons[index+1]) + else: + self.select_map(self.selected_map_btn.name) def refresh_chapter_titles(self): for cb in self.chapter_buttons: diff --git a/worlds/portal2/client/Portal2Client.py b/worlds/portal2/client/Portal2Client.py index 5ad2880190e..e8ce59819fd 100644 --- a/worlds/portal2/client/Portal2Client.py +++ b/worlds/portal2/client/Portal2Client.py @@ -114,7 +114,7 @@ def update_menu(self, location_id: int = None): with open(menu_file, "w", encoding='utf-8') as f: f.write(str(self.game_map_menu)) - self.client_map_menu.update_menu(self.game_map_menu.get_menu_info()) + self.client_map_menu.update_menu(self.game_map_menu.get_menu_info(), type(check_completed) == str) return check_completed def refresh_menu(self): @@ -262,8 +262,6 @@ async def handle_message(self, message: str): if done_map == self.goal_map_code: await self.handle_goal_completion() else: - logger.info(self.client_map_menu.return_to_menu) - logger.info(next_map) if not self.client_map_menu.return_to_menu and type(next_map) == str: await send_instant_command(f"changelevel {next_map}") else: diff --git a/worlds/portal2/mod_helpers/MapMenu.py b/worlds/portal2/mod_helpers/MapMenu.py index 8b4fd7f3820..8144722ae43 100644 --- a/worlds/portal2/mod_helpers/MapMenu.py +++ b/worlds/portal2/mod_helpers/MapMenu.py @@ -325,7 +325,7 @@ def complete_check(self, location_id: int) -> str | bool: return found_check return False - def get_menu_info(self) -> dict[str, dict]: + def get_menu_info(self) -> dict[str, list]: menu_info = {} for chapter in self.chapters: chapter_info = chapter.get_chapter_info()