1. Modification of CanvasScript and WasmScript classes: added a field to save the name of the script / file in the class. 2. Added logical nodes for working with Traits. - Get Object Traits - gets an array of Traits for the specified object; - Get Trait Name - get the Trait name (the name that appears in the list in Armory Traits) and its type (Canvas, Wasm, Bundle, LogicNode or Haxe).
45 lines
1.2 KiB
Haxe
45 lines
1.2 KiB
Haxe
package armory.logicnode;
|
|
|
|
import iron.Trait;
|
|
|
|
class GetTraitNameNode extends LogicNode {
|
|
|
|
public function new(tree: LogicTree) {
|
|
super(tree);
|
|
}
|
|
|
|
override function get(from: Int): Dynamic {
|
|
var trait: Dynamic = inputs[0].get();
|
|
if (trait == null) return null;
|
|
switch (from) {
|
|
// Name
|
|
case 0: {
|
|
// Check CanvasScript
|
|
var cname = cast Type.resolveClass("armory.trait.internal.CanvasScript");
|
|
if (Std.is(trait, cname)) {
|
|
return trait.cnvName;
|
|
}
|
|
// Check WasmScript
|
|
var cname = cast Type.resolveClass("armory.trait.internal.WasmScript");
|
|
if (Std.is(trait, cname)) {
|
|
return trait.wasmName;
|
|
}
|
|
// Other
|
|
var res_arr = (Type.getClassName(Type.getClass(trait))).split(".");
|
|
return res_arr[res_arr.length - 1];
|
|
}
|
|
// Class Type
|
|
case 1: {
|
|
var cname = Type.getClassName(Type.getClass(trait));
|
|
if (cname.indexOf("CanvasScript") > -1) return "Canvas";
|
|
if (cname.indexOf("WasmScript") > -1) return "Wasm";
|
|
if (cname.indexOf("armory.trait.") > -1) return "Bundle";
|
|
if (cname.indexOf("arm.node.") > -1) return "LogicNode";
|
|
if (cname.indexOf("Trait") > -1) return "Haxe";
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|