From cb2eca4fed1eb3692eaa13715f65ebcaf8472b64 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 25 Sep 2025 14:14:22 -0400 Subject: Client can be run from zipped apworld now --- apworld/__init__.py | 68 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'apworld/__init__.py') diff --git a/apworld/__init__.py b/apworld/__init__.py index 9d7d149..523c00c 100644 --- a/apworld/__init__.py +++ b/apworld/__init__.py @@ -3,6 +3,7 @@ Archipelago init file for Lingo 2 """ import asyncio import os.path +import pkgutil import subprocess from typing import ClassVar @@ -20,29 +21,6 @@ from .version import APWORLD_VERSION from ..LauncherComponents import Component, Type, components -async def run_game(): - exe_file = settings.get_settings().lingo2_options.exe_file - - subprocess.Popen( - [ - exe_file, - "--scene", - Utils.local_path("worlds", "lingo2", "client", "run_from_source.tscn"), - "--", - Utils.local_path("worlds", "lingo2", "client"), - ], - cwd=os.path.dirname(exe_file), - ) - - -async def client_main(): - Utils.async_start(run_game()) - - -def launch_client(*args): - asyncio.run(client_main()) - - class Lingo2WebWorld(WebWorld): rich_text_options_doc = True theme = "grass" @@ -183,6 +161,50 @@ class Lingo2World(World): # we are using re_gen_passthrough over modifying the world here due to complexities with ER return slot_data + +async def run_game(): + exe_file = settings.get_settings().lingo2_options.exe_file + + 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") + + with open(init_path, "wb") as file_handle: + file_handle.write(init_scene) + + subprocess.Popen( + [ + exe_file, + "--scene", + init_path, + "--", + str(Lingo2World.zip_path.absolute()), + ], + cwd=os.path.dirname(exe_file), + ) + else: + # The world is unzipped and being run in source. + subprocess.Popen( + [ + exe_file, + "--scene", + Utils.local_path("worlds", "lingo2", "client", "run_from_source.tscn"), + "--", + Utils.local_path("worlds", "lingo2", "client"), + ], + cwd=os.path.dirname(exe_file), + ) + + +async def client_main(): + Utils.async_start(run_game()) + + +def launch_client(*args): + asyncio.run(client_main()) + + component = Component("Lingo 2 Client", component_type=Type.CLIENT, func=launch_client, description="Open Lingo 2.") components.append(component) -- cgit 1.4.1