Implemented node child sorting

This commit is contained in:
2023-06-15 03:10:30 +10:00
parent bfb985a08e
commit 1172ad50b4
11 changed files with 235 additions and 31 deletions

View File

@@ -0,0 +1,34 @@
import node;
//generate a number of child nodes
fn onInit(node: opaque) {
node.loadChild("scripts:/empty.toy", 3);
node.loadChild("scripts:/empty.toy", 2);
node.loadChild("scripts:/empty.toy", 1);
node.loadChild("scripts:/empty.toy", 4);
node.loadChild("scripts:/empty.toy", 5);
node.freeChildNode(3);
}
fn onStep(node) {
node.sortChildrenNode(lessThan);
}
fn lessThan(lhs, rhs) {
var a = lhs.callNodeFn("getValue");
var b = rhs.callNodeFn("getValue");
return a < b;
}
//utils - polyfills
fn loadChild(parent: opaque, fname: string, value) {
var child: opaque = loadNode(fname);
child.callNodeFn("setValue", value);
parent.pushNode(child);
return child;
}