Files
LNXSDK/leenkx/Sources/leenkx/logicnode/JSEventTargetNode.hx
2025-01-22 16:18:30 +01:00

72 lines
1.9 KiB
Haxe

package leenkx.logicnode;
class JSEventTargetNode extends LogicNode {
public var property0: String;
public var property1: String;
public function new(tree:LogicTree) {
super(tree);
}
override function run(from:Int) {
#if js
var object: Dynamic = inputs[1].get();
if (object == null){ return; }
if (property0 == "dispatchEvent"){
var event: Dynamic = inputs[2].get();
object.dispatchEvent(event);
} else {
var type: String = inputs[2].get();
if(property0 == "addEventListener"){
var type: String = inputs[2].get();
switch (property1) {
case "inline":
trace("Running inline...");
var inl: String = inputs[3].get();
if(inputs[4].get() != null){
object.addEventListener(type,function(){
js.Syntax.code('(1, eval)({0})', inl.toString());
},inputs[4].get(), inputs[5].get());
} else {
object.addEventListener(type,function(){
js.Syntax.code('(1, eval)({0})', inl.toString());
},inputs[5].get());
}
runOutput(0);
case "output":
object.addEventListener(type,bindOutput);
default:
var fnc: Dynamic = inputs[3].get();
if (fnc == null){ return; }
if(inputs[4].get() != null){
object.addEventListener(type, fnc, inputs[4].get(), inputs[5].get());
runOutput(0);
} else {
object.addEventListener(type, fnc, inputs[5].get());
runOutput(0);
}
}
} else {
var fnc: Dynamic = inputs[3].get();
if(fnc != null){
object.removeEventListener(type, fnc);
runOutput(0);
}
}
}
#end
}
function bindOutput() {
runOutput(0);
}
}