Two new logic nodes for the "Random" category
This commit is contained in:
parent
b36cf8327b
commit
74d6b594a6
14
Sources/armory/logicnode/RandomChoiceNode.hx
Normal file
14
Sources/armory/logicnode/RandomChoiceNode.hx
Normal 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)];
|
||||||
|
}
|
||||||
|
}
|
12
Sources/armory/logicnode/RandomOutputNode.hx
Normal file
12
Sources/armory/logicnode/RandomOutputNode.hx
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
17
blender/arm/logicnode/random/LN_random_choice.py
Normal file
17
blender/arm/logicnode/random/LN_random_choice.py
Normal 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)
|
28
blender/arm/logicnode/random/LN_random_output.py
Normal file
28
blender/arm/logicnode/random/LN_random_output.py
Normal 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')
|
Loading…
Reference in a new issue