]> git.r.bdr.sh - rbdr/serpentity/blame - bin/test
Removes bower.json
[rbdr/serpentity] / bin / test
CommitLineData
85861d67
BB
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();
42c62ebf
BB
42
43Class("LowProTestSystem").inherits(Serpentity.System)({
44 prototype : {
45 added : function added(engine) {
46 this.testNodes = engine.getNodes(TestNode);
47 console.log("System added callback: " + "EXEC OK".green);
48 },
49
50 removed : function removed(engine) {
51 this.testNodes = null;
52 console.log("System removed callback: " + "EXEC OK".green);
53 },
54
55 update : function update(dt) {
56 this.testNodes.forEach(function (node) {
57 console.log("Running Low Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK".green : "FAIL".RED));
58 });
59 console.log("System update callback: " + "EXEC OK".green);
60 }
61 }
62});
63var lowProTestSystem = new LowProTestSystem();
64console.log("LowProTestSystem: " + "CREATE OK".green)
65
66Class("MidProTestSystem").inherits(Serpentity.System)({
67 prototype : {
68 added : function added(engine) {
69 this.testNodes = engine.getNodes(TestNode);
70 console.log("System added callback: " + "EXEC OK".green);
71 },
72
73 removed : function removed(engine) {
74 this.testNodes = null;
75 console.log("System removed callback: " + "EXEC OK".green);
76 },
77
78 update : function update(dt) {
79 this.testNodes.forEach(function (node) {
80 console.log("Running Mid Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK".green : "FAIL".RED));
81 });
82 console.log("System update callback: " + "EXEC OK".green);
83 }
84 }
85});
86var midProTestSystem = new MidProTestSystem();
87console.log("MidProTestSystem: " + "CREATE OK".green)
85861d67
BB
88
89
90Class("TestComponent").inherits(Serpentity.Component)({
91 prototype : {
92 testMessage : "test"
93 }
94});
95console.log("TestComponent: " + "CREATE OK".green)
96
97Class("TestNode").inherits(Serpentity.Node)({
98 types : {
99 test : TestComponent
100 }
101});
102console.log("TestNode: " + "CREATE OK".green)
103
104
105console.log("\n## Adding system to the engine".bold.black)
106
107var engine = new Serpentity();
108console.log("engine: " + "CREATE OK".green)
109
42c62ebf 110engine.addSystem(testSystem, 0);
85861d67
BB
111
112console.log("\n## Running update without any entities".bold.black)
113engine.update(10);
114
115console.log("\n## Adding system to the engine and updating".bold.black)
116var entity = new Serpentity.Entity();
509e372f 117entity.addComponent(new TestComponent());
85861d67
BB
118engine.addEntity(entity);
119engine.update(10);
120
42c62ebf
BB
121console.log("\n## Adding Low Priority System".bold.black)
122engine.addSystem(lowProTestSystem, 10);
123engine.update(10);
124
125console.log("\n## Adding Mid Priority System".bold.black)
126engine.addSystem(midProTestSystem, 5);
127engine.update(10);
128
85861d67
BB
129console.log("\n## Removing the system and readding".bold.black)
130engine.removeSystem(testSystem);
131engine.update(10);
42c62ebf 132engine.addSystem(testSystem, 0);
85861d67
BB
133engine.update(10);
134
135console.log("\n## Adding a second entity".bold.black)
136var entity = new Serpentity.Entity();
509e372f 137entity.addComponent(new TestComponent());
85861d67
BB
138engine.addEntity(entity);
139engine.update(10);
140
141console.log("\n## Removing entity".bold.black)
142engine.removeEntity(entity)
143engine.update(10);
144
145console.log("\n## Removing system".bold.black)
146engine.removeSystem(testSystem)
147engine.update(10);