Two new logic nodes for the "Random" category

This commit is contained in:
Moritz Brückner 2020-10-19 18:21:56 +02:00
parent b36cf8327b
commit 74d6b594a6
4 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,14 @@
package armory.logicnode;
class RandomChoiceNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var array: Array<Dynamic> = inputs[0].get();
return array[Std.random(array.length)];
}
}

View file

@ -0,0 +1,12 @@
package armory.logicnode;
class RandomOutputNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
runOutput(Std.random(outputs.length));
}
}

View file

@ -0,0 +1,17 @@
from arm.logicnode.arm_nodes import *
class RandomChoiceNode(ArmLogicTreeNode):
"""Choose a random value from a given array."""
bl_idname = 'LNRandomChoiceNode'
bl_label = 'Random Choice'
arm_version = 1
def init(self, context):
super().init(context)
self.add_input('ArmNodeSocketArray', 'Array')
self.add_output('NodeSocketShader', 'Value')
add_node(RandomChoiceNode, category=PKG_AS_CATEGORY)

View file

@ -0,0 +1,28 @@
from arm.logicnode.arm_nodes import *
class RandomOutputNode(ArmLogicTreeNode):
"""Activate a random output when the input is activated."""
bl_idname = 'LNRandomOutputNode'
bl_label = 'Random Output'
arm_version = 1
def __init__(self):
array_nodes[str(id(self))] = self
def init(self, context):
super().init(context)
self.add_input('ArmNodeSocketAction', 'In')
def draw_buttons(self, context, layout):
row = layout.row(align=True)
op = row.operator('arm.node_add_output', text='New', icon='PLUS', emboss=True)
op.node_index = str(id(self))
op.socket_type = 'ArmNodeSocketAction'
op2 = row.operator('arm.node_remove_output', text='', icon='X', emboss=True)
op2.node_index = str(id(self))
add_node(RandomOutputNode, category=PKG_AS_CATEGORY, section='logic')