Skip to content

Commit

Permalink
adds ap url handling to animal well component
Browse files Browse the repository at this point in the history
  • Loading branch information
qwint committed Oct 7, 2024
1 parent eb52c83 commit 74b8e3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
9 changes: 5 additions & 4 deletions worlds/animal_well/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ class TrackerSetting(IntEnum):
in_game_tracker: TrackerSetting = TrackerSetting.full_tracker


def launch_client():
def launch_client(*args):
"""
Launch the Animal Well Client
"""
from .client import launch
from CommonClient import gui_enabled
if gui_enabled:
launch_subprocess(launch, name="AnimalWellClient")
launch_subprocess(launch, name="AnimalWellClient", args=args)
else:
launch()
launch(args)


components.append(Component("ANIMAL WELL Client", func=launch_client,
component_type=Type.CLIENT, icon="Potate"))
component_type=Type.CLIENT, icon="Potate",
supports_uri=True, game_name="ANIMAL WELL"))

icon_paths["Potate"] = f"ap:{__name__}/Potate.png"

Expand Down
24 changes: 17 additions & 7 deletions worlds/animal_well/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,22 +1495,32 @@ async def console_task(ctx: AnimalWellContext):
await asyncio.sleep(1/120)


def launch():
def launch(args):
"""
Launch the client
"""

async def main():
async def main(*args):
"""
main function
"""
import sys
args = sys.argv[1:]
if "ANIMAL WELL Client" in args:
args.remove("ANIMAL WELL Client")
import urllib
parser = get_base_parser()
parser.add_argument("url", type=str, nargs="?", help="Archipelago Webhost uri to auto connect to.")
args = parser.parse_args(args)

# handle if text client is launched using the "archipelago://name:pass@host:port" url from webhost
if args.url:
url = urllib.parse.urlparse(args.url)
if url.scheme == "archipelago":
args.connect = url.netloc
if url.username:
args.name = urllib.parse.unquote(url.username)
if url.password:
args.password = urllib.parse.unquote(url.password)
else:
parser.error(f"bad url, found {args.url}, expected url in form of archipelago://archipelago.gg:38281")

ctx = AnimalWellContext(args.connect, args.password)
ctx.server_task = asyncio.create_task(server_loop(ctx), name="ServerLoop")

Expand Down Expand Up @@ -1548,5 +1558,5 @@ async def main():

import colorama
colorama.init()
asyncio.run(main())
asyncio.run(main(args))
colorama.deinit()

0 comments on commit 74b8e3c

Please sign in to comment.