//this file manages the tilemap-related utilities
import standard;
import engine;
import node;

var camX: float = 0;
var camY: float = 0;

//util to generate a child node of a given parent
fn loadChild(parent: opaque, fname: string) {
	var child: opaque = loadNode(fname);
	parent.pushNode(child);
	return child;
}

fn loadLayer(node: opaque, layerName: string) {
	//load the given layer as a child
	var layerNode = node.loadChild("scripts:/demo/tilemap/" + layerName);
}

//lifecycle functions
fn onStep(node: opaque) {
	camX--;
	camY--;
}

fn onDraw(node: opaque) {
	var screenWidth: int const = getRootNode().callNodeFn("getScreenWidth");
	var screenHeight: int const = getRootNode().callNodeFn("getScreenHeight");

	//iterate over each layer, passing in the screen dimensions
	for (var c = 0; c < node.getChildNodeCount(); c++) {
		node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 4.0);
	}
}
