From adfc639965b2bda776ceb0a20840438e31f82d58 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 2 Nov 2025 12:29:29 -0500 Subject: Allow ignoring locations in tracker --- apworld/context.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'apworld/context.py') diff --git a/apworld/context.py b/apworld/context.py index 52b04ae..e5ba3cf 100644 --- a/apworld/context.py +++ b/apworld/context.py @@ -57,8 +57,6 @@ class Lingo2Manager: self.client_ctx.manager = self self.tracker = Tracker(self) self.keyboard = {} - self.worldports = set() - self.latches = set() self.reset() @@ -276,6 +274,17 @@ class Lingo2GameContext: async_start(self.send_msgs([msg]), name="update latches") + def send_ignored_locations(self, ignored_locations): + if self.server is None: + return + + msg = { + "cmd": "SetIgnoredLocations", + "locations": ignored_locations, + } + + async_start(self.send_msgs([msg]), name="set ignored locations") + async def send_msgs(self, msgs: list[Any]) -> None: """ `msgs` JSON serializable """ if not self.server or not self.server.socket.open or self.server.socket.closed: @@ -330,7 +339,8 @@ class Lingo2ClientContext(CommonContext): 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, self.get_datastorage_key("latches")) + self.victory_data_storage_key, self.get_datastorage_key("latches"), + self.get_datastorage_key("ignored_locations")) msg_batch = [{ "cmd": "Set", "key": self.get_datastorage_key("keyboard1"), @@ -349,6 +359,12 @@ class Lingo2ClientContext(CommonContext): "default": [], "want_reply": True, "operations": [{"operation": "default", "value": []}] + }, { + "cmd": "Set", + "key": self.get_datastorage_key("ignored_locations"), + "default": [], + "want_reply": True, + "operations": [{"operation": "default", "value": []}] }] if self.slot_data.get("shuffle_worldports", False): @@ -464,6 +480,8 @@ class Lingo2ClientContext(CommonContext): updates = self.manager.update_latches(door_ids) if len(updates) > 0: self.manager.game_ctx.send_update_latches(updates) + elif args["key"] == self.get_datastorage_key("ignored_locations"): + self.manager.game_ctx.send_ignored_locations(args["value"]) def get_datastorage_key(self, name: str): return f"Lingo2_{self.slot}_{name}" @@ -559,6 +577,28 @@ class Lingo2ClientContext(CommonContext): }] }]) + async def add_ignored_location(self, loc_id: int): + await self.send_msgs([{ + "cmd": "Set", + "key": self.get_datastorage_key("ignored_locations"), + "want_reply": True, + "operations": [{ + "operation": "update", + "value": [loc_id] + }] + }]) + + async def remove_ignored_location(self, loc_id: int): + await self.send_msgs([{ + "cmd": "Set", + "key": self.get_datastorage_key("ignored_locations"), + "want_reply": True, + "operations": [{ + "operation": "remove", + "value": loc_id + }] + }]) + async def pipe_loop(manager: Lingo2Manager): while not manager.client_ctx.exit_event.is_set(): @@ -635,6 +675,10 @@ async def process_game_cmd(manager: Lingo2Manager, args: dict): updates = manager.update_latches({args["door"]}) if len(updates) > 0: async_start(manager.client_ctx.update_latches(updates), name="client update latches") + elif cmd == "IgnoreLocation": + async_start(manager.client_ctx.add_ignored_location(args["id"]), name="client ignore loc") + elif cmd == "UnignoreLocation": + async_start(manager.client_ctx.remove_ignored_location(args["id"]), name="client unignore loc") elif cmd == "Quit": manager.client_ctx.exit_event.set() -- cgit 1.4.1