Moved get_collection_*from_context functions to helpers.py

This commit is contained in:
Colin Basnett
2025-08-03 01:42:44 -07:00
parent bd3ea76109
commit 5c50e76771
3 changed files with 28 additions and 26 deletions

View File

@@ -15,7 +15,7 @@ from ..builder import (
get_psk_input_objects_for_context, get_psk_input_objects_for_context,
) )
from ..writer import write_psk from ..writer import write_psk
from ...shared.helpers import PsxBoneCollection, populate_bone_collection_list from ...shared.helpers import PsxBoneCollection, get_collection_export_operator_from_context, populate_bone_collection_list
from ...shared.ui import draw_bone_filter_mode from ...shared.ui import draw_bone_filter_mode
@@ -35,29 +35,6 @@ def populate_material_name_list(depsgraph: Depsgraph, mesh_objects: Iterable[Obj
def get_collection_from_context(context: Context) -> Optional[Collection]:
if context.space_data.type != 'PROPERTIES':
return None
space_data = typing_cast(SpaceProperties, context.space_data)
if space_data.use_pin_id:
return typing_cast(Collection, space_data.pin_id)
else:
return context.collection
def get_collection_export_operator_from_context(context: Context) -> Optional[object]:
collection = get_collection_from_context(context)
if collection is None:
return None
if 0 > collection.active_exporter_index >= len(collection.exporters):
return None
exporter = collection.exporters[collection.active_exporter_index]
# TODO: make sure this is actually an ASE exporter.
return exporter.export_properties
class PSK_OT_bone_collection_list_populate(Operator): class PSK_OT_bone_collection_list_populate(Operator):
bl_idname = 'psk.bone_collection_list_populate' bl_idname = 'psk.bone_collection_list_populate'
bl_label = 'Populate Bone Collection List' bl_label = 'Populate Bone Collection List'
@@ -69,6 +46,9 @@ class PSK_OT_bone_collection_list_populate(Operator):
if export_operator is None: if export_operator is None:
self.report({'ERROR_INVALID_CONTEXT'}, 'No valid export operator found in context') self.report({'ERROR_INVALID_CONTEXT'}, 'No valid export operator found in context')
return {'CANCELLED'} return {'CANCELLED'}
if context.collection is None:
self.report({'ERROR_INVALID_CONTEXT'}, 'No active collection')
return {'CANCELLED'}
try: try:
input_objects = get_psk_input_objects_for_collection(context.collection) input_objects = get_psk_input_objects_for_collection(context.collection)
except RuntimeError as e: except RuntimeError as e:

View File

@@ -1,13 +1,15 @@
from bpy.types import Context
from bpy.props import ( from bpy.props import (
BoolProperty, BoolProperty,
CollectionProperty, CollectionProperty,
EnumProperty, EnumProperty,
FloatProperty,
IntProperty, IntProperty,
PointerProperty, PointerProperty,
StringProperty, StringProperty,
) )
from bpy.types import Material, PropertyGroup from bpy.types import Material, PropertyGroup
from ...shared.helpers import get_collection_export_operator_from_context
from ...shared.types import ExportSpaceMixin, TransformMixin, PsxBoneExportMixin from ...shared.types import ExportSpaceMixin, TransformMixin, PsxBoneExportMixin
object_eval_state_items = ( object_eval_state_items = (

View File

@@ -1,7 +1,7 @@
import bpy import bpy
from collections import Counter from collections import Counter
from typing import List, Iterable, Optional, Dict, Tuple, cast as typing_cast from typing import List, Iterable, Optional, Dict, Tuple, cast as typing_cast
from bpy.types import Armature, AnimData, Object, ArmatureModifier from bpy.types import Armature, AnimData, Collection, Context, Object, ArmatureModifier, SpaceProperties
from mathutils import Matrix, Vector, Quaternion as BpyQuaternion from mathutils import Matrix, Vector, Quaternion as BpyQuaternion
from .data import Vector3, Quaternion from .data import Vector3, Quaternion
from ..shared.data import PsxBone from ..shared.data import PsxBone
@@ -480,3 +480,23 @@ def get_armatures_for_mesh_objects(mesh_objects: Iterable[Object]):
if armature_object is not None: if armature_object is not None:
armature_objects.add(armature_object) armature_objects.add(armature_object)
yield from armature_objects yield from armature_objects
def get_collection_from_context(context: Context) -> Optional[Collection]:
if context.space_data is None or context.space_data.type != 'PROPERTIES':
return None
space_data = typing_cast(SpaceProperties, context.space_data)
if space_data.use_pin_id:
return typing_cast(Collection, space_data.pin_id)
else:
return context.collection
def get_collection_export_operator_from_context(context: Context) -> Optional[object]:
collection = get_collection_from_context(context)
if collection is None or collection.active_exporter_index is None:
return None
if 0 > collection.active_exporter_index >= len(collection.exporters):
return None
exporter = collection.exporters[collection.active_exporter_index]
return exporter.export_properties