mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 11:18:26 +02:00
72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
import argparse
|
|
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, argparser: argparse.ArgumentParser):
|
|
argparser.add_argument("-m", "--mod", help="name of the mod to install")
|
|
argparser.add_argument("-s", "--source", help="path to the original game")
|
|
argparser.add_argument("-d", "--dest", help="destination directory of the patched game")
|
|
argparser.add_argument("-ot", "--output_type", help="format of the patched game")
|
|
args = argparser.parse_args()
|
|
|
|
packs = []
|
|
for pack in Path("./Pack/").iterdir():
|
|
packs.append(pack)
|
|
|
|
mod_name = args.mod
|
|
choices = [pack.name for pack in packs]
|
|
while mod_name is None or mod_name not in choices: mod_name = input(_("TEXT_INPUT_MOD_NAME") % choices)
|
|
mod_config = ModConfig.from_file(Path(f"./Pack/{mod_name}/mod_config.json"))
|
|
|
|
source_path = args.source
|
|
if source_path is None: source_path = input(_("TEXT_INPUT_SOURCE_PATH"))
|
|
game = Game(source_path)
|
|
|
|
destination_directory = args.dest
|
|
if destination_directory is None: destination_directory = input(_("TEXT_INPUT_DESTINATION_DIRECTORY"))
|
|
destination_path = Path(destination_directory)
|
|
|
|
output_name = args.output_type
|
|
choices = [extension.name for extension in Extension]
|
|
if output_name is None or mod_name not in choices: output_name = input(_("TEXT_INPUT_OUPUT_TYPE") % choices)
|
|
output_type = Extension[output_name]
|
|
|
|
progressbar_max: int = 40
|
|
|
|
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)}]"
|
|
)
|
|
|