From 99191f3aa87b2362516971c1fdd64d21b16f87b7 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 29 Sep 2025 12:31:01 -0400 Subject: Show when goal is reachable in tracker --- apworld/context.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'apworld/context.py') diff --git a/apworld/context.py b/apworld/context.py index 4b78517..0e1a125 100644 --- a/apworld/context.py +++ b/apworld/context.py @@ -10,7 +10,7 @@ import Utils import settings from BaseClasses import ItemClassification from CommonClient import CommonContext, server_loop, gui_enabled, logger, get_base_parser, handle_url_arg -from NetUtils import Endpoint, decode, encode +from NetUtils import Endpoint, decode, encode, ClientStatus from Utils import async_start from . import Lingo2World from .tracker import Tracker @@ -36,6 +36,7 @@ class Lingo2Manager: keyboard: dict[str, int] worldports: set[int] + goaled: bool def __init__(self, game_ctx: "Lingo2GameContext", client_ctx: "Lingo2ClientContext"): self.game_ctx = game_ctx @@ -53,6 +54,7 @@ class Lingo2Manager: self.keyboard[k] = 0 self.worldports = set() + self.goaled = False def update_keyboard(self, new_keyboard: dict[str, int]) -> dict[str, int]: ret: dict[str, int] = {} @@ -177,6 +179,9 @@ class Lingo2GameContext: if len(self.manager.tracker.accessible_worldports) > 0: msg["worldports"] = list(self.manager.tracker.accessible_worldports) + if self.manager.tracker.goal_accessible and not self.manager.goaled: + msg["goal"] = True + async_start(self.send_msgs([msg]), name="accessible locations") def send_update_locations(self, locations): @@ -226,6 +231,7 @@ class Lingo2ClientContext(CommonContext): items_handling = 0b111 slot_data: dict[str, Any] | None + victory_data_storage_key: str def __init__(self, server_address: str | None = None, password: str | None = None): super().__init__(server_address, password) @@ -253,7 +259,10 @@ class Lingo2ClientContext(CommonContext): self.manager.tracker.set_checked_locations(self.checked_locations) self.manager.game_ctx.send_accessible_locations() - self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2")) + self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}" + + self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"), + self.victory_data_storage_key) msg_batch = [{ "cmd": "Set", "key": self.get_datastorage_key("keyboard1"), @@ -360,6 +369,9 @@ class Lingo2ClientContext(CommonContext): }) self.manager.game_ctx.send_location_info(locations) + elif cmd == "Received": + if args["key"] == self.victory_data_storage_key: + self.handle_status_update(args["value"]) elif cmd == "SetReply": if args["key"] == self.get_datastorage_key("keyboard1"): self.handle_keyboard_update(1, args) @@ -369,6 +381,8 @@ class Lingo2ClientContext(CommonContext): updates = self.manager.update_worldports(set(args["value"])) if len(updates) > 0: self.manager.game_ctx.send_update_worldports(updates) + elif args["key"] == self.victory_data_storage_key: + self.handle_status_update(args["value"]) def get_datastorage_key(self, name: str): return f"Lingo2_{self.slot}_{name}" @@ -445,6 +459,11 @@ class Lingo2ClientContext(CommonContext): }] }]) + def handle_status_update(self, value: int): + self.manager.goaled = (value == ClientStatus.CLIENT_GOAL) + self.manager.tracker.refresh_state() + self.manager.game_ctx.send_accessible_locations() + async def pipe_loop(manager: Lingo2Manager): while not manager.client_ctx.exit_event.is_set(): -- cgit 1.4.1