Skip to content

Commit

Permalink
fixed level writing errors, added extra safety checks, modified UI an…
Browse files Browse the repository at this point in the history
…d cleaned formatting
  • Loading branch information
scut committed Jan 10, 2024
1 parent 9ccca22 commit 980fdfd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 95 deletions.
21 changes: 1 addition & 20 deletions fast64_internal/sm64/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,7 @@ class SM64_Properties(PropertyGroup):
goal: EnumProperty(items=sm64GoalTypeEnum, name="Export Goal", default="All")

combined_export: bpy.props.PointerProperty(type=SM64_CombinedObjectProperties)

# TODO: Utilize these across all exports
# C exporting
# useCustomExportLocation = BoolProperty(name = 'Use Custom Export Path')
# customExportPath: StringProperty(name = 'Custom Export Path', subtype = 'FILE_PATH')
# exportLocation: EnumProperty(items = enumExportHeaderType, name = 'Export Location', default = 'Actor')
# useSelectedObjectName = BoolProperty(name = 'Use Name From Selected Object', default=False)
# exportName: StringProperty(name='Name', default='mario')
# exportGeolayoutName: StringProperty(name='Name', default='mario_geo')

# Actor exports
# exportGroup: StringProperty(name='Group', default='group0')

# Level exports
# exportLevelName: StringProperty(name = 'Level', default = 'bob')
# exportLevelOption: EnumProperty(items = enumLevelNames, name = 'Level', default = 'bob')

# Insertable Binary
# exportInsertableBinaryPath: StringProperty(name = 'Filepath', subtype = 'FILE_PATH')


@staticmethod
def upgrade_changed_props():
if bpy.context.scene.fast64.sm64.version != SM64_Properties.cur_version:
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/sm64/sm64_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def exportCollisionCommon(obj, transformMatrix, includeSpecials, includeChildren
try:
addCollisionTriangles(tempObj, collisionDict, includeChildren, transformMatrix, areaIndex)
if not collisionDict:
raise PluginError("No collision data to export, col export cancelled")
raise PluginError("No collision data to export")
cleanupDuplicatedObjects(allObjs)
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
Expand Down
38 changes: 17 additions & 21 deletions fast64_internal/sm64/sm64_level_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ def __init__(self, masks, originalData):
self.originalData = originalData

def to_c(self):
result = ""
# result += 'u8 sZoomOutAreaMasks[] = {\n'
result += "\n"
result += macrosToString(self.masks)
# result += '};\n'
return result
return f"{macrosToString(self.masks)}\n"

def write(self, filepath):
matchResult = re.search(
Expand Down Expand Up @@ -199,9 +194,9 @@ def __init__(self, headerInfo, courses, bonusCourses, originalData):

def to_c(self):
result = self.headerInfo
result += macrosToString(self.courses, tabDepth=0)
result += "DEFINE_COURSES_END()\n"
result += macrosToString(self.bonusCourses, tabDepth=0)
result += macrosToString(self.courses, tabDepth=0, comma = False)
result += "\nDEFINE_COURSES_END()\n"
result += macrosToString(self.bonusCourses, tabDepth=0, comma = False)
return result

def write(self, filepath):
Expand Down Expand Up @@ -241,7 +236,7 @@ def __init__(self, headerInfo, defineMacros, originalData):

def to_c(self):
result = self.headerInfo
result += macrosToString(self.defineMacros, tabDepth=0)
result += macrosToString(self.defineMacros, tabDepth=0, comma = False)
return result

def write(self, filepath, headerPath):
Expand Down Expand Up @@ -357,7 +352,8 @@ def to_c(self, areaString):
None,
(
# all the includes
"#include <ultra64.h>" '#include "sm64.h"',
"#include <ultra64.h>",
'#include "sm64.h"',
'#include "behavior_data.h"',
'#include "model_ids.h"',
'#include "seq_ids.h"',
Expand Down Expand Up @@ -518,13 +514,13 @@ def stringToMacros(data):
return macroData


def macroToString(macro_cmd):
return f"{macro_cmd.function}({', '.join(macro_cmd.args)}), {macro_cmd.comment}"
def macroToString(macro_cmd, comma = True):
return f"{macro_cmd.function}({', '.join(macro_cmd.args)}){',' if comma else ''} {macro_cmd.comment}"


def macrosToString(macro_cmds, tabDepth=1):
def macrosToString(macro_cmds, tabDepth=1, comma = True):
tabs = "\t" * tabDepth
return "\n".join([f"{tabs}{macroToString(macro_cmd)}" for macro_cmd in macro_cmds])
return "\n".join([f"{tabs}{macroToString(macro_cmd, comma = comma)}" for macro_cmd in macro_cmds])


def setStartLevel(basePath, levelEnum):
Expand Down Expand Up @@ -738,7 +734,7 @@ def __init__(self):


def export_area_c(
obj, level_data, area_root, prev_level_script, transformMatrix, levelName, level_dir, fModel, DLFormat, savePNG
obj, level_data, area_root, prev_level_script, transformMatrix, level_name, level_dir, fModel, DLFormat, savePNG
):
areaName = f"area_{area_root.areaIndex}"
areaDir = os.path.join(level_dir, areaName)
Expand All @@ -749,14 +745,14 @@ def export_area_c(
uses_env_fx = envOption != "ENVFX_MODE_NONE"

def include_proto(file_name):
return f'#include "levels/{levelName}/{areaName}/{file_name}"\n'
return f'#include "levels/{level_name}/{areaName}/{file_name}"\n'

# Write geolayout
geolayoutGraph, fModel = convertObjectToGeolayout(
obj,
transformMatrix,
area_root.areaCamera,
f"{levelName}_{areaName}",
f"{level_name}_{areaName}",
fModel,
area_root,
DLFormat,
Expand All @@ -770,7 +766,7 @@ def include_proto(file_name):
# Write collision, rooms MUST be done first
setRooms(area_root)
collision = exportCollisionCommon(
area_root, transformMatrix, True, True, f"{levelName}_{areaName}", area_root.areaIndex
area_root, transformMatrix, True, True, f"{level_name}_{areaName}", area_root.areaIndex
)
collisionC = collision.to_c()
saveDataToFile(os.path.join(areaDir, "collision.inc.c"), collisionC.source)
Expand All @@ -786,7 +782,7 @@ def include_proto(file_name):

# Get area
area = exportAreaCommon(
area_root, transformMatrix, geolayoutGraph.startGeolayout, collision, f"{levelName}_{areaName}"
area_root, transformMatrix, geolayoutGraph.startGeolayout, collision, f"{level_name}_{areaName}"
)
if area.mario_start is not None:
prev_level_script.marioStart = area.mario_start
Expand Down Expand Up @@ -933,7 +929,7 @@ def exportLevelC(obj, transformMatrix, level_name, exportDir, savePNG, customExp
shutil.rmtree(os.path.join(level_dir, folder))

def include_proto(file_name):
return f'#include "levels/{level_name}/{file_name}/"\n'
return f'#include "levels/{level_name}/{file_name}"\n'

gfxFormatter = SM64GfxFormatter(ScrollMethod.Vertex)
exportData = fModel.to_c(TextureExportSettings(savePNG, savePNG, f"levels/{level_name}", level_dir), gfxFormatter)
Expand Down
Loading

0 comments on commit 980fdfd

Please sign in to comment.