Moved get_collection_*from_context functions to helpers.py
This commit is contained in:
@@ -15,7 +15,7 @@ from ..builder import (
|
||||
get_psk_input_objects_for_context,
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
@@ -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):
|
||||
bl_idname = 'psk.bone_collection_list_populate'
|
||||
bl_label = 'Populate Bone Collection List'
|
||||
@@ -69,6 +46,9 @@ class PSK_OT_bone_collection_list_populate(Operator):
|
||||
if export_operator is None:
|
||||
self.report({'ERROR_INVALID_CONTEXT'}, 'No valid export operator found in context')
|
||||
return {'CANCELLED'}
|
||||
if context.collection is None:
|
||||
self.report({'ERROR_INVALID_CONTEXT'}, 'No active collection')
|
||||
return {'CANCELLED'}
|
||||
try:
|
||||
input_objects = get_psk_input_objects_for_collection(context.collection)
|
||||
except RuntimeError as e:
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
from bpy.types import Context
|
||||
from bpy.props import (
|
||||
BoolProperty,
|
||||
CollectionProperty,
|
||||
EnumProperty,
|
||||
FloatProperty,
|
||||
IntProperty,
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
)
|
||||
from bpy.types import Material, PropertyGroup
|
||||
|
||||
from ...shared.helpers import get_collection_export_operator_from_context
|
||||
from ...shared.types import ExportSpaceMixin, TransformMixin, PsxBoneExportMixin
|
||||
|
||||
object_eval_state_items = (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import bpy
|
||||
from collections import Counter
|
||||
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 .data import Vector3, Quaternion
|
||||
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:
|
||||
armature_objects.add(armature_object)
|
||||
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
|
||||
Reference in New Issue
Block a user