From cb069fe24014dd9d115080367142cfffe33e06b4 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 12 Jul 2022 20:02:03 +0200 Subject: [PATCH] safe_eval now has mod_config in the environnement --- source/mkw/ExtractedGame.py | 2 +- source/mkw/Patch/Patch.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/mkw/ExtractedGame.py b/source/mkw/ExtractedGame.py index 16ce2bb..aa2934d 100644 --- a/source/mkw/ExtractedGame.py +++ b/source/mkw/ExtractedGame.py @@ -44,4 +44,4 @@ class ExtractedGame: # for all the subdirectory named "_PATCH", apply the patch for part_directory in mod_config.get_mod_directory().glob("[!_]*"): for patch_directory in part_directory.glob("_PATCH/"): - yield from Patch(patch_directory).install(self) + yield from Patch(patch_directory, mod_config).install(self) diff --git a/source/mkw/Patch/Patch.py b/source/mkw/Patch/Patch.py index f4f9d3f..6954e05 100644 --- a/source/mkw/Patch/Patch.py +++ b/source/mkw/Patch/Patch.py @@ -9,8 +9,9 @@ class Patch: Represent a patch object """ - def __init__(self, path: Path | str): + def __init__(self, path: Path | str, mod_config: "ModConfig"): self.path = Path(path) + self.mod_config = mod_config def __repr__(self) -> str: return f"<{self.__class__.__name__} {self.path}>" @@ -24,8 +25,14 @@ class Patch: """ return safe_eval( template, - extra_token_map={"extracted_game": "extracted_game"}, - env={"extracted_game": extracted_game}, + extra_token_map={ + "extracted_game": "extracted_game", + "mod_config": "mod_config" + }, + env={ + "extracted_game": extracted_game, + "mod_config": self.mod_config + }, ) def install(self, extracted_game: "ExtractedGame") -> Generator[dict, None, None]: