diff options
Diffstat (limited to 'apworld/context.py')
| -rw-r--r-- | apworld/context.py | 26 |
1 files changed, 26 insertions, 0 deletions
| 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: | |||
| 229 | 229 | ||
| 230 | async_start(self.send_msgs([msg]), name="update worldports") | 230 | async_start(self.send_msgs([msg]), name="update worldports") |
| 231 | 231 | ||
| 232 | def send_path_reply(self, object_type: str, object_id: int | None, path: list[str]): | ||
| 233 | if self.server is None: | ||
| 234 | return | ||
| 235 | |||
| 236 | msg = { | ||
| 237 | "cmd": "PathReply", | ||
| 238 | "type": object_type, | ||
| 239 | "path": path, | ||
| 240 | } | ||
| 241 | |||
| 242 | if object_id is not None: | ||
| 243 | msg["id"] = object_id | ||
| 244 | |||
| 245 | async_start(self.send_msgs([msg]), name="path reply") | ||
| 246 | |||
| 232 | async def send_msgs(self, msgs: list[Any]) -> None: | 247 | async def send_msgs(self, msgs: list[Any]) -> None: |
| 233 | """ `msgs` JSON serializable """ | 248 | """ `msgs` JSON serializable """ |
| 234 | if not self.server or not self.server.socket.open or self.server.socket.closed: | 249 | 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): | |||
| 542 | if len(updates) > 0: | 557 | if len(updates) > 0: |
| 543 | async_start(manager.client_ctx.update_worldports(updates), name="client update worldports") | 558 | async_start(manager.client_ctx.update_worldports(updates), name="client update worldports") |
| 544 | manager.game_ctx.send_update_worldports(updates) | 559 | manager.game_ctx.send_update_worldports(updates) |
| 560 | elif cmd == "GetPath": | ||
| 561 | path = None | ||
| 562 | |||
| 563 | if args["type"] == "location": | ||
| 564 | path = manager.tracker.get_path_to_location(args["id"]) | ||
| 565 | elif args["type"] == "worldport": | ||
| 566 | path = manager.tracker.get_path_to_port(args["id"]) | ||
| 567 | elif args["type"] == "goal": | ||
| 568 | path = manager.tracker.get_path_to_goal() | ||
| 569 | |||
| 570 | manager.game_ctx.send_path_reply(args["type"], args.get("id", None), path) | ||
| 545 | elif cmd == "Quit": | 571 | elif cmd == "Quit": |
| 546 | manager.client_ctx.exit_event.set() | 572 | manager.client_ctx.exit_event.set() |
| 547 | 573 | ||
