diff --git a/pyenliven/__init__.py b/pyenliven/__init__.py index 0e9d332..e5517a5 100644 --- a/pyenliven/__init__.py +++ b/pyenliven/__init__.py @@ -87,6 +87,7 @@ MY_MODULE_DIR = os.path.dirname(os.path.realpath(__file__)) # ^ realpath follows symlinks REPO_DIR = os.path.dirname(MY_MODULE_DIR) MODS_STOPGAP_DIR = os.path.join(REPO_DIR, "patches", "mods-stopgap") +PATCHES_SUBGAME_DIR = os.path.join(REPO_DIR, "patches", "subgame") if not os.path.isdir(MODS_STOPGAP_DIR): echo0("Error: \"{}\" is missing.".format(MODS_STOPGAP_DIR)) exit(1) diff --git a/pyenliven/gamebuilder.py b/pyenliven/gamebuilder.py index 0ab337f..5405647 100644 --- a/pyenliven/gamebuilder.py +++ b/pyenliven/gamebuilder.py @@ -7,7 +7,7 @@ from typing import Dict from git import Repo -from pyenliven import MODS_STOPGAP_DIR, echo0 +from pyenliven import MODS_STOPGAP_DIR, PATCHES_SUBGAME_DIR, echo0 from pyenliven.metadata import ( BASE_ENLIVEN_CONF_SETTINGS, gamespec, @@ -190,6 +190,31 @@ class GameBuilder: update_conf(path, new_settings) # desired_set = {line.strip() for line in desired_lines if line.strip()} + def apply_subgame_patch(self, name, src_parent=None, level=0): + if src_parent is None: + src_parent = os.path.join(PATCHES_SUBGAME_DIR, name) + dst_parent = os.path.join(self.target_game, name) + if os.path.isdir(src_parent): + for sub in os.listdir(src_parent): + src = os.path.join(src_parent, sub) + dst = os.path.join(dst_parent, sub) + if os.path.isdir(src): + if not os.path.isdir(dst): + os.makedirs(dst) + self.apply_subgame_patch( + os.path.join(name, sub), + src_parent=src, + level=level+1) + continue + if os.path.isfile(dst): + os.remove(dst) + shutil.copy(src, dst) + else: + logger.warning(f"There is no {src_parent}," + " so the icon and header will not be patched.") + # if level == 0: + echo0(f"Applied overwrite-based patch:\n-{dst_parent}\n+{src_parent}") + def build(self, conf_path: str = None): self.prepare_target() self.apply_remove_list() @@ -201,6 +226,7 @@ class GameBuilder: conf_path = os.path.join(self.target_game, "minetest.conf.enliven") self.update_conf(conf_path) + self.apply_subgame_patch("menu") echo0("\nBuild finished.") echo0(f"Game location: {self.target_game}")