about summary refs log tree commit diff stats
path: root/apworld/context.py
diff options
context:
space:
mode:
Diffstat (limited to 'apworld/context.py')
-rw-r--r--apworld/context.py50
1 files changed, 47 insertions, 3 deletions
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:
57 self.client_ctx.manager = self 57 self.client_ctx.manager = self
58 self.tracker = Tracker(self) 58 self.tracker = Tracker(self)
59 self.keyboard = {} 59 self.keyboard = {}
60 self.worldports = set()
61 self.latches = set()
62 60
63 self.reset() 61 self.reset()
64 62
@@ -276,6 +274,17 @@ class Lingo2GameContext:
276 274
277 async_start(self.send_msgs([msg]), name="update latches") 275 async_start(self.send_msgs([msg]), name="update latches")
278 276
277 def send_ignored_locations(self, ignored_locations):
278 if self.server is None:
279 return
280
281 msg = {
282 "cmd": "SetIgnoredLocations",
283 "locations": ignored_locations,
284 }
285
286 async_start(self.send_msgs([msg]), name="set ignored locations")
287
279 async def send_msgs(self, msgs: list[Any]) -> None: 288 async def send_msgs(self, msgs: list[Any]) -> None:
280 """ `msgs` JSON serializable """ 289 """ `msgs` JSON serializable """
281 if not self.server or not self.server.socket.open or self.server.socket.closed: 290 if not self.server or not self.server.socket.open or self.server.socket.closed:
@@ -330,7 +339,8 @@ class Lingo2ClientContext(CommonContext):
330 self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}" 339 self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}"
331 340
332 self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"), 341 self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"),
333 self.victory_data_storage_key, self.get_datastorage_key("latches")) 342 self.victory_data_storage_key, self.get_datastorage_key("latches"),
343 self.get_datastorage_key("ignored_locations"))
334 msg_batch = [{ 344 msg_batch = [{
335 "cmd": "Set", 345 "cmd": "Set",
336 "key": self.get_datastorage_key("keyboard1"), 346 "key": self.get_datastorage_key("keyboard1"),
@@ -349,6 +359,12 @@ class Lingo2ClientContext(CommonContext):
349 "default": [], 359 "default": [],
350 "want_reply": True, 360 "want_reply": True,
351 "operations": [{"operation": "default", "value": []}] 361 "operations": [{"operation": "default", "value": []}]
362 }, {
363 "cmd": "Set",
364 "key": self.get_datastorage_key("ignored_locations"),
365 "default": [],
366 "want_reply": True,
367 "operations": [{"operation": "default", "value": []}]
352 }] 368 }]
353 369
354 if self.slot_data.get("shuffle_worldports", False): 370 if self.slot_data.get("shuffle_worldports", False):
@@ -464,6 +480,8 @@ class Lingo2ClientContext(CommonContext):
464 updates = self.manager.update_latches(door_ids) 480 updates = self.manager.update_latches(door_ids)
465 if len(updates) > 0: 481 if len(updates) > 0:
466 self.manager.game_ctx.send_update_latches(updates) 482 self.manager.game_ctx.send_update_latches(updates)
483 elif args["key"] == self.get_datastorage_key("ignored_locations"):
484 self.manager.game_ctx.send_ignored_locations(args["value"])
467 485
468 def get_datastorage_key(self, name: str): 486 def get_datastorage_key(self, name: str):
469 return f"Lingo2_{self.slot}_{name}" 487 return f"Lingo2_{self.slot}_{name}"
@@ -559,6 +577,28 @@ class Lingo2ClientContext(CommonContext):
559 }] 577 }]
560 }]) 578 }])
561 579
580 async def add_ignored_location(self, loc_id: int):
581 await self.send_msgs([{
582 "cmd": "Set",
583 "key": self.get_datastorage_key("ignored_locations"),
584 "want_reply": True,
585 "operations": [{
586 "operation": "update",
587 "value": [loc_id]
588 }]
589 }])
590
591 async def remove_ignored_location(self, loc_id: int):
592 await self.send_msgs([{
593 "cmd": "Set",
594 "key": self.get_datastorage_key("ignored_locations"),
595 "want_reply": True,
596 "operations": [{
597 "operation": "remove",
598 "value": loc_id
599 }]
600 }])
601
562 602
563async def pipe_loop(manager: Lingo2Manager): 603async def pipe_loop(manager: Lingo2Manager):
564 while not manager.client_ctx.exit_event.is_set(): 604 while not manager.client_ctx.exit_event.is_set():
@@ -635,6 +675,10 @@ async def process_game_cmd(manager: Lingo2Manager, args: dict):
635 updates = manager.update_latches({args["door"]}) 675 updates = manager.update_latches({args["door"]})
636 if len(updates) > 0: 676 if len(updates) > 0:
637 async_start(manager.client_ctx.update_latches(updates), name="client update latches") 677 async_start(manager.client_ctx.update_latches(updates), name="client update latches")
678 elif cmd == "IgnoreLocation":
679 async_start(manager.client_ctx.add_ignored_location(args["id"]), name="client ignore loc")
680 elif cmd == "UnignoreLocation":
681 async_start(manager.client_ctx.remove_ignored_location(args["id"]), name="client unignore loc")
638 elif cmd == "Quit": 682 elif cmd == "Quit":
639 manager.client_ctx.exit_event.set() 683 manager.client_ctx.exit_event.set()
640 684