Added onLoad() lifecycle function
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
import node;
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChild(parent: opaque, fname: string) {
|
||||
//looks like a polyfill
|
||||
fn loadChild(parent: opaque, fname: string) {
|
||||
var child: opaque = loadNode(fname);
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
return child;
|
||||
}
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
fn onLoad(node: opaque) {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
node.makeChild("scripts:/tilemap/tile.toy");
|
||||
node.loadChild("scripts:/empty.toy");
|
||||
}
|
||||
|
||||
node.freeChildNode(10);
|
||||
var n = node.getChildNode(10);
|
||||
|
||||
for (var i = 0; i < 20; i++) {
|
||||
//this would originally prune tombstones...
|
||||
node.makeChild("scripts:/tilemap/tile.toy");
|
||||
node.loadChild("scripts:/empty.toy");
|
||||
}
|
||||
|
||||
print node.getChildNodeCount();
|
||||
|
||||
1
assets/scripts/empty.toy
Normal file
1
assets/scripts/empty.toy
Normal file
@@ -0,0 +1 @@
|
||||
//this file is a polyfill
|
||||
@@ -1,17 +1,20 @@
|
||||
//the overarching scene
|
||||
import node;
|
||||
|
||||
//debugging tools
|
||||
var stepCounter: int = 0;
|
||||
var stepTracker: [int] = [0, 0, 0];
|
||||
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChild(parent: opaque, fname: string) {
|
||||
var child: opaque = loadNode(fname);
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
//lifecycle functions
|
||||
fn onLoad(node: opaque) {
|
||||
//load the tile map node
|
||||
var tilemapNode = node.makeChild("scripts:/tilemap/tilemap.toy");
|
||||
|
||||
@@ -22,6 +25,22 @@ fn onInit(node: opaque) {
|
||||
//tilemapNode.callNodeFn("loadLayer", "layer-maze.toy");
|
||||
}
|
||||
|
||||
//debugging code
|
||||
fn onStep(node: opaque) {
|
||||
stepCounter++;
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
//round off - too many skips means it's crappy anyway
|
||||
if (stepCounter > stepTracker.length() - 1) {
|
||||
stepCounter = stepTracker.length() - 1;
|
||||
}
|
||||
|
||||
//This logic is just a debugging tool
|
||||
stepTracker[stepCounter] = stepTracker[stepCounter] + 1;
|
||||
print stepTracker;
|
||||
stepCounter = 0;
|
||||
}
|
||||
|
||||
//global accessors
|
||||
fn getTileWidth(node: opaque): int { return 64; }
|
||||
|
||||
@@ -4,24 +4,25 @@ import engine;
|
||||
import node;
|
||||
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChildSprite(parent: opaque, spriteName: string) {
|
||||
var child: opaque = loadNode("scripts:/tilemap/tile.toy");
|
||||
//TODO: replace with an empty node function (polyfill)
|
||||
fn loadChildEmpty(parent: opaque) {
|
||||
var child: opaque = loadNode("scripts:/empty.toy");
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
|
||||
child.loadTexture("sprites:/" + spriteName);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
fn onLoad(node: opaque) {
|
||||
//load the child node, with the tiling back image
|
||||
node.makeChildSprite("tile-background.png");
|
||||
node.loadChildEmpty();
|
||||
}
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
node.getChildNode(0).loadTexture("sprites:/tile-background.png");
|
||||
}
|
||||
|
||||
|
||||
//drawing util
|
||||
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
//get the constants from root
|
||||
var root: opaque = getRootNode();
|
||||
|
||||
@@ -4,24 +4,25 @@ import engine;
|
||||
import node;
|
||||
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChildSprite(parent: opaque, spriteName: string) {
|
||||
var child: opaque = loadNode("scripts:/tilemap/tile.toy");
|
||||
//TODO: replace with an empty node function (polyfill)
|
||||
fn loadChildEmpty(parent: opaque) {
|
||||
var child: opaque = loadNode("scripts:/empty.toy");
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
|
||||
child.loadTexture("sprites:/" + spriteName);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
fn onLoad(node: opaque) {
|
||||
//load the child node, with the tiling back image
|
||||
node.makeChildSprite("tile-wall.png");
|
||||
node.loadChildEmpty();
|
||||
}
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
node.getChildNode(0).loadTexture("sprites:/tile-wall.png");
|
||||
}
|
||||
|
||||
|
||||
//drawing util
|
||||
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
//get the constants from root
|
||||
var root: opaque = getRootNode();
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
//EMPTY
|
||||
|
||||
@@ -6,44 +6,25 @@ import node;
|
||||
var camX: float = 0;
|
||||
var camY: float = 0;
|
||||
|
||||
var stepCounter: int = 0;
|
||||
var stepTracker: [int] = [0, 0, 0, 0, 0, 0];
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChild(parent: opaque, fname: string) {
|
||||
//util to generate a child node of a given parent
|
||||
fn loadChild(parent: opaque, fname: string) {
|
||||
var child: opaque = loadNode(fname);
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
return child;
|
||||
}
|
||||
|
||||
fn loadLayer(node: opaque, layerName: string) {
|
||||
//load the given layer as a child
|
||||
var layerNode = node.makeChild("scripts:/tilemap/" + layerName);
|
||||
var layerNode = node.loadChild("scripts:/tilemap/" + layerName);
|
||||
}
|
||||
|
||||
//lifecycle functions
|
||||
fn onStep(node: opaque) {
|
||||
stepCounter++;
|
||||
|
||||
camX--;
|
||||
camY--;
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
var tmp = stepCounter;
|
||||
print stepCounter;
|
||||
stepCounter = 0;
|
||||
|
||||
if (tmp > 5) {
|
||||
tmp = 5;
|
||||
}
|
||||
|
||||
print typeof (stepTracker[tmp] + 1);
|
||||
|
||||
//TODO: index[]++
|
||||
stepTracker[tmp] = stepTracker[tmp] + 1;
|
||||
print stepTracker;
|
||||
|
||||
var screenWidth: int const = getRootNode().callNodeFn("getScreenWidth");
|
||||
var screenHeight: int const = getRootNode().callNodeFn("getScreenHeight");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user