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.py23
1 files changed, 21 insertions, 2 deletions
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
10import settings 10import settings
11from BaseClasses import ItemClassification 11from BaseClasses import ItemClassification
12from CommonClient import CommonContext, server_loop, gui_enabled, logger, get_base_parser, handle_url_arg 12from CommonClient import CommonContext, server_loop, gui_enabled, logger, get_base_parser, handle_url_arg
13from NetUtils import Endpoint, decode, encode 13from NetUtils import Endpoint, decode, encode, ClientStatus
14from Utils import async_start 14from Utils import async_start
15from . import Lingo2World 15from . import Lingo2World
16from .tracker import Tracker 16from .tracker import Tracker
@@ -36,6 +36,7 @@ class Lingo2Manager:
36 36
37 keyboard: dict[str, int] 37 keyboard: dict[str, int]
38 worldports: set[int] 38 worldports: set[int]
39 goaled: bool
39 40
40 def __init__(self, game_ctx: "Lingo2GameContext", client_ctx: "Lingo2ClientContext"): 41 def __init__(self, game_ctx: "Lingo2GameContext", client_ctx: "Lingo2ClientContext"):
41 self.game_ctx = game_ctx 42 self.game_ctx = game_ctx
@@ -53,6 +54,7 @@ class Lingo2Manager:
53 self.keyboard[k] = 0 54 self.keyboard[k] = 0
54 55
55 self.worldports = set() 56 self.worldports = set()
57 self.goaled = False
56 58
57 def update_keyboard(self, new_keyboard: dict[str, int]) -> dict[str, int]: 59 def update_keyboard(self, new_keyboard: dict[str, int]) -> dict[str, int]:
58 ret: dict[str, int] = {} 60 ret: dict[str, int] = {}
@@ -177,6 +179,9 @@ class Lingo2GameContext:
177 if len(self.manager.tracker.accessible_worldports) > 0: 179 if len(self.manager.tracker.accessible_worldports) > 0:
178 msg["worldports"] = list(self.manager.tracker.accessible_worldports) 180 msg["worldports"] = list(self.manager.tracker.accessible_worldports)
179 181
182 if self.manager.tracker.goal_accessible and not self.manager.goaled:
183 msg["goal"] = True
184
180 async_start(self.send_msgs([msg]), name="accessible locations") 185 async_start(self.send_msgs([msg]), name="accessible locations")
181 186
182 def send_update_locations(self, locations): 187 def send_update_locations(self, locations):
@@ -226,6 +231,7 @@ class Lingo2ClientContext(CommonContext):
226 items_handling = 0b111 231 items_handling = 0b111
227 232
228 slot_data: dict[str, Any] | None 233 slot_data: dict[str, Any] | None
234 victory_data_storage_key: str
229 235
230 def __init__(self, server_address: str | None = None, password: str | None = None): 236 def __init__(self, server_address: str | None = None, password: str | None = None):
231 super().__init__(server_address, password) 237 super().__init__(server_address, password)
@@ -253,7 +259,10 @@ class Lingo2ClientContext(CommonContext):
253 self.manager.tracker.set_checked_locations(self.checked_locations) 259 self.manager.tracker.set_checked_locations(self.checked_locations)
254 self.manager.game_ctx.send_accessible_locations() 260 self.manager.game_ctx.send_accessible_locations()
255 261
256 self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2")) 262 self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}"
263
264 self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"),
265 self.victory_data_storage_key)
257 msg_batch = [{ 266 msg_batch = [{
258 "cmd": "Set", 267 "cmd": "Set",
259 "key": self.get_datastorage_key("keyboard1"), 268 "key": self.get_datastorage_key("keyboard1"),
@@ -360,6 +369,9 @@ class Lingo2ClientContext(CommonContext):
360 }) 369 })
361 370
362 self.manager.game_ctx.send_location_info(locations) 371 self.manager.game_ctx.send_location_info(locations)
372 elif cmd == "Received":
373 if args["key"] == self.victory_data_storage_key:
374 self.handle_status_update(args["value"])
363 elif cmd == "SetReply": 375 elif cmd == "SetReply":
364 if args["key"] == self.get_datastorage_key("keyboard1"): 376 if args["key"] == self.get_datastorage_key("keyboard1"):
365 self.handle_keyboard_update(1, args) 377 self.handle_keyboard_update(1, args)
@@ -369,6 +381,8 @@ class Lingo2ClientContext(CommonContext):
369 updates = self.manager.update_worldports(set(args["value"])) 381 updates = self.manager.update_worldports(set(args["value"]))
370 if len(updates) > 0: 382 if len(updates) > 0:
371 self.manager.game_ctx.send_update_worldports(updates) 383 self.manager.game_ctx.send_update_worldports(updates)
384 elif args["key"] == self.victory_data_storage_key:
385 self.handle_status_update(args["value"])
372 386
373 def get_datastorage_key(self, name: str): 387 def get_datastorage_key(self, name: str):
374 return f"Lingo2_{self.slot}_{name}" 388 return f"Lingo2_{self.slot}_{name}"
@@ -445,6 +459,11 @@ class Lingo2ClientContext(CommonContext):
445 }] 459 }]
446 }]) 460 }])
447 461
462 def handle_status_update(self, value: int):
463 self.manager.goaled = (value == ClientStatus.CLIENT_GOAL)
464 self.manager.tracker.refresh_state()
465 self.manager.game_ctx.send_accessible_locations()
466
448 467
449async def pipe_loop(manager: Lingo2Manager): 468async def pipe_loop(manager: Lingo2Manager):
450 while not manager.client_ctx.exit_event.is_set(): 469 while not manager.client_ctx.exit_event.is_set():