Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM64] Fix/Improve multi-actor UI (not export all selected) #450

Merged
merged 5 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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:
Expand Down
69 changes: 45 additions & 24 deletions fast64_internal/sm64/sm64_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 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 @@ -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}")
Expand All @@ -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")):
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 @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading