diff --git a/source/mkw/Patch/Patch.py b/source/mkw/Patch/Patch.py index 6954e05..c6f30ef 100644 --- a/source/mkw/Patch/Patch.py +++ b/source/mkw/Patch/Patch.py @@ -16,23 +16,23 @@ class Patch: def __repr__(self) -> str: return f"<{self.__class__.__name__} {self.path}>" - def safe_eval(self, template: str, extracted_game: "ExtractedGame") -> str: + def safe_eval(self, template: str, **env) -> str: """ Safe eval with a patch environment - :param extracted_game: the extracted game to patch + :param env: other variable that are allowed in the safe_eval :param template: template to evaluate :return: the result of the evaluation """ return safe_eval( template, extra_token_map={ - "extracted_game": "extracted_game", - "mod_config": "mod_config" + "extracted_game": "extracted_game" + } | { + key: key for key in env }, env={ - "extracted_game": extracted_game, "mod_config": self.mod_config - }, + } | env, ) def install(self, extracted_game: "ExtractedGame") -> Generator[dict, None, None]: diff --git a/source/mkw/Patch/PatchDirectory.py b/source/mkw/Patch/PatchDirectory.py index 1c1d0c2..62203da 100644 --- a/source/mkw/Patch/PatchDirectory.py +++ b/source/mkw/Patch/PatchDirectory.py @@ -24,7 +24,7 @@ class PatchDirectory(PatchObject): """ yield {"description": f"Patching {self}"} - if self.patch.safe_eval(self.configuration["if"], extracted_game) == "False": return + if self.patch.safe_eval(self.configuration["if"], extracted_game=extracted_game) == "False": return match self.configuration["mode"]: # if the mode is copy, then simply patch the subfile into the game with the same path diff --git a/source/mkw/Patch/PatchFile.py b/source/mkw/Patch/PatchFile.py index 33a45bd..892fe5c 100644 --- a/source/mkw/Patch/PatchFile.py +++ b/source/mkw/Patch/PatchFile.py @@ -31,7 +31,7 @@ class PatchFile(PatchObject): yield {"description": f"Patching {self}"} # check if the file should be patched considering the "if" configuration - if self.patch.safe_eval(self.configuration["if"], extracted_game) == "False": return + if self.patch.safe_eval(self.configuration["if"], extracted_game=extracted_game) == "False": return # check if the path to the game_subpath is inside a szs, and if yes extract it for szs_subpath in filter(lambda path: path.suffix == ".d",