diff --git a/source/gui/install.py b/source/gui/install.py index 4752cc5..b360ae4 100644 --- a/source/gui/install.py +++ b/source/gui/install.py @@ -150,16 +150,20 @@ class Menu(tkinter.Menu): class Language(tkinter.Menu): def __init__(self, master: tkinter.Menu): super().__init__(master, tearoff=False) - master.add_cascade(label=_("LANGUAGE_SELECTION"), menu=self) + self.variable = tkinter.StringVar(value=self.master.master.options["language"]) + def callback(file: Path): def func(): self.master.master.options["language"] = file.stem return func for file in Path("./assets/language/").iterdir(): - self.add_command( - label=json.loads(file.read_text(encoding="utf8"))["name"], + lang_json = json.loads(file.read_text(encoding="utf8")) + self.add_radiobutton( + label=lang_json["name"], + value=file.stem, + variable=self.variable, command=callback(file) ) @@ -179,6 +183,27 @@ class Menu(tkinter.Menu): master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self) self.add_command(label="Debug mode") + self.threads_used = self.ThreadsUsed(self) + + class ThreadsUsed(tkinter.Menu): + def __init__(self, master: tkinter.Menu): + super().__init__(master, tearoff=False) + master.add_cascade(label=_("THREADS_USED"), menu=self) + + self.variable = tkinter.IntVar(value=self.master.master.master.options["threads"]) + + def callback(threads_amount: int): + def func(): self.master.master.master.options["threads"] = threads_amount + return func + + for i in [1, 2, 4, 8, 12, 16]: + self.add_radiobutton( + label=_("USE", f" {i} ", "THREADS"), + value=i, + variable=self.variable, + command=callback(i), + ) + # Help menu class Help(tkinter.Menu): def __init__(self, master: tkinter.Menu): @@ -377,7 +402,14 @@ class ButtonInstall(ttk.Button): game = Game(source_path) mod_config = self.master.get_mod_config() output_type = self.master.get_output_type() - self.master.progress_function(game.install_mod(destination_path, mod_config, output_type)) + self.master.progress_function( + game.install_mod( + dest=destination_path, + mod_config=mod_config, + output_type=output_type, + options=self.master.options + ) + ) finally: self.master.set_state(InstallerState.IDLE) diff --git a/source/mkw/Game.py b/source/mkw/Game.py index a2f6b63..740c672 100644 --- a/source/mkw/Game.py +++ b/source/mkw/Game.py @@ -3,6 +3,7 @@ from typing import Generator from source.mkw.ExtractedGame import ExtractedGame from source.mkw.ModConfig import ModConfig +from source.option import Option from source.wt.wit import WITPath, Region, Extension @@ -87,11 +88,13 @@ class Game: return extracted_game - def install_mod(self, dest: Path, mod_config: ModConfig, output_type: Extension) -> Generator[dict, None, None]: + def install_mod(self, dest: Path, mod_config: ModConfig, options: "Option", output_type: Extension + ) -> Generator[dict, None, None]: """ Patch the game with the mod :dest: destination directory :mod_config: mod configuration + :options: others options for customized installation :output_type: type of the destination game """ # create a cache directory for some files @@ -122,7 +125,7 @@ class Game: cache_autoadd_directory, cache_cttracks_directory, cache_ogtracks_directory, - 8 + options["threads"], ) # patch the game diff --git a/source/option.py b/source/option.py index 6f69cef..aaaa91b 100644 --- a/source/option.py +++ b/source/option.py @@ -7,15 +7,21 @@ from source import restart_program class Option: __slots__ = ("_path", "_options") - reboot_on_change: list[any] = ["language"] + reboot_on_change: list[str] = [ + "language", + ] + default_options: dict[str, any] = { - "language": "en" + "language": "en", + "threads": 8, } - def __init__(self, language=None): + def __init__(self, **options): self._path: Path | None = None self._options: dict[str, any] = self.default_options.copy() - if language is not None: self._options["language"] = language + + for option_name, option_value in options.items(): + self._options[option_name] = option_value def __getitem__(self, key: str) -> any: """ @@ -55,11 +61,7 @@ class Option: :param option_dict: dict containing the configuration :return: Option """ - kwargs = {} - for key in cls.default_options.keys(): - if "key" in option_dict: kwargs[key] = option_dict[key] - - return cls(**kwargs) + return cls(**option_dict) @classmethod def from_file(cls, option_file: str | Path) -> "Option": diff --git a/source/translation.py b/source/translation.py index a503fc7..9857532 100644 --- a/source/translation.py +++ b/source/translation.py @@ -22,7 +22,11 @@ def translate(*text) -> str: :param text: list of text to translate :return: translated text """ - return "".join([self._language_data["translation"].get(word, word) for word in text]) + return "".join([ + self._language_data["translation"].get(word, word) if isinstance(word, str) + else str(word) + for word in text + ])