Skip to content

Commit

Permalink
move collection stuff to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis002 committed Dec 18, 2024
1 parent 81fd463 commit 29a7729
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 196 deletions.
7 changes: 4 additions & 3 deletions fast64_internal/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from .props_panel_main import oot_obj_panel_register, oot_obj_panel_unregister, oot_obj_register, oot_obj_unregister
from .skeleton.properties import OOTSkeletonImportSettings, OOTSkeletonExportSettings
from .oot_utility import oot_utility_register, oot_utility_unregister, setAllActorsVisibility
from .collection_utility import collections_register, collections_unregister
from .oot_utility import setAllActorsVisibility
from .file_settings import file_register, file_unregister
from .collision.properties import OOTCollisionExportSettings

Expand Down Expand Up @@ -141,7 +142,7 @@ def oot_panel_unregister():

def oot_register(registerPanels):
oot_operator_register()
oot_utility_register()
collections_register()
collision_ops_register() # register first, so panel goes above mat panel
collision_props_register()
cutscene_props_register()
Expand Down Expand Up @@ -180,7 +181,7 @@ def oot_unregister(unregisterPanels):
unregister_class(cls)

oot_operator_unregister()
oot_utility_unregister()
collections_unregister()
collision_ops_unregister() # register first, so panel goes above mat panel
collision_props_unregister()
oot_obj_unregister()
Expand Down
10 changes: 2 additions & 8 deletions fast64_internal/oot/actor/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
from ..oot_upgrade import upgradeActors
from ..scene.properties import OOTAlternateSceneHeaderProperty
from ..room.properties import OOTAlternateRoomHeaderProperty
from ..collection_utility import drawAddButton, drawCollectionOps
from ..oot_utility import getRoomObj, getEnumName, drawEnumWithCustom
from .operators import OOT_SearchActorIDEnumOperator

from ..oot_utility import (
getRoomObj,
getEnumName,
drawAddButton,
drawCollectionOps,
drawEnumWithCustom,
)

ootEnumSceneSetupPreset = [
("Custom", "Custom", "Custom"),
("All Scene Setups", "All Scene Setups", "All Scene Setups"),
Expand Down
177 changes: 177 additions & 0 deletions fast64_internal/oot/collection_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import bpy

from bpy.types import Operator
from bpy.utils import register_class, unregister_class
from bpy.props import IntProperty, StringProperty
from ..utility import PluginError, ootGetSceneOrRoomHeader


class OOTCollectionAdd(Operator):
bl_idname = "object.oot_collection_add"
bl_label = "Add Item"
bl_options = {"REGISTER", "UNDO"}

option: IntProperty()
collectionType: StringProperty(default="Actor")
subIndex: IntProperty(default=0)
objName: StringProperty()

def execute(self, context):
collection = getCollection(self.objName, self.collectionType, self.subIndex)

collection.add()
collection.move(len(collection) - 1, self.option)
return {"FINISHED"}


class OOTCollectionRemove(Operator):
bl_idname = "object.oot_collection_remove"
bl_label = "Remove Item"
bl_options = {"REGISTER", "UNDO"}

option: IntProperty()
collectionType: StringProperty(default="Actor")
subIndex: IntProperty(default=0)
objName: StringProperty()

def execute(self, context):
collection = getCollection(self.objName, self.collectionType, self.subIndex)
collection.remove(self.option)
return {"FINISHED"}


class OOTCollectionMove(Operator):
bl_idname = "object.oot_collection_move"
bl_label = "Move Item"
bl_options = {"REGISTER", "UNDO"}

option: IntProperty()
offset: IntProperty()
subIndex: IntProperty(default=0)
objName: StringProperty()

collectionType: StringProperty(default="Actor")

def execute(self, context):
collection = getCollection(self.objName, self.collectionType, self.subIndex)
collection.move(self.option, self.option + self.offset)
return {"FINISHED"}


def getCollectionFromIndex(obj, prop, subIndex, isRoom):
header = ootGetSceneOrRoomHeader(obj, subIndex, isRoom)
return getattr(header, prop)


# Operators cannot store mutable references (?), so to reuse PropertyCollection modification code we do this.
# Save a string identifier in the operator, then choose the member variable based on that.
# subIndex is for a collection within a collection element
def getCollection(objName, collectionType, subIndex):
obj = bpy.data.objects[objName]
if collectionType == "Actor":
collection = obj.ootActorProperty.headerSettings.cutsceneHeaders
elif collectionType == "Transition Actor":
collection = obj.ootTransitionActorProperty.actor.headerSettings.cutsceneHeaders
elif collectionType == "Entrance":
collection = obj.ootEntranceProperty.actor.headerSettings.cutsceneHeaders
elif collectionType == "Room":
collection = obj.ootAlternateRoomHeaders.cutsceneHeaders
elif collectionType == "Scene":
collection = obj.ootAlternateSceneHeaders.cutsceneHeaders
elif collectionType == "Light":
collection = getCollectionFromIndex(obj, "lightList", subIndex, False)
elif collectionType == "Exit":
collection = getCollectionFromIndex(obj, "exitList", subIndex, False)
elif collectionType == "Object":
collection = getCollectionFromIndex(obj, "objectList", subIndex, True)
elif collectionType == "Curve":
collection = obj.ootSplineProperty.headerSettings.cutsceneHeaders
elif collectionType.startswith("CSHdr."):
# CSHdr.HeaderNumber[.ListType]
# Specifying ListType means uses subIndex
toks = collectionType.split(".")
assert len(toks) in [2, 3]
hdrnum = int(toks[1])
collection = getCollectionFromIndex(obj, "csLists", hdrnum, False)
if len(toks) == 3:
collection = getattr(collection[subIndex], toks[2])
elif collectionType.startswith("Cutscene."):
# Cutscene.ListType
toks = collectionType.split(".")
assert len(toks) == 2
collection = obj.ootCutsceneProperty.csLists
collection = getattr(collection[subIndex], toks[1])
elif collectionType == "Cutscene":
collection = obj.ootCutsceneProperty.csLists
elif collectionType == "extraCutscenes":
collection = obj.ootSceneHeader.extraCutscenes
elif collectionType == "BgImage":
collection = obj.ootRoomHeader.bgImageList
else:
raise PluginError("Invalid collection type: " + collectionType)

return collection


def drawAddButton(layout, index, collectionType, subIndex, objName):
if subIndex is None:
subIndex = 0
addOp = layout.operator(OOTCollectionAdd.bl_idname)
addOp.option = index
addOp.collectionType = collectionType
addOp.subIndex = subIndex
addOp.objName = objName


def drawCollectionOps(layout, index, collectionType, subIndex, objName, allowAdd=True, compact=False):
if subIndex is None:
subIndex = 0

if not compact:
buttons = layout.row(align=True)
else:
buttons = layout

if allowAdd:
addOp = buttons.operator(OOTCollectionAdd.bl_idname, text="Add" if not compact else "", icon="ADD")
addOp.option = index + 1
addOp.collectionType = collectionType
addOp.subIndex = subIndex
addOp.objName = objName

removeOp = buttons.operator(OOTCollectionRemove.bl_idname, text="Delete" if not compact else "", icon="REMOVE")
removeOp.option = index
removeOp.collectionType = collectionType
removeOp.subIndex = subIndex
removeOp.objName = objName

moveUp = buttons.operator(OOTCollectionMove.bl_idname, text="Up" if not compact else "", icon="TRIA_UP")
moveUp.option = index
moveUp.offset = -1
moveUp.collectionType = collectionType
moveUp.subIndex = subIndex
moveUp.objName = objName

moveDown = buttons.operator(OOTCollectionMove.bl_idname, text="Down" if not compact else "", icon="TRIA_DOWN")
moveDown.option = index
moveDown.offset = 1
moveDown.collectionType = collectionType
moveDown.subIndex = subIndex
moveDown.objName = objName


collections_classes = (
OOTCollectionAdd,
OOTCollectionRemove,
OOTCollectionMove,
)


def collections_register():
for cls in collections_classes:
register_class(cls)


def collections_unregister():
for cls in reversed(collections_classes):
unregister_class(cls)
2 changes: 1 addition & 1 deletion fast64_internal/oot/cutscene/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from bpy.types import Scene, Operator, Context
from bpy.utils import register_class, unregister_class
from ...utility import CData, PluginError, writeCData, raisePluginError
from ..oot_utility import getCollection
from ..collection_utility import getCollection
from ..oot_constants import ootData
from .constants import ootEnumCSTextboxType, ootEnumCSListType
from .importer import importCutsceneData
Expand Down
3 changes: 2 additions & 1 deletion fast64_internal/oot/cutscene/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from bpy.props import StringProperty, EnumProperty, IntProperty, BoolProperty, CollectionProperty, PointerProperty
from bpy.utils import register_class, unregister_class
from ...utility import PluginError, prop_split
from ..oot_utility import OOTCollectionAdd, drawCollectionOps, getEnumName
from ..collection_utility import OOTCollectionAdd, drawCollectionOps
from ..oot_utility import getEnumName
from ..oot_constants import ootData
from ..oot_upgrade import upgradeCutsceneSubProps, upgradeCSListProps, upgradeCutsceneProperty
from .operators import OOTCSTextAdd, OOT_SearchCSDestinationEnumOperator, OOTCSListAdd, OOT_SearchCSSeqOperator
Expand Down
Loading

0 comments on commit 29a7729

Please sign in to comment.