Skip to content

Commit

Permalink
Some Adjustments
Browse files Browse the repository at this point in the history
A few adjustments to my poor copy paste to hopefully match it better with the node's other pieces.
  • Loading branch information
DoobesURU committed Feb 6, 2022
1 parent 2554b6e commit d042cc2
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions korman/nodes/node_python.py
Expand Up @@ -852,46 +852,47 @@ def _poll_texture(self, value: bpy.types.Texture) -> bool:
else:
return True

target_object = PointerProperty(name="Object",
description="",
type=bpy.types.Object,
poll=idprops.poll_drawable_objects)
material = PointerProperty(name="Material",
description="Material the texture is attached to",
type=bpy.types.Material,
poll=_poll_material)
texture = PointerProperty(name="Texture",
description="Texture to expose to Python",
type=bpy.types.Texture,
poll=_poll_texture)

# Blender memory workaround
_ENTIRE_ANIMATION = "(Entire Animation)"
def _get_anim_names(self, context):
if self.anim_type == "TEXTURE":
if self.target_texture is not None:
if self.texture.plasma_layer.subanimations:
if self.texture is not None:
items = [(anim.animation_name, anim.animation_name, "")
for anim in self.target_texture.plasma_layer.subanimations]
elif self.target_material is not None or self.target_object is not None:
if self.target_material is None:
for anim in self.texture.plasma_layer.subanimations]
elif self.material is not None or self.target_object is not None:
if self.material is None:
materials = (i.material for i in self.target_object.material_slots if i and i.material)
else:
materials = (self.target_material,)
materials = (self.material,)
layer_props = (i.texture.plasma_layer for mat in materials for i in mat.texture_slots if i and i.texture)
all_anims = frozenset((anim.animation_name for i in layer_props for anim in i.subanimations))
items = [(i, i, "") for i in all_anims]
else:
items = [(PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, "")]
items = [(PlasmaAttribTextureNode._ENTIRE_ANIMATION, PlasmaAttribTextureNode._ENTIRE_ANIMATION, "")]
else:
raise RuntimeError()

# We always want "(Entire Animation)", if it exists, to be the first item.
entire = items.index((PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, ""))
entire = items.index((PlasmaAttribTextureNode._ENTIRE_ANIMATION, PlasmaAttribTextureNode._ENTIRE_ANIMATION, ""))
if entire not in (-1, 0):
items.pop(entire)
items.insert(0, (PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, PlasmaAnimCmdMsgNode._ENTIRE_ANIMATION, ""))
items.insert(0, (PlasmaAttribTextureNode._ENTIRE_ANIMATION, PlasmaAttribTextureNode._ENTIRE_ANIMATION, ""))

return items

target_object = PointerProperty(name="Object",
description="",
type=bpy.types.Object,
poll=idprops.poll_drawable_objects)
material = PointerProperty(name="Material",
description="Material the texture is attached to",
type=bpy.types.Material,
poll=_poll_material)
texture = PointerProperty(name="Texture",
description="Texture to expose to Python",
type=bpy.types.Texture,
poll=_poll_texture)
anim_name = EnumProperty(name="Animation",
description="Name of the animation to control",
items=_get_anim_names,
Expand All @@ -916,7 +917,7 @@ def draw_buttons(self, context, layout):
if self.anim_name is None:
layout.label("The selected texture has no animation data.", icon="ERROR")
layout.alert = True

layout.alert = not any((self.target_object, self.material, self.texture))
layout.prop(self, "target_object")
layout.prop(self, "material")
layout.prop(self, "texture")
Expand Down

0 comments on commit d042cc2

Please sign in to comment.