Update leenkx/blender/lnx/props_traits.py

This commit is contained in:
2025-09-29 05:28:13 +00:00
parent c24baa3364
commit 73fcb55acc

View File

@ -13,13 +13,6 @@ import lnx.make as make
from lnx.props_traits_props import *
import lnx.ui_icons as ui_icons
def compatible_prop(property_func, **kwargs):
"""Create properties compatible with different Blender versions."""
if bpy.app.version < (2, 90, 0):
# Remove override parameter for Blender 2.83
kwargs.pop('override', None)
return property_func(**kwargs)
import lnx.utils
import lnx.write_data as write_data
@ -99,21 +92,32 @@ class LnxTraitListItem(bpy.types.PropertyGroup):
def poll_node_trees(self, tree: NodeTree):
"""Ensure that only logic node trees show up as node traits"""
return tree.bl_idname == 'LnxLogicTreeType'
if bpy.app.version < (2, 90, 0):
name: StringProperty(name="Name", description="The name of the trait", default="")
enabled_prop: BoolProperty(name="", description="Whether this trait is enabled", default=True, update=trigger_recompile)
fake_user: BoolProperty(name="Fake User", description="Export this trait even if it is deactivated", default=False)
class_name_prop: StringProperty(name="Class", description="A name for this item", default="", update=update_trait_group)
canvas_name_prop: StringProperty(name="Canvas", description="A name for this item", default="", update=update_trait_group)
webassembly_prop: StringProperty(name="Module", description="A name for this item", default="", update=update_trait_group)
node_tree_prop: PointerProperty(type=NodeTree, update=update_trait_group, poll=poll_node_trees)
lnx_traitpropslist_index: IntProperty(name="Index for my_list", default=0, options={"LIBRARY_EDITABLE"})
else:
name: StringProperty(name="Name", description="The name of the trait", default="", override={"LIBRARY_OVERRIDABLE"})
enabled_prop: BoolProperty(name="", description="Whether this trait is enabled", default=True, update=trigger_recompile, override={"LIBRARY_OVERRIDABLE"})
fake_user: BoolProperty(name="Fake User", description="Export this trait even if it is deactivated", default=False, override={"LIBRARY_OVERRIDABLE"})
class_name_prop: StringProperty(name="Class", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
canvas_name_prop: StringProperty(name="Canvas", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
webassembly_prop: StringProperty(name="Module", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
node_tree_prop: PointerProperty(type=NodeTree, update=update_trait_group, override={"LIBRARY_OVERRIDABLE"}, poll=poll_node_trees)
lnx_traitpropslist_index: IntProperty(name="Index for my_list", default=0, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"})
name = compatible_prop(StringProperty, name="Name", description="The name of the trait", default="", override={"LIBRARY_OVERRIDABLE"})
enabled_prop = compatible_prop(BoolProperty, name="", description="Whether this trait is enabled", default=True, update=trigger_recompile, override={"LIBRARY_OVERRIDABLE"})
is_object = BoolProperty(name="", default=True)
fake_user = compatible_prop(BoolProperty, name="Fake User", description="Export this trait even if it is deactivated", default=False, override={"LIBRARY_OVERRIDABLE"})
type_prop = EnumProperty(name="Type", items=PROP_TYPES_ENUM)
is_object: BoolProperty(name="", default=True)
type_prop: EnumProperty(name="Type", items=PROP_TYPES_ENUM)
class_name_prop = compatible_prop(StringProperty, name="Class", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
canvas_name_prop = compatible_prop(StringProperty, name="Canvas", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
webassembly_prop = compatible_prop(StringProperty, name="Module", description="A name for this item", default="", update=update_trait_group, override={"LIBRARY_OVERRIDABLE"})
node_tree_prop = compatible_prop(PointerProperty, type=NodeTree, update=update_trait_group, override={"LIBRARY_OVERRIDABLE"}, poll=poll_node_trees)
lnx_traitpropslist = CollectionProperty(type=LnxTraitPropListItem)
lnx_traitpropslist_index = compatible_prop(IntProperty, name="Index for my_list", default=0, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"})
lnx_traitpropswarnings = CollectionProperty(type=LnxTraitPropWarning)
lnx_traitpropslist: CollectionProperty(type=LnxTraitPropListItem)
lnx_traitpropswarnings: CollectionProperty(type=LnxTraitPropWarning)
class LNX_UL_TraitList(bpy.types.UIList):
"""List of traits."""
@ -1077,7 +1081,14 @@ __reg_classes, unregister = bpy.utils.register_classes_factory(__REG_CLASSES)
def register():
__reg_classes()
bpy.types.Object.lnx_traitlist = compatible_prop(CollectionProperty, type=LnxTraitListItem)
bpy.types.Object.lnx_traitlist_index = compatible_prop(IntProperty, name="Index for lnx_traitlist", default=0)
bpy.types.Scene.lnx_traitlist = compatible_prop(CollectionProperty, type=LnxTraitListItem)
bpy.types.Scene.lnx_traitlist_index = compatible_prop(IntProperty, name="Index for lnx_traitlist", default=0)
if bpy.app.version < (2, 90, 0):
bpy.types.Object.lnx_traitlist = CollectionProperty(type=LnxTraitListItem)
bpy.types.Object.lnx_traitlist_index = IntProperty(name="Index for lnx_traitlist", default=0, options={"LIBRARY_EDITABLE"})
bpy.types.Scene.lnx_traitlist = CollectionProperty(type=LnxTraitListItem)
bpy.types.Scene.lnx_traitlist_index = IntProperty(name="Index for lnx_traitlist", default=0, options={"LIBRARY_EDITABLE"})
else:
bpy.types.Object.lnx_traitlist = CollectionProperty(type=LnxTraitListItem, override={"LIBRARY_OVERRIDABLE", "USE_INSERTION"})
bpy.types.Object.lnx_traitlist_index = IntProperty(name="Index for lnx_traitlist", default=0, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"})
bpy.types.Scene.lnx_traitlist = CollectionProperty(type=LnxTraitListItem, override={"LIBRARY_OVERRIDABLE", "USE_INSERTION"})
bpy.types.Scene.lnx_traitlist_index = IntProperty(name="Index for lnx_traitlist", default=0, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"})