diff options
Diffstat (limited to 'apworld/__init__.py')
-rw-r--r-- | apworld/__init__.py | 68 |
1 files changed, 45 insertions, 23 deletions
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 | |||
3 | """ | 3 | """ |
4 | import asyncio | 4 | import asyncio |
5 | import os.path | 5 | import os.path |
6 | import pkgutil | ||
6 | import subprocess | 7 | import subprocess |
7 | from typing import ClassVar | 8 | from typing import ClassVar |
8 | 9 | ||
@@ -20,29 +21,6 @@ from .version import APWORLD_VERSION | |||
20 | from ..LauncherComponents import Component, Type, components | 21 | from ..LauncherComponents import Component, Type, components |
21 | 22 | ||
22 | 23 | ||
23 | async def run_game(): | ||
24 | exe_file = settings.get_settings().lingo2_options.exe_file | ||
25 | |||
26 | subprocess.Popen( | ||
27 | [ | ||
28 | exe_file, | ||
29 | "--scene", | ||
30 | Utils.local_path("worlds", "lingo2", "client", "run_from_source.tscn"), | ||
31 | "--", | ||
32 | Utils.local_path("worlds", "lingo2", "client"), | ||
33 | ], | ||
34 | cwd=os.path.dirname(exe_file), | ||
35 | ) | ||
36 | |||
37 | |||
38 | async def client_main(): | ||
39 | Utils.async_start(run_game()) | ||
40 | |||
41 | |||
42 | def launch_client(*args): | ||
43 | asyncio.run(client_main()) | ||
44 | |||
45 | |||
46 | class Lingo2WebWorld(WebWorld): | 24 | class Lingo2WebWorld(WebWorld): |
47 | rich_text_options_doc = True | 25 | rich_text_options_doc = True |
48 | theme = "grass" | 26 | theme = "grass" |
@@ -183,6 +161,50 @@ class Lingo2World(World): | |||
183 | # we are using re_gen_passthrough over modifying the world here due to complexities with ER | 161 | # we are using re_gen_passthrough over modifying the world here due to complexities with ER |
184 | return slot_data | 162 | return slot_data |
185 | 163 | ||
164 | |||
165 | async def run_game(): | ||
166 | exe_file = settings.get_settings().lingo2_options.exe_file | ||
167 | |||
168 | if Lingo2World.zip_path is not None: | ||
169 | # This is a packaged apworld. | ||
170 | init_scene = pkgutil.get_data(__name__, "client/run_from_apworld.tscn") | ||
171 | init_path = Utils.local_path("data", "lingo2_init.tscn") | ||
172 | |||
173 | with open(init_path, "wb") as file_handle: | ||
174 | file_handle.write(init_scene) | ||
175 | |||
176 | subprocess.Popen( | ||
177 | [ | ||
178 | exe_file, | ||
179 | "--scene", | ||
180 | init_path, | ||
181 | "--", | ||
182 | str(Lingo2World.zip_path.absolute()), | ||
183 | ], | ||
184 | cwd=os.path.dirname(exe_file), | ||
185 | ) | ||
186 | else: | ||
187 | # The world is unzipped and being run in source. | ||
188 | subprocess.Popen( | ||
189 | [ | ||
190 | exe_file, | ||
191 | "--scene", | ||
192 | Utils.local_path("worlds", "lingo2", "client", "run_from_source.tscn"), | ||
193 | "--", | ||
194 | Utils.local_path("worlds", "lingo2", "client"), | ||
195 | ], | ||
196 | cwd=os.path.dirname(exe_file), | ||
197 | ) | ||
198 | |||
199 | |||
200 | async def client_main(): | ||
201 | Utils.async_start(run_game()) | ||
202 | |||
203 | |||
204 | def launch_client(*args): | ||
205 | asyncio.run(client_main()) | ||
206 | |||
207 | |||
186 | component = Component("Lingo 2 Client", component_type=Type.CLIENT, func=launch_client, | 208 | component = Component("Lingo 2 Client", component_type=Type.CLIENT, func=launch_client, |
187 | description="Open Lingo 2.") | 209 | description="Open Lingo 2.") |
188 | components.append(component) | 210 | components.append(component) |