diff options
-rw-r--r-- | apworld/client/client.gd | 17 | ||||
-rw-r--r-- | apworld/client/door.gd | 31 | ||||
-rw-r--r-- | apworld/client/manager.gd | 15 | ||||
-rw-r--r-- | apworld/context.py | 47 |
4 files changed, 108 insertions, 2 deletions
diff --git a/apworld/client/client.gd b/apworld/client/client.gd index 9a4b402..ce5ac7e 100644 --- a/apworld/client/client.gd +++ b/apworld/client/client.gd | |||
@@ -25,6 +25,7 @@ var _slot_data = {} | |||
25 | var _accessible_locations = [] | 25 | var _accessible_locations = [] |
26 | var _accessible_worldports = [] | 26 | var _accessible_worldports = [] |
27 | var _goal_accessible = false | 27 | var _goal_accessible = false |
28 | var _latched_doors = [] | ||
28 | 29 | ||
29 | signal could_not_connect | 30 | signal could_not_connect |
30 | signal connect_status | 31 | signal connect_status |
@@ -34,6 +35,7 @@ signal location_scout_received(location_id, item_name, player_name, flags, for_s | |||
34 | signal text_message_received(message) | 35 | signal text_message_received(message) |
35 | signal item_sent_notification(message) | 36 | signal item_sent_notification(message) |
36 | signal hint_received(message) | 37 | signal hint_received(message) |
38 | signal door_latched(id) | ||
37 | signal accessible_locations_updated | 39 | signal accessible_locations_updated |
38 | signal checked_locations_updated | 40 | signal checked_locations_updated |
39 | signal checked_worldports_updated | 41 | signal checked_worldports_updated |
@@ -189,6 +191,14 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo | |||
189 | message["type"], int(message.get("id", null)), message["path"] | 191 | message["type"], int(message.get("id", null)), message["path"] |
190 | ) | 192 | ) |
191 | 193 | ||
194 | elif cmd == "UpdateLatches": | ||
195 | for id in message["latches"]: | ||
196 | var iid = int(id) | ||
197 | if not _latched_doors.has(iid): | ||
198 | _latched_doors.append(iid) | ||
199 | |||
200 | door_latched.emit(iid) | ||
201 | |||
192 | 202 | ||
193 | func connectToServer(server, un, pw): | 203 | func connectToServer(server, un, pw): |
194 | sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}]) | 204 | sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}]) |
@@ -255,6 +265,13 @@ func checkWorldport(port_id): | |||
255 | sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}]) | 265 | sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}]) |
256 | 266 | ||
257 | 267 | ||
268 | func latchDoor(id): | ||
269 | if not _latched_doors.has(id): | ||
270 | _latched_doors.append(id) | ||
271 | |||
272 | sendMessage([{"cmd": "LatchDoor", "door": id}]) | ||
273 | |||
274 | |||
258 | func getLogicalPath(object_type, object_id): | 275 | func getLogicalPath(object_type, object_id): |
259 | var msg = {"cmd": "GetPath", "type": object_type} | 276 | var msg = {"cmd": "GetPath", "type": object_type} |
260 | if object_id != null: | 277 | if object_id != null: |
diff --git a/apworld/client/door.gd b/apworld/client/door.gd index 49f5728..63cfa99 100644 --- a/apworld/client/door.gd +++ b/apworld/client/door.gd | |||
@@ -1,7 +1,9 @@ | |||
1 | extends "res://scripts/nodes/door.gd" | 1 | extends "res://scripts/nodes/door.gd" |
2 | 2 | ||
3 | var door_id | ||
3 | var item_id | 4 | var item_id |
4 | var item_amount | 5 | var item_amount |
6 | var latched = false | ||
5 | 7 | ||
6 | 8 | ||
7 | func _ready(): | 9 | func _ready(): |
@@ -10,7 +12,7 @@ func _ready(): | |||
10 | ) | 12 | ) |
11 | 13 | ||
12 | var gamedata = global.get_node("Gamedata") | 14 | var gamedata = global.get_node("Gamedata") |
13 | var door_id = gamedata.get_door_for_map_node_path(global.map, node_path) | 15 | door_id = gamedata.get_door_for_map_node_path(global.map, node_path) |
14 | if door_id != null: | 16 | if door_id != null: |
15 | var ap = global.get_node("Archipelago") | 17 | var ap = global.get_node("Archipelago") |
16 | var item_lock = ap.get_item_id_for_door(door_id) | 18 | var item_lock = ap.get_item_id_for_door(door_id) |
@@ -27,6 +29,12 @@ func _ready(): | |||
27 | self.excludeSenders = [] | 29 | self.excludeSenders = [] |
28 | 30 | ||
29 | call_deferred("_readier") | 31 | call_deferred("_readier") |
32 | else: | ||
33 | var door_data = gamedata.objects.get_doors()[door_id] | ||
34 | if door_data.has_latch() and door_data.get_latch(): | ||
35 | _check_latched.call_deferred(door_id) | ||
36 | |||
37 | latched = true | ||
30 | 38 | ||
31 | if global.map == "the_sun_temple": | 39 | if global.map == "the_sun_temple": |
32 | if name == "spe_EndPlatform" or name == "spe_entry_2": | 40 | if name == "spe_EndPlatform" or name == "spe_entry_2": |
@@ -44,3 +52,24 @@ func _readier(): | |||
44 | 52 | ||
45 | if ap.client.getItemAmount(item_id) >= item_amount: | 53 | if ap.client.getItemAmount(item_id) >= item_amount: |
46 | handleTriggered() | 54 | handleTriggered() |
55 | |||
56 | |||
57 | func _check_latched(door_id): | ||
58 | var ap = global.get_node("Archipelago") | ||
59 | |||
60 | if ap.client._latched_doors.has(door_id): | ||
61 | triggered = total | ||
62 | handleTriggered() | ||
63 | |||
64 | |||
65 | func handleTriggered(): | ||
66 | super.handleTriggered() | ||
67 | |||
68 | if latched and ran: | ||
69 | var ap = global.get_node("Archipelago") | ||
70 | ap.client.latchDoor(door_id) | ||
71 | |||
72 | |||
73 | func handleUntriggered(): | ||
74 | if not latched or not ran: | ||
75 | super.handleUntriggered() | ||
diff --git a/apworld/client/manager.gd b/apworld/client/manager.gd index dac09b2..a17bee8 100644 --- a/apworld/client/manager.gd +++ b/apworld/client/manager.gd | |||
@@ -141,6 +141,7 @@ func _ready(): | |||
141 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) | 141 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) |
142 | client.checked_locations_updated.connect(_on_checked_locations_updated) | 142 | client.checked_locations_updated.connect(_on_checked_locations_updated) |
143 | client.checked_worldports_updated.connect(_on_checked_worldports_updated) | 143 | client.checked_worldports_updated.connect(_on_checked_worldports_updated) |
144 | client.door_latched.connect(_on_door_latched) | ||
144 | 145 | ||
145 | client.could_not_connect.connect(_client_could_not_connect) | 146 | client.could_not_connect.connect(_client_could_not_connect) |
146 | client.connect_status.connect(_client_connect_status) | 147 | client.connect_status.connect(_client_connect_status) |
@@ -376,6 +377,20 @@ func _on_checked_worldports_updated(): | |||
376 | textclient_node.update_worldports() | 377 | textclient_node.update_worldports() |
377 | 378 | ||
378 | 379 | ||
380 | func _on_door_latched(door_id): | ||
381 | var gamedata = global.get_node("Gamedata") | ||
382 | if gamedata.get_door_map_name(door_id) != global.map: | ||
383 | return | ||
384 | |||
385 | var receivers = gamedata.get_door_receivers(door_id) | ||
386 | var scene = get_tree().get_root().get_node_or_null("scene") | ||
387 | if scene != null: | ||
388 | for receiver in receivers: | ||
389 | var rnode = scene.get_node_or_null(receiver) | ||
390 | if rnode != null: | ||
391 | rnode.handleTriggered() | ||
392 | |||
393 | |||
379 | func _client_could_not_connect(message): | 394 | func _client_could_not_connect(message): |
380 | could_not_connect.emit(message) | 395 | could_not_connect.emit(message) |
381 | 396 | ||
diff --git a/apworld/context.py b/apworld/context.py index d59bf9d..7975686 100644 --- a/apworld/context.py +++ b/apworld/context.py | |||
@@ -38,6 +38,7 @@ class Lingo2Manager: | |||
38 | keyboard: dict[str, int] | 38 | keyboard: dict[str, int] |
39 | worldports: set[int] | 39 | worldports: set[int] |
40 | goaled: bool | 40 | goaled: bool |
41 | latches: set[int] | ||
41 | 42 | ||
42 | def __init__(self, game_ctx: "Lingo2GameContext", client_ctx: "Lingo2ClientContext"): | 43 | def __init__(self, game_ctx: "Lingo2GameContext", client_ctx: "Lingo2ClientContext"): |
43 | self.game_ctx = game_ctx | 44 | self.game_ctx = game_ctx |
@@ -47,6 +48,7 @@ class Lingo2Manager: | |||
47 | self.tracker = Tracker(self) | 48 | self.tracker = Tracker(self) |
48 | self.keyboard = {} | 49 | self.keyboard = {} |
49 | self.worldports = set() | 50 | self.worldports = set() |
51 | self.latches = set() | ||
50 | 52 | ||
51 | self.reset() | 53 | self.reset() |
52 | 54 | ||
@@ -56,6 +58,7 @@ class Lingo2Manager: | |||
56 | 58 | ||
57 | self.worldports = set() | 59 | self.worldports = set() |
58 | self.goaled = False | 60 | self.goaled = False |
61 | self.latches = set() | ||
59 | 62 | ||
60 | def update_keyboard(self, new_keyboard: dict[str, int]) -> dict[str, int]: | 63 | def update_keyboard(self, new_keyboard: dict[str, int]) -> dict[str, int]: |
61 | ret: dict[str, int] = {} | 64 | ret: dict[str, int] = {} |
@@ -81,6 +84,12 @@ class Lingo2Manager: | |||
81 | 84 | ||
82 | return ret | 85 | return ret |
83 | 86 | ||
87 | def update_latches(self, new_latches: set[int]) -> set[int]: | ||
88 | ret = new_latches.difference(self.latches) | ||
89 | self.latches.update(new_latches) | ||
90 | |||
91 | return ret | ||
92 | |||
84 | 93 | ||
85 | class Lingo2GameContext: | 94 | class Lingo2GameContext: |
86 | server: Endpoint | None | 95 | server: Endpoint | None |
@@ -244,6 +253,17 @@ class Lingo2GameContext: | |||
244 | 253 | ||
245 | async_start(self.send_msgs([msg]), name="path reply") | 254 | async_start(self.send_msgs([msg]), name="path reply") |
246 | 255 | ||
256 | def send_update_latches(self, latches): | ||
257 | if self.server is None: | ||
258 | return | ||
259 | |||
260 | msg = { | ||
261 | "cmd": "UpdateLatches", | ||
262 | "latches": latches, | ||
263 | } | ||
264 | |||
265 | async_start(self.send_msgs([msg]), name="update latches") | ||
266 | |||
247 | async def send_msgs(self, msgs: list[Any]) -> None: | 267 | async def send_msgs(self, msgs: list[Any]) -> None: |
248 | """ `msgs` JSON serializable """ | 268 | """ `msgs` JSON serializable """ |
249 | if not self.server or not self.server.socket.open or self.server.socket.closed: | 269 | if not self.server or not self.server.socket.open or self.server.socket.closed: |
@@ -298,7 +318,7 @@ class Lingo2ClientContext(CommonContext): | |||
298 | self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}" | 318 | self.victory_data_storage_key = f"_read_client_status_{self.team}_{self.slot}" |
299 | 319 | ||
300 | self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"), | 320 | self.set_notify(self.get_datastorage_key("keyboard1"), self.get_datastorage_key("keyboard2"), |
301 | self.victory_data_storage_key) | 321 | self.victory_data_storage_key, self.get_datastorage_key("latches")) |
302 | msg_batch = [{ | 322 | msg_batch = [{ |
303 | "cmd": "Set", | 323 | "cmd": "Set", |
304 | "key": self.get_datastorage_key("keyboard1"), | 324 | "key": self.get_datastorage_key("keyboard1"), |
@@ -311,6 +331,12 @@ class Lingo2ClientContext(CommonContext): | |||
311 | "default": 0, | 331 | "default": 0, |
312 | "want_reply": True, | 332 | "want_reply": True, |
313 | "operations": [{"operation": "default", "value": 0}] | 333 | "operations": [{"operation": "default", "value": 0}] |
334 | }, { | ||
335 | "cmd": "Set", | ||
336 | "key": self.get_datastorage_key("latches"), | ||
337 | "default": [], | ||
338 | "want_reply": True, | ||
339 | "operations": [{"operation": "default", "value": []}] | ||
314 | }] | 340 | }] |
315 | 341 | ||
316 | if self.slot_data.get("shuffle_worldports", False): | 342 | if self.slot_data.get("shuffle_worldports", False): |
@@ -420,6 +446,10 @@ class Lingo2ClientContext(CommonContext): | |||
420 | self.manager.game_ctx.send_update_worldports(updates) | 446 | self.manager.game_ctx.send_update_worldports(updates) |
421 | elif args["key"] == self.victory_data_storage_key: | 447 | elif args["key"] == self.victory_data_storage_key: |
422 | self.handle_status_update(args["value"]) | 448 | self.handle_status_update(args["value"]) |
449 | elif args["key"] == self.get_datastorage_key("latches"): | ||
450 | updates = self.manager.update_latches(set(args["value"])) | ||
451 | if len(updates) > 0: | ||
452 | self.manager.game_ctx.send_update_latches(updates) | ||
423 | 453 | ||
424 | def get_datastorage_key(self, name: str): | 454 | def get_datastorage_key(self, name: str): |
425 | return f"Lingo2_{self.slot}_{name}" | 455 | return f"Lingo2_{self.slot}_{name}" |
@@ -501,6 +531,17 @@ class Lingo2ClientContext(CommonContext): | |||
501 | self.manager.tracker.refresh_state() | 531 | self.manager.tracker.refresh_state() |
502 | self.manager.game_ctx.send_accessible_locations() | 532 | self.manager.game_ctx.send_accessible_locations() |
503 | 533 | ||
534 | async def update_latches(self, updates: set[int]): | ||
535 | await self.send_msgs([{ | ||
536 | "cmd": "Set", | ||
537 | "key": self.get_datastorage_key("latches"), | ||
538 | "want_reply": True, | ||
539 | "operations": [{ | ||
540 | "operation": "update", | ||
541 | "value": updates | ||
542 | }] | ||
543 | }]) | ||
544 | |||
504 | 545 | ||
505 | async def pipe_loop(manager: Lingo2Manager): | 546 | async def pipe_loop(manager: Lingo2Manager): |
506 | while not manager.client_ctx.exit_event.is_set(): | 547 | while not manager.client_ctx.exit_event.is_set(): |
@@ -571,6 +612,10 @@ async def process_game_cmd(manager: Lingo2Manager, args: dict): | |||
571 | path = manager.tracker.get_path_to_goal() | 612 | path = manager.tracker.get_path_to_goal() |
572 | 613 | ||
573 | manager.game_ctx.send_path_reply(args["type"], args.get("id", None), path) | 614 | manager.game_ctx.send_path_reply(args["type"], args.get("id", None), path) |
615 | elif cmd == "LatchDoor": | ||
616 | updates = manager.update_latches({args["door"]}) | ||
617 | if len(updates) > 0: | ||
618 | async_start(manager.client_ctx.update_latches(updates), name="client update latches") | ||
574 | elif cmd == "Quit": | 619 | elif cmd == "Quit": |
575 | manager.client_ctx.exit_event.set() | 620 | manager.client_ctx.exit_event.set() |
576 | 621 | ||