From a5579386ec940679a4162c456e1b510006d78ed9 Mon Sep 17 00:00:00 2001 From: qwint Date: Sat, 14 Dec 2024 19:09:32 -0600 Subject: [PATCH] make a crude component lookup on init and change launcher identify to check that lookup first --- Launcher.py | 5 +++++ worlds/LauncherComponents.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Launcher.py b/Launcher.py index 22c0944ab1a4..054e86d06be1 100644 --- a/Launcher.py +++ b/Launcher.py @@ -170,6 +170,11 @@ def _stop(self, *largs): def identify(path: Union[None, str]) -> Tuple[Union[None, str], Union[None, Component]]: if path is None: return None, None + else: + suffix = "." + path.split(".")[-1] + from worlds.LauncherComponents import component_by_suffix + if suffix in component_by_suffix: + return path, component_by_suffix[suffix] for component in components: if component.handles_file(path): return path, component diff --git a/worlds/LauncherComponents.py b/worlds/LauncherComponents.py index 7f178f1739fc..6e238225ead3 100644 --- a/worlds/LauncherComponents.py +++ b/worlds/LauncherComponents.py @@ -8,6 +8,9 @@ from Utils import local_path, open_filename +component_by_suffix = {} + + class Type(Enum): TOOL = auto() MISC = auto() @@ -48,6 +51,12 @@ def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_ Type.ADJUSTER if "Adjuster" in display_name else Type.MISC) self.func = func self.file_identifier = file_identifier + if isinstance(file_identifier, SuffixIdentifier): + for suffix in file_identifier.suffixes: + if suffix in component_by_suffix: + raise Exception("TODO") + else: + component_by_suffix[suffix] = self self.game_name = game_name self.supports_uri = supports_uri