mirror of https://github.com/H-uru/korman.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.6 KiB
61 lines
2.6 KiB
# This file is part of Korman. |
|
# |
|
# Korman is free software: you can redistribute it and/or modify |
|
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation, either version 3 of the License, or |
|
# (at your option) any later version. |
|
# |
|
# Korman is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
import bpy |
|
from bpy.props import * |
|
|
|
class TextureOperator: |
|
@classmethod |
|
def poll(cls, context): |
|
return context.scene.render.engine == "PLASMA_GAME" and context.texture |
|
|
|
|
|
class TextureCollectionAddOperator(TextureOperator, bpy.types.Operator): |
|
bl_idname = "texture.plasma_collection_add" |
|
bl_label = "Add Item" |
|
bl_description = "Adds an item to the collection" |
|
|
|
group = StringProperty(name="Modifier", description="Attribute name of the PropertyGroup") |
|
collection = StringProperty(name="Collection", description="Attribute name of the collection property") |
|
name_prefix = StringProperty(name="Name Prefix", description="Prefix for autogenerated item names", default="Item") |
|
name_prop = StringProperty(name="Name Property", description="Attribute name of the item name property") |
|
|
|
def execute(self, context): |
|
mod = getattr(context.texture, self.group) |
|
collection = getattr(mod, self.collection) |
|
idx = len(collection) |
|
collection.add() |
|
if self.name_prop: |
|
setattr(collection[idx], self.name_prop, "{} {}".format(self.name_prefix, idx+1)) |
|
return {"FINISHED"} |
|
|
|
|
|
class TextureCollectionRemoveOperator(TextureOperator, bpy.types.Operator): |
|
bl_idname = "texture.plasma_collection_remove" |
|
bl_label = "Remove Item" |
|
bl_description = "Removes an item from the collection" |
|
|
|
group = StringProperty(name="Modifier", description="Attribute name of the PropertyGroup") |
|
collection = StringProperty(name="Collection", description="Attribute name of the collection property") |
|
index = IntProperty(name="Index", description="Item index to remove") |
|
|
|
def execute(self, context): |
|
mod = getattr(context.texture, self.group) |
|
collection = getattr(mod, self.collection) |
|
if len(collection) > self.index: |
|
collection.remove(self.index) |
|
return {"FINISHED"} |
|
else: |
|
return {"CANCELLED"}
|
|
|