diff --git a/worlds/tunic/__init__.py b/worlds/tunic/__init__.py index ce72c422b61..15d01264f18 100644 --- a/worlds/tunic/__init__.py +++ b/worlds/tunic/__init__.py @@ -23,6 +23,7 @@ from .options import (TunicOptions, EntranceRando, tunic_option_groups, tunic_op LaurelsLocation, LaurelsZips, IceGrappling, LadderStorage, EntranceLayout, check_options, LocalFill, get_hexagons_in_pool, HexagonQuestAbilityUnlockType) from . import ut_stuff +from . import launcher class TunicSettings(Group): @@ -37,9 +38,15 @@ class TunicSettings(Group): description = "TUNIC Poptracker Pack zip file" required = False + class GamePath(FilePath): + """Name of the TUNIC executable file.""" + description = "TUNIC Game Executable" + is_exe = True + disable_local_spoiler: DisableLocalSpoiler | bool = False limit_grass_rando: LimitGrassRando | bool = True ut_poptracker_path: UTPoptrackerPath | str = UTPoptrackerPath() + game_path: GamePath = GamePath(["Tunic.exe", "Secret Legend.exe"]) class TunicWeb(WebWorld): diff --git a/worlds/tunic/launcher.py b/worlds/tunic/launcher.py new file mode 100644 index 00000000000..ef42bf889d0 --- /dev/null +++ b/worlds/tunic/launcher.py @@ -0,0 +1,68 @@ +import argparse +import logging +import os +import subprocess + +from Utils import messagebox +from worlds.LauncherComponents import Component, Type, components + + +logger = logging.getLogger(__name__) + + +def launch_game(*args: str) -> None: + from . import TunicWorld + + try: + game_folder = os.path.dirname(TunicWorld.settings.game_path) + except ValueError as e: + logger.error(e) + messagebox( + "Invalid File", + "Please try again and ensure you select Tunic.exe or Secret Legend.exe.", + ) + return + + working_directory = os.getcwd() + parser = argparse.ArgumentParser(description="TUNIC Launcher") + parser.add_argument("url", type=str, nargs="?", help="Archipelago Webhost URI to auto connect to.") + parsed_args = parser.parse_args(args) + os.chdir(game_folder) + if parsed_args.url: + subprocess.Popen([TunicWorld.settings.game_path, str(parsed_args.url)]) + else: + subprocess.Popen(TunicWorld.settings.game_path) + os.chdir(working_directory) + + +def attempt_launch_ut(*args: str) -> None: + try: + from worlds.tracker import launch_client + + launch_client(*args) + except ImportError as e: + logger.error(e) + messagebox( + "Cannot Load UT", + "There was an error loading Universal Tracker. Please ensure it is installed and up to date.", + ) + + +components.extend( + ( + Component( + "TUNIC", + func=launch_game, + game_name="TUNIC", + component_type=Type.HIDDEN, + supports_uri=True, + ), + Component( + "Universal Tracker for TUNIC", + func=attempt_launch_ut, + game_name="TUNIC", + component_type=Type.HIDDEN, + supports_uri=True, + ), + ) +)