From 25e85cd245ebc051c20b01904ba3a69ca0d43783 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Sun, 3 Nov 2024 19:01:56 +1100 Subject: [PATCH 1/2] Add URL support to the client and launcher component --- src/ManualClient.py | 25 +++++++++++++++++++------ src/__init__.py | 25 +++++++++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/ManualClient.py b/src/ManualClient.py index 0cecb0ba..eae08579 100644 --- a/src/ManualClient.py +++ b/src/ManualClient.py @@ -1,12 +1,14 @@ from __future__ import annotations -import time +import asyncio +import json +import os +import re import sys -from typing import Any import typing -from worlds import AutoWorldRegister, network_data_package -import json +from typing import Any -import asyncio, re +import urllib +from worlds import AutoWorldRegister, network_data_package import ModuleUpdate ModuleUpdate.update() @@ -718,7 +720,18 @@ def read_apmanual_file(apmanual_file): async def main(args): config_file = {} - if args.apmanual_file: + if args.apmanual_file and args.apmanual_file.startswith("archipelago://"): + url = urllib.parse.urlparse(args.apmanual_file) + args.connect = url.netloc + if url.username: + args.name = urllib.parse.unquote(url.username) + if url.password: + args.password = urllib.parse.unquote(url.password) + queries = urllib.parse.parse_qs(url.query) + if "game" in queries: + config_file['game'] = queries["game"][0] + + elif args.apmanual_file and os.path.exists(args.apmanual_file): config_file = read_apmanual_file(args.apmanual_file) ctx = ManualContext(args.connect, args.password, config_file.get("game"), config_file.get("player_name")) ctx.server_task = asyncio.create_task(server_loop(ctx), name="server loop") diff --git a/src/__init__.py b/src/__init__.py index 48574a85..c848cf65 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -9,7 +9,7 @@ from worlds.generic.Rules import forbid_items_for_player from worlds.LauncherComponents import Component, SuffixIdentifier, components, Type, launch_subprocess, icon_paths -from .Data import item_table, location_table, region_table, category_table, meta_table +from .Data import item_table, location_table, region_table, category_table from .Game import game_name, filler_item_name, starting_items from .Meta import world_description, world_webworld, enable_region_diagram from .Locations import location_id_to_name, location_name_to_id, location_name_to_location, location_name_groups, victory_names @@ -22,9 +22,9 @@ from .Options import manual_options_data from .Helpers import is_item_enabled, get_option_value, get_items_for_player, resolve_yaml_option -from BaseClasses import ItemClassification, Tutorial, Item +from BaseClasses import ItemClassification, Item from Options import PerGameCommonOptions -from worlds.AutoWorld import World, WebWorld +from worlds.AutoWorld import World, AutoWorldRegister from .hooks.World import \ hook_get_filler_item_name, before_create_regions, after_create_regions, \ @@ -444,9 +444,21 @@ class VersionedComponent(Component): def __init__(self, display_name: str, script_name: Optional[str] = None, func: Optional[Callable] = None, version: int = 0, file_identifier: Optional[Callable[[str], bool]] = None, icon: Optional[str] = None): super().__init__(display_name=display_name, script_name=script_name, func=func, component_type=Type.CLIENT, file_identifier=file_identifier, icon=icon) self.version = version + self.supports_uri = True + + @property + def game_name(self) -> list[str]: + return [name for name in AutoWorldRegister.world_types.keys() if name.startswith("Manual_")] + + @game_name.setter + def game_name(self, value: str): + # This needs to exist because the base class sets it to [] in the __init__ method + if value: + raise ValueError("Manual Client does not support setting game_name manually.") + def add_client_to_launcher() -> None: - version = 2024_11_03 # YYYYMMDD + version = 2024_11_04 # YYYYMMDD found = False if "manual" not in icon_paths: @@ -459,6 +471,11 @@ def add_client_to_launcher() -> None: for c in components: if c.display_name == "Manual Client": found = True + if not getattr(c, "supports_uri", False): + components.remove(c) + found = False + break + if getattr(c, "version", 0) < version: # We have a newer version of the Manual Client than the one the last apworld added c.version = version c.func = launch_client From 7492b1a3fce0a308a628932303e09d845993e303 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Wed, 18 Dec 2024 15:44:46 +1100 Subject: [PATCH 2/2] Bump client version --- src/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__init__.py b/src/__init__.py index 651d922d..37b5092b 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -472,7 +472,7 @@ def game_name(self, value: str): def add_client_to_launcher() -> None: - version = 2024_12_13 # YYYYMMDD + version = 2024_12_18 # YYYYMMDD found = False if "manual" not in icon_paths: