diff --git a/Pack/MKWFaraphel/mod_config.json b/Pack/MKWFaraphel/mod_config.json index 59c9482..7e7b16b 100644 --- a/Pack/MKWFaraphel/mod_config.json +++ b/Pack/MKWFaraphel/mod_config.json @@ -22,7 +22,7 @@ "fr": "Mode" }, "description": { - "en": "Special mod's configuration.", + "en": "Special mod configuration.", "fr": "Configuration spécial du mod." }, "type": "choices", diff --git a/assets/language/en.json b/assets/language/en.json index fdeef96..0599927 100644 --- a/assets/language/en.json +++ b/assets/language/en.json @@ -107,6 +107,11 @@ "ERROR_SOURCE_NOT_IMPLEMENTED": "Source \"%s\" is not implemented (in patch : \"%s\")", "ERROR_OPERATION_NOT_IMPLEMENTED": "Operation \"%s\" is not implemented", "ERROR_BMG_LAYER_MODE_NOT_IMPLEMENTED": "Bmg layer mode \"%s\" not implemented", - "ERROR_IMAGE_LAYER_TYPE_NOT_IMPLEMENTED": "Image layer type \"%s\" not implemented" + "ERROR_IMAGE_LAYER_TYPE_NOT_IMPLEMENTED": "Image layer type \"%s\" not implemented", + + "TEXT_INPUT_MOD_NAME": "Name of the mod to install %s : ", + "TEXT_INPUT_SOURCE_PATH": "Enter the path to the source game : ", + "TEXT_INPUT_DESTINATION_DIRECTORY": "Enter the path to the destination directory : ", + "TEXT_INPUT_OUPUT_TYPE": "Enter output type %s : " } } \ No newline at end of file diff --git a/main.pyw b/main.pyw index 2146446..17a3ee7 100644 --- a/main.pyw +++ b/main.pyw @@ -1,4 +1,5 @@ -from source.gui import install +import argparse + from source.option import Options from source.translation import load_language @@ -9,5 +10,22 @@ self = __import__(__name__) options = Options.from_file("./option.json") translater = load_language(options.language.get()) -self.window = install.Window(options) -self.window.run() + +def main_gui(): + from source.gui import install + self.window = install.Window(options) + self.window.run() + + +def main_cli(): + from source.cli import install + install.cli(options) + + +parser = argparse.ArgumentParser() +parser.add_argument("-i", "--interface", choices=["gui", "cli"], default="gui") +args = parser.parse_args() + +match args.interface: + case "gui": main_gui() + case "cli": main_cli() diff --git a/source/cli/install.py b/source/cli/install.py new file mode 100644 index 0000000..aedb94d --- /dev/null +++ b/source/cli/install.py @@ -0,0 +1,61 @@ +from pathlib import Path + +from source.mkw.Game import Game +from source.mkw.ModConfig import ModConfig +from source.translation import translate as _ +from source.mkw.collection.Extension import Extension + + +def cli(options): + print(_("TITLE_INSTALL")) + + packs = [] + for pack in Path("./Pack/").iterdir(): + packs.append(pack) + + mod_name = input(_("TEXT_INPUT_MOD_NAME") % [pack.name for pack in packs]) + mod_config = ModConfig.from_file(Path(f"./Pack/{mod_name}/mod_config.json")) + + source_path = input(_("TEXT_INPUT_SOURCE_PATH")) + game = Game(source_path) + + destination_directory = input(_("TEXT_INPUT_DESTINATION_DIRECTORY")) + destination_path = Path(destination_directory) + + output_name = input(_("TEXT_INPUT_OUPUT_TYPE") % [extension.name for extension in Extension]) + output_type = Extension[output_name] + + progressbar_max: int = 30 + + title: str = "" + description: str = "" + current_part: int = 0 + max_part: int = 0 + current_step: int = 0 + max_step: int = 0 + + for step in game.install_mod( + dest=destination_path, + mod_config=mod_config, + output_type=output_type, + options=options + ): + if step.title is not None: title = step.title + if step.description is not None: description = step.description + if step.max_part is not None: max_part = step.max_part + if step.set_part is not None: current_part = step.set_part + if step.part is not None: current_part += step.part + if step.max_step is not None: max_step = step.max_step + if step.set_step is not None: current_step = step.set_step + if step.step is not None: current_step += step.step + + progressbar_step: int = current_step * progressbar_max // max_step if max_step > 0 else 0 + + print("\033[H\033[J", end="") + print(title, f"({current_part} / {max_part})") + print(description) + print( + f"{round((current_step / max_step if max_step > 0 else 0) * 100, 2)}% " + f"[{'#' * progressbar_step}{' ' * (progressbar_max - progressbar_step)}]" + ) + diff --git a/source/gui/install.py b/source/gui/install.py index 1e2a2cb..65b5fb8 100644 --- a/source/gui/install.py +++ b/source/gui/install.py @@ -523,9 +523,8 @@ class SelectPack(ttk.Frame): """ self.packs = [] - for pack in Path("./Pack/").iterdir(): - if self.is_valid_pack(pack): - self.packs.append(pack) + for pack in filter(lambda pack: self.is_valid_pack(pack), Path("./Pack/").iterdir()): + self.packs.append(pack) self.combobox["values"] = [pack.name for pack in self.packs]