From 3dea4ae8ad2ece61fc7f2ba2e0ad939076792270 Mon Sep 17 00:00:00 2001 From: Lila Date: Mon, 9 Sep 2024 13:34:29 +0100 Subject: [PATCH 1/4] [SM64] Fix/Improve multi-actor UI (not export all selected) --- fast64_internal/sm64/sm64_objects.py | 59 +++++++++++++++++++--------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index 951e8bcc5..d523ed706 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -2104,21 +2104,21 @@ def actor_custom_path(self): return self.custom_export_path @property - def level_directory(self): + def level_directory(self) -> Path: if self.non_decomp_level: - return self.custom_level_name + return Path(self.custom_level_name) level_name = self.custom_level_name if self.level_name == "Custom" else self.level_name - return os.path.join("/levels/", level_name) + return Path("levels") / level_name @property def base_level_path(self): if self.non_decomp_level: - return bpy.path.abspath(self.custom_level_path) - return bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path) + return Path(bpy.path.abspath(self.custom_level_path)) + return Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) @property def full_level_path(self): - return os.path.join(self.base_level_path, self.level_directory) + return self.base_level_path / self.level_directory # remove user prefixes/naming that I will be adding, such as _col, _geo etc. def filter_name(self, name): @@ -2156,8 +2156,21 @@ def draw_export_options(self, layout): col.prop(self, "export_bhv") self.draw_obj_name(layout) + @property + def actor_names(self) -> list: + return list(dict.fromkeys(filter(None, [self.obj_name_col, self.obj_name_gfx])).keys()) + + @property + def export_locations(self) -> str | None: + names = self.actor_names + if len(names) > 1: + return f"({'/'.join(names)})" + elif len(names) == 1: + return names[0] + return None + def draw_level_path(self, layout): - if not directory_ui_warnings(layout, bpy.path.abspath(self.base_level_path)): + if not directory_ui_warnings(layout, self.base_level_path): return if self.non_decomp_level: layout.label(text=f"Level export path: {self.full_level_path}") @@ -2166,12 +2179,24 @@ def draw_level_path(self, layout): return True def draw_actor_path(self, layout): - actor_path = Path(bpy.context.scene.fast64.sm64.decomp_path) / "actors" - if not filepath_ui_warnings(layout, (actor_path / self.actor_group_name).with_suffix(".c")): + if self.export_locations is None: return - export_locations = ",".join({self.obj_name_col, self.obj_name_gfx}) - # can this be more clear? - layout.label(text=f"Actor export path: actors/{export_locations}") + decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + if self.export_header_type == "Actor": + actor_path = decomp_path / "actors" + if not filepath_ui_warnings(layout, (actor_path / self.actor_group_name).with_suffix(".c")): + return + layout.label(text=f"Actor export path: actors/{self.export_locations}/") + elif self.export_header_type == "Level": + if not directory_ui_warnings(layout, self.full_level_path): + return + level_path = self.full_level_path if self.non_decomp_level else self.level_directory + layout.label(text=f"Actor export path: {level_path / self.export_locations}/") + elif self.export_header_type == "Custom": + custom_path = Path(bpy.path.abspath(self.custom_export_path)) + if not directory_ui_warnings(layout, custom_path): + return + layout.label(text=f"Actor export path: {custom_path / self.export_locations}/") return True def draw_col_names(self, layout): @@ -2266,17 +2291,13 @@ def draw_props(self, layout): "Duplicates objects will be exported! Use with Caution.", icon="ERROR", ) + return info_box = box.box() info_box.scale_y = 0.5 - if self.export_header_type == "Level": - if not self.draw_level_path(info_box): - return - - elif self.export_header_type == "Actor": - if not self.draw_actor_path(info_box): - return + if not self.draw_actor_path(info_box): + return if self.obj_name_gfx and self.export_gfx: self.draw_gfx_names(info_box) From b05065ffe31d14ee9647f92adbbf3124ecda2974 Mon Sep 17 00:00:00 2001 From: Lila Date: Mon, 9 Sep 2024 14:56:19 +0100 Subject: [PATCH 2/4] abs_decomp_path a little extra addition for code quality --- fast64_internal/sm64/settings/properties.py | 15 ++++++++++----- fast64_internal/sm64/sm64_objects.py | 12 ++++++------ fast64_internal/utility.py | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/fast64_internal/sm64/settings/properties.py b/fast64_internal/sm64/settings/properties.py index 471ad617d..07c38e849 100644 --- a/fast64_internal/sm64/settings/properties.py +++ b/fast64_internal/sm64/settings/properties.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import bpy from bpy.types import PropertyGroup, UILayout, Context from bpy.props import BoolProperty, StringProperty, EnumProperty, IntProperty, FloatProperty, PointerProperty @@ -22,10 +23,10 @@ def decomp_path_update(self, context: Context): fast64_settings = context.scene.fast64.settings - if fast64_settings.repo_settings_path: + if fast64_settings.repo_settings_path and Path(abspath(fast64_settings.repo_settings_path)).exists(): return - directory_path_checks(abspath(self.decomp_path)) - fast64_settings.repo_settings_path = os.path.join(abspath(self.decomp_path), "fast64.json") + directory_path_checks(self.abs_decomp_path) + fast64_settings.repo_settings_path = str(self.abs_decomp_path / "fast64.json") class SM64_Properties(PropertyGroup): @@ -83,7 +84,11 @@ class SM64_Properties(PropertyGroup): @property def binary_export(self): - return self.export_type in ["Binary", "Insertable Binary"] + return self.export_type in {"Binary", "Insertable Binary"} + + @property + def abs_decomp_path(self) -> Path: + return Path(abspath(self.decomp_path)) @staticmethod def upgrade_changed_props(): @@ -149,7 +154,7 @@ def draw_props(self, layout: UILayout, show_repo_settings: bool = True): col.prop(self, "extend_bank_4") elif not self.binary_export: prop_split(col, self, "decomp_path", "Decomp Path") - directory_ui_warnings(col, abspath(self.decomp_path)) + directory_ui_warnings(col, self.abs_decomp_path) col.separator() if not self.binary_export: diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index d523ed706..c0211608b 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -1548,7 +1548,7 @@ def write_file_lines(self, path, file_lines): # exports the model ID load into the appropriate script.c location def export_script_load(self, context, props): - decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path if props.export_header_type == "Level": # for some reason full_level_path doesn't work here if props.non_decomp_level: @@ -1594,7 +1594,7 @@ def export_model_id(self, context, props, offset): if props.non_decomp_level: return # check if model_ids.h exists - decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path model_ids = decomp_path / "include" / "model_ids.h" if not model_ids.exists(): PluginError("Could not find model_ids.h") @@ -1711,7 +1711,7 @@ def export_level_specific_load(self, script_path, props): def export_behavior_header(self, context, props): # check if behavior_header.h exists - decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path behavior_header = decomp_path / "include" / "behavior_data.h" if not behavior_header.exists(): PluginError("Could not find behavior_data.h") @@ -1745,7 +1745,7 @@ def export_behavior_script(self, context, props): raise PluginError("Behavior must have more than 0 cmds to export") # export the behavior script itself - decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path behavior_data = decomp_path / "data" / "behavior_data.c" if not behavior_data.exists(): PluginError("Could not find behavior_data.c") @@ -2114,7 +2114,7 @@ def level_directory(self) -> Path: def base_level_path(self): if self.non_decomp_level: return Path(bpy.path.abspath(self.custom_level_path)) - return Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + return bpy.context.scene.fast64.sm64.abs_decomp_path @property def full_level_path(self): @@ -2181,7 +2181,7 @@ def draw_level_path(self, layout): def draw_actor_path(self, layout): if self.export_locations is None: return - decomp_path = Path(bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path)) + decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path if self.export_header_type == "Actor": actor_path = decomp_path / "actors" if not filepath_ui_warnings(layout, (actor_path / self.actor_group_name).with_suffix(".c")): diff --git a/fast64_internal/utility.py b/fast64_internal/utility.py index 14f6aea59..a90fc5eed 100644 --- a/fast64_internal/utility.py +++ b/fast64_internal/utility.py @@ -423,7 +423,7 @@ def getPathAndLevel(is_custom_export, custom_export_path, custom_level_name, lev export_path = bpy.path.abspath(custom_export_path) level_name = custom_level_name else: - export_path = bpy.path.abspath(bpy.context.scene.fast64.sm64.decomp_path) + export_path = str(bpy.context.scene.fast64.sm64.abs_decomp_path) if level_enum == "Custom": level_name = custom_level_name else: From 37efd5b88ad10854599a798175e1e73857154736 Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 11 Sep 2024 12:40:44 +0100 Subject: [PATCH 3/4] dragon's review suggestions --- fast64_internal/sm64/sm64_objects.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index c0211608b..a31876226 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -2164,7 +2164,7 @@ def actor_names(self) -> list: def export_locations(self) -> str | None: names = self.actor_names if len(names) > 1: - return f"({'/'.join(names)})" + return f"{{{'/'.join(names)}}}" elif len(names) == 1: return names[0] return None @@ -2180,22 +2180,22 @@ def draw_level_path(self, layout): def draw_actor_path(self, layout): if self.export_locations is None: - return + return False decomp_path = bpy.context.scene.fast64.sm64.abs_decomp_path if self.export_header_type == "Actor": actor_path = decomp_path / "actors" if not filepath_ui_warnings(layout, (actor_path / self.actor_group_name).with_suffix(".c")): - return + return False layout.label(text=f"Actor export path: actors/{self.export_locations}/") elif self.export_header_type == "Level": if not directory_ui_warnings(layout, self.full_level_path): - return + return False level_path = self.full_level_path if self.non_decomp_level else self.level_directory layout.label(text=f"Actor export path: {level_path / self.export_locations}/") elif self.export_header_type == "Custom": custom_path = Path(bpy.path.abspath(self.custom_export_path)) if not directory_ui_warnings(layout, custom_path): - return + return False layout.label(text=f"Actor export path: {custom_path / self.export_locations}/") return True From 4a1060a9555874bddb8aedc14f8e63dfbb45c159 Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 11 Sep 2024 12:41:13 +0100 Subject: [PATCH 4/4] forgot to change this to a comma, oops --- fast64_internal/sm64/sm64_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast64_internal/sm64/sm64_objects.py b/fast64_internal/sm64/sm64_objects.py index a31876226..80884a3ac 100644 --- a/fast64_internal/sm64/sm64_objects.py +++ b/fast64_internal/sm64/sm64_objects.py @@ -2164,7 +2164,7 @@ def actor_names(self) -> list: def export_locations(self) -> str | None: names = self.actor_names if len(names) > 1: - return f"{{{'/'.join(names)}}}" + return f"{{{','.join(names)}}}" elif len(names) == 1: return names[0] return None