aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2014-08-11 01:35:17 -0500
committerBen Beltran <ben@nsovocal.com>2014-08-11 01:35:17 -0500
commit85861d6720c30adc4afd1e041fd7e27fb596dde7 (patch)
tree1df8c4e6774f0555c2be0e57498b08d183ff7df5 /bin
Serpentity initial commit
Diffstat (limited to 'bin')
-rwxr-xr-xbin/test94
1 files changed, 94 insertions, 0 deletions
diff --git a/bin/test b/bin/test
new file mode 100755
index 0000000..55e0aa2
--- /dev/null
+++ b/bin/test
@@ -0,0 +1,94 @@
+#!/usr/bin/env node
+
+require("colors");
+require("serpentity");
+
+/////////////////
+// Load the stuff
+/////////////////
+console.log("\n## Loading".bold.black)
+console.log("Serpentity: " + (typeof Serpentity !== "undefined" ? "LOAD OK".green : "FAIL".red));
+console.log("Serpentity.Entity: " + (typeof Serpentity !== "undefined" && Serpentity.Entity ? "LOAD OK".green : "FAIL".red));
+console.log("Serpentity.Component: " + (typeof Serpentity !== "undefined" && Serpentity.Component ? "LOAD OK".green : "FAIL".red));
+console.log("Serpentity.System: " + (typeof Serpentity !== "undefined" && Serpentity.System ? "LOAD OK".green : "FAIL".red));
+console.log("Serpentity.Node: " + (typeof Serpentity !== "undefined" && Serpentity.Node ? "LOAD OK".green : "FAIL".red));
+console.log("Serpentity.NodeCollection: " + (typeof Serpentity !== "undefined" && Serpentity.NodeCollection ? "LOAD OK".green : "FAIL".red));
+
+//////////////////////
+// Create test classes
+//////////////////////
+console.log("\n## Creating Test Classes".bold.black);
+Class("TestSystem").inherits(Serpentity.System)({
+ prototype : {
+ added : function added(engine) {
+ this.testNodes = engine.getNodes(TestNode);
+ console.log("System added callback: " + "EXEC OK".green);
+ },
+
+ removed : function removed(engine) {
+ this.testNodes = null;
+ console.log("System removed callback: " + "EXEC OK".green);
+ },
+
+ update : function update(dt) {
+ this.testNodes.forEach(function (node) {
+ console.log("Running Node: " + (node.test.testMessage === "test" ? "SYSTEM OK".green : "FAIL".RED));
+ });
+ console.log("System update callback: " + "EXEC OK".green);
+ }
+ }
+});
+var testSystem = new TestSystem();
+console.log("TestSystem: " + "CREATE OK".green)
+
+
+Class("TestComponent").inherits(Serpentity.Component)({
+ prototype : {
+ testMessage : "test"
+ }
+});
+console.log("TestComponent: " + "CREATE OK".green)
+
+Class("TestNode").inherits(Serpentity.Node)({
+ types : {
+ test : TestComponent
+ }
+});
+console.log("TestNode: " + "CREATE OK".green)
+
+
+console.log("\n## Adding system to the engine".bold.black)
+
+var engine = new Serpentity();
+console.log("engine: " + "CREATE OK".green)
+
+engine.addSystem(testSystem);
+
+console.log("\n## Running update without any entities".bold.black)
+engine.update(10);
+
+console.log("\n## Adding system to the engine and updating".bold.black)
+var entity = new Serpentity.Entity();
+entity.add(new TestComponent());
+engine.addEntity(entity);
+engine.update(10);
+
+console.log("\n## Removing the system and readding".bold.black)
+engine.removeSystem(testSystem);
+engine.update(10);
+engine.addSystem(testSystem);
+engine.update(10);
+
+console.log("\n## Adding a second entity".bold.black)
+var entity = new Serpentity.Entity();
+entity.add(new TestComponent());
+engine.addEntity(entity);
+engine.update(10);
+
+console.log("\n## Removing entity".bold.black)
+engine.removeEntity(entity)
+engine.update(10);
+
+console.log("\n## Removing system".bold.black)
+engine.removeSystem(testSystem)
+engine.update(10);