mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 11:18:26 +02:00
implemented threads amount options, added checkbox to language options and changed some part of the Option class
This commit is contained in:
parent
0e4c318c19
commit
332edcdcc5
4 changed files with 57 additions and 16 deletions
|
@ -150,16 +150,20 @@ class Menu(tkinter.Menu):
|
||||||
class Language(tkinter.Menu):
|
class Language(tkinter.Menu):
|
||||||
def __init__(self, master: tkinter.Menu):
|
def __init__(self, master: tkinter.Menu):
|
||||||
super().__init__(master, tearoff=False)
|
super().__init__(master, tearoff=False)
|
||||||
|
|
||||||
master.add_cascade(label=_("LANGUAGE_SELECTION"), menu=self)
|
master.add_cascade(label=_("LANGUAGE_SELECTION"), menu=self)
|
||||||
|
|
||||||
|
self.variable = tkinter.StringVar(value=self.master.master.options["language"])
|
||||||
|
|
||||||
def callback(file: Path):
|
def callback(file: Path):
|
||||||
def func(): self.master.master.options["language"] = file.stem
|
def func(): self.master.master.options["language"] = file.stem
|
||||||
return func
|
return func
|
||||||
|
|
||||||
for file in Path("./assets/language/").iterdir():
|
for file in Path("./assets/language/").iterdir():
|
||||||
self.add_command(
|
lang_json = json.loads(file.read_text(encoding="utf8"))
|
||||||
label=json.loads(file.read_text(encoding="utf8"))["name"],
|
self.add_radiobutton(
|
||||||
|
label=lang_json["name"],
|
||||||
|
value=file.stem,
|
||||||
|
variable=self.variable,
|
||||||
command=callback(file)
|
command=callback(file)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -179,6 +183,27 @@ class Menu(tkinter.Menu):
|
||||||
master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self)
|
master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self)
|
||||||
self.add_command(label="Debug mode")
|
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
|
# Help menu
|
||||||
class Help(tkinter.Menu):
|
class Help(tkinter.Menu):
|
||||||
def __init__(self, master: tkinter.Menu):
|
def __init__(self, master: tkinter.Menu):
|
||||||
|
@ -377,7 +402,14 @@ class ButtonInstall(ttk.Button):
|
||||||
game = Game(source_path)
|
game = Game(source_path)
|
||||||
mod_config = self.master.get_mod_config()
|
mod_config = self.master.get_mod_config()
|
||||||
output_type = self.master.get_output_type()
|
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:
|
finally:
|
||||||
self.master.set_state(InstallerState.IDLE)
|
self.master.set_state(InstallerState.IDLE)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import Generator
|
||||||
|
|
||||||
from source.mkw.ExtractedGame import ExtractedGame
|
from source.mkw.ExtractedGame import ExtractedGame
|
||||||
from source.mkw.ModConfig import ModConfig
|
from source.mkw.ModConfig import ModConfig
|
||||||
|
from source.option import Option
|
||||||
from source.wt.wit import WITPath, Region, Extension
|
from source.wt.wit import WITPath, Region, Extension
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,11 +88,13 @@ class Game:
|
||||||
|
|
||||||
return extracted_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
|
Patch the game with the mod
|
||||||
:dest: destination directory
|
:dest: destination directory
|
||||||
:mod_config: mod configuration
|
:mod_config: mod configuration
|
||||||
|
:options: others options for customized installation
|
||||||
:output_type: type of the destination game
|
:output_type: type of the destination game
|
||||||
"""
|
"""
|
||||||
# create a cache directory for some files
|
# create a cache directory for some files
|
||||||
|
@ -122,7 +125,7 @@ class Game:
|
||||||
cache_autoadd_directory,
|
cache_autoadd_directory,
|
||||||
cache_cttracks_directory,
|
cache_cttracks_directory,
|
||||||
cache_ogtracks_directory,
|
cache_ogtracks_directory,
|
||||||
8
|
options["threads"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# patch the game
|
# patch the game
|
||||||
|
|
|
@ -7,15 +7,21 @@ from source import restart_program
|
||||||
class Option:
|
class Option:
|
||||||
__slots__ = ("_path", "_options")
|
__slots__ = ("_path", "_options")
|
||||||
|
|
||||||
reboot_on_change: list[any] = ["language"]
|
reboot_on_change: list[str] = [
|
||||||
|
"language",
|
||||||
|
]
|
||||||
|
|
||||||
default_options: dict[str, any] = {
|
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._path: Path | None = None
|
||||||
self._options: dict[str, any] = self.default_options.copy()
|
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:
|
def __getitem__(self, key: str) -> any:
|
||||||
"""
|
"""
|
||||||
|
@ -55,11 +61,7 @@ class Option:
|
||||||
:param option_dict: dict containing the configuration
|
:param option_dict: dict containing the configuration
|
||||||
:return: Option
|
:return: Option
|
||||||
"""
|
"""
|
||||||
kwargs = {}
|
return cls(**option_dict)
|
||||||
for key in cls.default_options.keys():
|
|
||||||
if "key" in option_dict: kwargs[key] = option_dict[key]
|
|
||||||
|
|
||||||
return cls(**kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, option_file: str | Path) -> "Option":
|
def from_file(cls, option_file: str | Path) -> "Option":
|
||||||
|
|
|
@ -22,7 +22,11 @@ def translate(*text) -> str:
|
||||||
:param text: list of text to translate
|
:param text: list of text to translate
|
||||||
:return: translated text
|
: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
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue