Skip to content

Commit

Permalink
[SM64] Fix/Improve multi-actor UI (not export all selected) (#450)
Browse files Browse the repository at this point in the history
* [SM64] Fix/Improve multi-actor UI (not export all selected)

* abs_decomp_path

a little extra addition for code quality

* dragon's review suggestions

* forgot to change this to a comma, oops
  • Loading branch information
Lilaa3 authored Dec 28, 2024
1 parent 85330e1 commit c475ce3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
15 changes: 10 additions & 5 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -173,7 +178,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 show_repo_settings:
Expand Down
66 changes: 42 additions & 24 deletions fast64_internal/sm64/sm64_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,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:
Expand Down Expand Up @@ -1605,7 +1605,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")
Expand Down Expand Up @@ -1722,7 +1722,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")
Expand Down Expand Up @@ -1756,7 +1756,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")
Expand Down Expand Up @@ -2116,21 +2116,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 bpy.context.scene.fast64.sm64.abs_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):
Expand Down Expand Up @@ -2172,8 +2172,17 @@ def draw_export_options(self, layout):
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}")
Expand All @@ -2182,12 +2191,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")):
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}")
if self.export_locations is None:
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 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 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 False
layout.label(text=f"Actor export path: {custom_path / self.export_locations}/")
return True

def draw_col_names(self, layout):
Expand Down Expand Up @@ -2284,18 +2305,15 @@ 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
if not self.draw_actor_path(info_box):
return

elif self.export_header_type == "Actor":
if not self.draw_actor_path(info_box):
return
elif self.export_header_type == "Custom" and bpy.context.scene.saveTextures:
if self.export_header_type == "Custom" and bpy.context.scene.saveTextures:
if self.custom_include_directory:
info_box.label(text=f'Include directory "{self.custom_include_directory}"')
else:
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,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:
Expand Down

0 comments on commit c475ce3

Please sign in to comment.