]> git.r.bdr.sh - rbdr/serpentity/blame_incremental - bin/test
Serpentity initial commit
[rbdr/serpentity] / bin / test
... / ...
CommitLineData
1#!/usr/bin/env node
2
3require("colors");
4require("serpentity");
5
6/////////////////
7// Load the stuff
8/////////////////
9console.log("\n## Loading".bold.black)
10console.log("Serpentity: " + (typeof Serpentity !== "undefined" ? "LOAD OK".green : "FAIL".red));
11console.log("Serpentity.Entity: " + (typeof Serpentity !== "undefined" && Serpentity.Entity ? "LOAD OK".green : "FAIL".red));
12console.log("Serpentity.Component: " + (typeof Serpentity !== "undefined" && Serpentity.Component ? "LOAD OK".green : "FAIL".red));
13console.log("Serpentity.System: " + (typeof Serpentity !== "undefined" && Serpentity.System ? "LOAD OK".green : "FAIL".red));
14console.log("Serpentity.Node: " + (typeof Serpentity !== "undefined" && Serpentity.Node ? "LOAD OK".green : "FAIL".red));
15console.log("Serpentity.NodeCollection: " + (typeof Serpentity !== "undefined" && Serpentity.NodeCollection ? "LOAD OK".green : "FAIL".red));
16
17//////////////////////
18// Create test classes
19//////////////////////
20console.log("\n## Creating Test Classes".bold.black);
21Class("TestSystem").inherits(Serpentity.System)({
22 prototype : {
23 added : function added(engine) {
24 this.testNodes = engine.getNodes(TestNode);
25 console.log("System added callback: " + "EXEC OK".green);
26 },
27
28 removed : function removed(engine) {
29 this.testNodes = null;
30 console.log("System removed callback: " + "EXEC OK".green);
31 },
32
33 update : function update(dt) {
34 this.testNodes.forEach(function (node) {
35 console.log("Running Node: " + (node.test.testMessage === "test" ? "SYSTEM OK".green : "FAIL".RED));
36 });
37 console.log("System update callback: " + "EXEC OK".green);
38 }
39 }
40});
41var testSystem = new TestSystem();
42console.log("TestSystem: " + "CREATE OK".green)
43
44
45Class("TestComponent").inherits(Serpentity.Component)({
46 prototype : {
47 testMessage : "test"
48 }
49});
50console.log("TestComponent: " + "CREATE OK".green)
51
52Class("TestNode").inherits(Serpentity.Node)({
53 types : {
54 test : TestComponent
55 }
56});
57console.log("TestNode: " + "CREATE OK".green)
58
59
60console.log("\n## Adding system to the engine".bold.black)
61
62var engine = new Serpentity();
63console.log("engine: " + "CREATE OK".green)
64
65engine.addSystem(testSystem);
66
67console.log("\n## Running update without any entities".bold.black)
68engine.update(10);
69
70console.log("\n## Adding system to the engine and updating".bold.black)
71var entity = new Serpentity.Entity();
72entity.add(new TestComponent());
73engine.addEntity(entity);
74engine.update(10);
75
76console.log("\n## Removing the system and readding".bold.black)
77engine.removeSystem(testSystem);
78engine.update(10);
79engine.addSystem(testSystem);
80engine.update(10);
81
82console.log("\n## Adding a second entity".bold.black)
83var entity = new Serpentity.Entity();
84entity.add(new TestComponent());
85engine.addEntity(entity);
86engine.update(10);
87
88console.log("\n## Removing entity".bold.black)
89engine.removeEntity(entity)
90engine.update(10);
91
92console.log("\n## Removing system".bold.black)
93engine.removeSystem(testSystem)
94engine.update(10);