From 8eda2b4f3da26f4fddffb394eee679f4ad65c3e0 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Fri, 12 Aug 2022 19:18:13 +0200 Subject: [PATCH] implemented EDIT so that game's name and id6 can now be modified --- source/mkw/ExtractedGame.py | 9 ++++----- source/mkw/Game.py | 10 +++++++++- source/wt/wit.py | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source/mkw/ExtractedGame.py b/source/mkw/ExtractedGame.py index 7a60faa..fc5071e 100644 --- a/source/mkw/ExtractedGame.py +++ b/source/mkw/ExtractedGame.py @@ -9,9 +9,6 @@ from source.wt import szs, lec, wit from source.wt.wstrt import StrPath -Game: any - - class PathOutsideMod(Exception): def __init__(self, forbidden_path: Path, allowed_range: Path): super().__init__(f"Error : path {forbidden_path} outside of allowed range {allowed_range}") @@ -155,7 +152,7 @@ class ExtractedGame: for patch_directory in part_directory.glob("_PATCH/"): yield from Patch(patch_directory, mod_config, self._special_file).install(self) - def convert_to(self, output_type: wit.Extension) -> Generator[dict, None, None]: + def convert_to(self, output_type: wit.Extension) -> Generator[dict, None, wit.WITPath | None]: """ Convert the extracted game to another format :param output_type: path to the destination of the game @@ -172,10 +169,12 @@ class ExtractedGame: i += 1 destination_file = destination_file.with_name(dest_name + f" ({i})") - wit.copy( + converted_game: wit.WITPath = wit.copy( source_directory=self.path, destination_file=destination_file, ) yield {"description": "Deleting the extracted game...", "determinate": False} shutil.rmtree(self.path) + + return converted_game diff --git a/source/mkw/Game.py b/source/mkw/Game.py index ed0ead2..3a888d7 100644 --- a/source/mkw/Game.py +++ b/source/mkw/Game.py @@ -67,6 +67,13 @@ class Game: except StopIteration as e: return e.value + def edit(self, mod_config: ModConfig) -> Generator[dict, None, None]: + yield {"description": "Changing game metadata...", "determinate": False} + self.wit_path.edit( + name=mod_config.name, + game_id=self.wit_path.id[:4] + mod_config.variant + ) + @staticmethod def get_output_directory(dest: "Path | str", mod_config: ModConfig) -> Path: """ @@ -140,4 +147,5 @@ class Game: ) # convert the extracted game into a file - yield from extracted_game.convert_to(output_type) + converted_game: WITPath = yield from extracted_game.convert_to(output_type) + if converted_game is not None: yield from Game(converted_game.path).edit(mod_config) diff --git a/source/wt/wit.py b/source/wt/wit.py index 73e42c2..ed45a43 100644 --- a/source/wt/wit.py +++ b/source/wt/wit.py @@ -13,7 +13,7 @@ _tools_run_dict = get_tools_run_dict_function(tools_path) _tools_run_popen = get_tools_run_popen_function(tools_path) -def copy(source_directory: Path | str, destination_file: Path | str): +def copy(source_directory: Path | str, destination_file: Path | str) -> "WITPath": """ Copy a game directory to a game file with a specific format. :param source_directory: path to the extracted game @@ -21,7 +21,7 @@ def copy(source_directory: Path | str, destination_file: Path | str): :return: the destination game path """ _tools_run("COPY", source_directory, "--DEST", destination_file) - return Path(destination_file) + return WITPath(destination_file) class Extension(enum.Enum): @@ -76,6 +76,18 @@ class WITPath: # main.dol is located in ./sys/main.dol, so return parent of parent if self.extension == Extension.FST: return self.path.parent.parent + def edit(self, name: str = None, game_id: str = None) -> None: + """ + Edit the game's information. If the game is a directory, this is ignored. + """ + if self.extension == Extension.FST: return + + args = [] + if name is not None: args.extend(["--name", name]) + if game_id is not None: args.extend(["--id", game_id]) + + _tools_run("EDIT", self.path, *args) + def analyze(self) -> dict: """ Return the analyze of the file