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