From b524e153ad71e368afbe50da78c4b73c3ac65c5f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 27 Sep 2025 11:10:07 -0400 Subject: Added accessible locations tab to game --- apworld/context.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'apworld/context.py') diff --git a/apworld/context.py b/apworld/context.py index 05f75a3..2a2149f 100644 --- a/apworld/context.py +++ b/apworld/context.py @@ -8,9 +8,12 @@ import websockets import Utils import settings +from BaseClasses import ItemClassification from CommonClient import CommonContext, server_loop, gui_enabled, logger, get_base_parser, handle_url_arg from NetUtils import Endpoint, decode, encode from Utils import async_start +from . import Lingo2World +from .tracker import Tracker PORT = 43182 MESSAGE_MAX_SIZE = 16*1024*1024 @@ -19,9 +22,11 @@ MESSAGE_MAX_SIZE = 16*1024*1024 class Lingo2GameContext: server: Endpoint | None client: "Lingo2ClientContext" + tracker: Tracker def __init__(self): self.server = None + self.tracker = Tracker() def send_connected(self): msg = { @@ -84,6 +89,22 @@ class Lingo2GameContext: async_start(self.send_msgs([msg]), name="notif") + def send_accessible_locations(self): + msg = { + "cmd": "AccessibleLocations", + "locations": list(self.tracker.accessible_locations), + } + + async_start(self.send_msgs([msg]), name="accessible locations") + + def send_update_locations(self, locations): + msg = { + "cmd": "UpdateLocations", + "locations": locations, + } + + async_start(self.send_msgs([msg]), name="update locations") + 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: @@ -119,7 +140,14 @@ class Lingo2ClientContext(CommonContext): if self.game_ctx.server is not None: self.game_ctx.send_connected() + + self.game_ctx.tracker.setup_slot(self.slot_data) + elif cmd == "RoomUpdate": + if self.game_ctx.server is not None: + self.game_ctx.send_update_locations(args["checked_locations"]) elif cmd == "ReceivedItems": + self.game_ctx.tracker.set_collected_items(self.items_received) + if self.game_ctx.server is not None: cur_index = 0 items = [] @@ -141,6 +169,9 @@ class Lingo2ClientContext(CommonContext): items.append(item_msg) self.game_ctx.send_item_received(items) + + if any(ItemClassification.progression in ItemClassification(item.flags) for item in args["items"]): + self.game_ctx.send_accessible_locations() elif cmd == "PrintJSON": if self.game_ctx.server is not None: if "receiving" in args and "item" in args and args["item"].player == self.slot: @@ -195,6 +226,9 @@ class Lingo2ClientContext(CommonContext): self.game_ctx.send_location_info(locations) + if cmd in ["Connected", "RoomUpdate"]: + self.game_ctx.tracker.set_checked_locations(self.checked_locations) + async def pipe_loop(ctx: Lingo2GameContext): while not ctx.client.exit_event.is_set(): @@ -205,6 +239,7 @@ async def pipe_loop(ctx: Lingo2GameContext): logger.info("Connected to Lingo 2!") if ctx.client.auth is not None: ctx.send_connected() + ctx.send_accessible_locations() async for data in ctx.server.socket: for msg in decode(data): await process_game_cmd(ctx, msg) @@ -237,10 +272,7 @@ async def process_game_cmd(ctx: Lingo2GameContext, args: dict): async def run_game(): exe_file = settings.get_settings().lingo2_options.exe_file - from worlds import AutoWorldRegister - world = AutoWorldRegister.world_types["Lingo 2"] - - if world.zip_path is not None: + if Lingo2World.zip_path is not None: # This is a packaged apworld. init_scene = pkgutil.get_data(__name__, "client/run_from_apworld.tscn") init_path = Utils.local_path("data", "lingo2_init.tscn") @@ -254,7 +286,7 @@ async def run_game(): "--scene", init_path, "--", - str(world.zip_path.absolute()), + str(Lingo2World.zip_path.absolute()), ], cwd=os.path.dirname(exe_file), ) -- cgit 1.4.1