implemented EDIT so that game's name and id6 can now be modified

This commit is contained in:
Faraphel 2022-08-12 19:18:13 +02:00
parent 94dddac6d4
commit 8eda2b4f3d
3 changed files with 27 additions and 8 deletions

View file

@ -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

View file

@ -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)

View file

@ -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