armory/Sources/armory/logicnode/TimeNode.hx

78 lines
1.6 KiB
Haxe
Raw Normal View History

2016-08-22 21:56:28 +02:00
package armory.logicnode;
2015-11-26 15:36:17 +01:00
2016-07-28 13:21:27 +02:00
import armory.trait.internal.NodeExecutor;
2015-11-26 15:36:17 +01:00
class TimeNode extends FloatNode {
public static inline var _startTime = 0; // Float
public static inline var _stopTime = 1; // Float
2016-08-14 21:08:01 +02:00
public static inline var _enabled = 2; // Bool
public static inline var _loop = 3; // Bool
public static inline var _reflect = 4; // Bool
var scale = 1.0;
2015-11-26 15:36:17 +01:00
public function new() {
super();
}
public override function start(executor:NodeExecutor, parent:Node = null) {
super.start(executor, parent);
f = inputs[_startTime].f;
2016-08-14 21:08:01 +02:00
executor.notifyOnNodeUpdate(update);
2015-11-26 15:36:17 +01:00
}
function update() {
if (inputs[_enabled].b) {
2016-09-23 00:34:42 +02:00
f += iron.system.Time.delta * scale;
2015-11-26 15:36:17 +01:00
// Time out
if (inputs[_stopTime].f > 0) {
2016-08-14 21:08:01 +02:00
if (scale > 0 && f >= inputs[_stopTime].f ||
scale < 0 && f <= inputs[_startTime].f) {
2015-11-26 15:36:17 +01:00
// Loop
if (inputs[_loop].b) {
// Reflect
if (inputs[_reflect].b) {
2016-08-14 21:08:01 +02:00
if (scale > 0) {
2015-11-26 15:36:17 +01:00
f = inputs[_stopTime].f;
}
else {
f = inputs[_startTime].f;
}
2016-08-14 21:08:01 +02:00
scale *= -1;
2015-11-26 15:36:17 +01:00
}
// Reset
else {
f = inputs[_startTime].f;
}
}
// Stop
else {
f = inputs[_stopTime].f;
inputs[_enabled].b = false;
}
}
}
inputChanged();
}
}
public static function create(startTime:Float, stopTime:Float, enabled:Bool, loop:Bool, reflect:Bool) {
var n = new TimeNode();
n.inputs.push(FloatNode.create(startTime));
n.inputs.push(FloatNode.create(stopTime));
n.inputs.push(BoolNode.create(enabled));
n.inputs.push(BoolNode.create(loop));
n.inputs.push(BoolNode.create(reflect));
return n;
}
}