diff --git a/soulstruct/base/maps/msb/core.py b/soulstruct/base/maps/msb/core.py index 3423766d..5d99327c 100644 --- a/soulstruct/base/maps/msb/core.py +++ b/soulstruct/base/maps/msb/core.py @@ -13,6 +13,7 @@ from soulstruct.games import GameSpecificType from soulstruct.utilities.binary import BinaryReader from soulstruct.utilities.maths import Vector3, Matrix3, resolve_rotation +from soulstruct.utilities.files import PACKAGE_PATH from .msb_entry import MSBEntry @@ -434,11 +435,12 @@ def write_entities_module( area_id: int = None, block_id: int = None, # TODO: cc_id and dd_id for Elden Ring - append_to_module: str = "" + include_vanilla_entities: bool = False, ): """Generates a '{mXX_YY}_entities.py' file with entity IDs for import into EVS script. - - If `append_to_module` text is given, all map entities will be appended to it. + + If include_vanilla_entities is true, attempts to append this map's vanilla_entities + content to the generated file. """ if module_path is None: if self.path is None: @@ -482,6 +484,21 @@ def sort_key(key_value) -> tuple[str, int]: module_path = Path(module_path) game_types_import = f"from soulstruct.{self.GAME.submodule_name}.game_types import *\n" + + if include_vanilla_entities: + game_folder = self.GAME.submodule_name + # DS1R vanilla_entities are located in PTDE folder + if game_folder == 'darksouls1r': + game_folder = 'darksouls1ptde' + try: + append_to_module = PACKAGE_PATH( + f"{game_folder}/events/vanilla_entities/{self.path.stem}_entities.py" + ).read_text() + except FileNotFoundError: + append_to_module = "" + else: + append_to_module = "" + if append_to_module: if game_types_import not in append_to_module: # Add game type start import to module. (Very rare that it wouldn't already be there.) diff --git a/soulstruct/base/project/core.py b/soulstruct/base/project/core.py index ee71765b..38050a5f 100644 --- a/soulstruct/base/project/core.py +++ b/soulstruct/base/project/core.py @@ -96,6 +96,7 @@ def __init__(self, project_path="", with_window: ProjectWindow = None, game_root self.text_editor_font_size = DEFAULT_TEXT_EDITOR_FONT_SIZE self.custom_script_directory = Path() self.entities_in_events_directory = False + self.include_vanila_entities = False self.prefer_json = False # TODO: Record last edit time for each file/structure. @@ -628,6 +629,7 @@ def load_config(self, with_window: ProjectWindow = None, game_root: Path = None) self._vanilla_game_root = Path(vanilla_game_root) self.text_editor_font_size = config.get("TextEditorFontSize", DEFAULT_TEXT_EDITOR_FONT_SIZE) self.entities_in_events_directory = config.get("EntitiesInEventsDirectory", False) + self.include_vanila_entities = config.get("IncludeVanillaEntities", False) self.prefer_json = config.get("PreferJSON", False) except KeyError: raise SoulstructProjectError( @@ -752,6 +754,7 @@ def _build_config_dict(self): "VanillaGameDirectory": str(self._vanilla_game_root), "TextEditorFontSize": DEFAULT_TEXT_EDITOR_FONT_SIZE, "EntitiesInEventsDirectory": self.entities_in_events_directory, + "IncludeVanillaEntities": self.include_vanila_entities, "PreferJSON": self.prefer_json, } diff --git a/soulstruct/base/project/editors/entities.py b/soulstruct/base/project/editors/entities.py index c689fd8b..05dec1cc 100644 --- a/soulstruct/base/project/editors/entities.py +++ b/soulstruct/base/project/editors/entities.py @@ -692,7 +692,12 @@ def _write_entities_module(self): msb = self.get_selected_msb() try: - msb.write_entities_module(module_path, area_id=game_map.area_id, block_id=game_map.block_id) + msb.write_entities_module( + module_path, + area_id=game_map.area_id, + block_id=game_map.block_id, + include_vanilla_entities=self._project.include_vanila_entities + ) except Exception as ex: self.CustomDialog( "Write Failed", f"An error occurred while writing '{{project}}/events/{module_path.name}':\n{ex}" diff --git a/soulstruct/darksouls1r/project/core.py b/soulstruct/darksouls1r/project/core.py index 7b015f6f..61a32599 100644 --- a/soulstruct/darksouls1r/project/core.py +++ b/soulstruct/darksouls1r/project/core.py @@ -193,18 +193,11 @@ def offer_entities_export(self, with_window: ProjectWindow = None): game_map = self.maps.GET_MAP(map_name) if write_vanilla_entities_result == 0: - try: - vanilla_module = PACKAGE_PATH( - f"darksouls1ptde/events/vanilla_entities/{game_map.emevd_file_stem}_entities.py" - ).read_text() - except FileNotFoundError: - vanilla_module = "" - else: - vanilla_module = "" + self.include_vanila_entities = True msb.write_entities_module( self.project_root / f"entities/{game_map.emevd_file_stem}_entities.py", - append_to_module=vanilla_module, + include_vanilla_entities=self.include_vanila_entities ) return True else: