From b53d1f94582ebc62eb0520f041f83baecb747c0a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 4 Oct 2025 16:06:32 -0400 Subject: Added button to get logical path --- apworld/context.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'apworld/context.py') diff --git a/apworld/context.py b/apworld/context.py index e78ce35..7b5f0bc 100644 --- a/apworld/context.py +++ b/apworld/context.py @@ -229,6 +229,21 @@ class Lingo2GameContext: async_start(self.send_msgs([msg]), name="update worldports") + def send_path_reply(self, object_type: str, object_id: int | None, path: list[str]): + if self.server is None: + return + + msg = { + "cmd": "PathReply", + "type": object_type, + "path": path, + } + + if object_id is not None: + msg["id"] = object_id + + async_start(self.send_msgs([msg]), name="path reply") + 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: @@ -542,6 +557,17 @@ async def process_game_cmd(manager: Lingo2Manager, args: dict): if len(updates) > 0: async_start(manager.client_ctx.update_worldports(updates), name="client update worldports") manager.game_ctx.send_update_worldports(updates) + elif cmd == "GetPath": + path = None + + if args["type"] == "location": + path = manager.tracker.get_path_to_location(args["id"]) + elif args["type"] == "worldport": + path = manager.tracker.get_path_to_port(args["id"]) + elif args["type"] == "goal": + path = manager.tracker.get_path_to_goal() + + manager.game_ctx.send_path_reply(args["type"], args.get("id", None), path) elif cmd == "Quit": manager.client_ctx.exit_event.set() -- cgit 1.4.1