Files
armorpaint/Sources/arm/node/LogicNode.hx
T

72 lines
1.3 KiB
Haxe
Raw Normal View History

2019-11-13 15:17:10 +01:00
package arm.node;
2019-06-22 00:21:47 +02:00
class LogicNode {
var tree:LogicTree;
var inputs:Array<LogicNodeInput> = [];
var outputs:Array<Array<LogicNode>> = [];
public function new(tree:LogicTree) {
this.tree = tree;
}
public function addInput(node:LogicNode, from:Int) {
inputs.push(new LogicNodeInput(node, from));
}
public function addOutputs(nodes:Array<LogicNode>) {
outputs.push(nodes);
}
/**
* Called when this node is activated.
* @param from impulse index
*/
function run(from:Int) {}
/**
* Call to activate node connected to the output.
* @param i output index
*/
function runOutput(i:Int) {
if (i >= outputs.length) return;
for (o in outputs[i]) {
// Check which input activated the node
for (j in 0...o.inputs.length) {
if (o.inputs[j].node == this) {
o.run(j);
break;
}
}
}
}
2019-11-13 15:17:10 +01:00
@:allow(arm.node.LogicNodeInput)
2019-06-22 00:21:47 +02:00
function get(from:Int):Dynamic { return this; }
2019-11-13 15:17:10 +01:00
@:allow(arm.node.LogicNodeInput)
2019-06-22 00:21:47 +02:00
function set(value:Dynamic) { }
}
class LogicNodeInput {
2019-11-13 15:17:10 +01:00
@:allow(arm.node.LogicNode)
2019-06-22 00:21:47 +02:00
var node:LogicNode;
var from:Int; // Socket index
public function new(node:LogicNode, from:Int) {
this.node = node;
this.from = from;
}
2019-11-13 15:17:10 +01:00
@:allow(arm.node.LogicNode)
2019-06-22 00:21:47 +02:00
function get():Dynamic {
return node.get(from);
}
2019-11-13 15:17:10 +01:00
@:allow(arm.node.LogicNode)
2019-06-22 00:21:47 +02:00
function set(value:Dynamic) {
node.set(value);
}
}