]>
git.r.bdr.sh - rbdr/serpentity/blob - bin/test
222a65316d32f3595010628182efb8c619d1ff4c
9 console
.log("\n## Loading".bold
.black
)
10 console
.log("Serpentity: " + (typeof Serpentity
!== "undefined" ? "LOAD OK".green : "FAIL".red
));
11 console
.log("Serpentity.Entity: " + (typeof Serpentity
!== "undefined" && Serpentity
.Entity
? "LOAD OK".green : "FAIL".red
));
12 console
.log("Serpentity.Component: " + (typeof Serpentity
!== "undefined" && Serpentity
.Component
? "LOAD OK".green : "FAIL".red
));
13 console
.log("Serpentity.System: " + (typeof Serpentity
!== "undefined" && Serpentity
.System
? "LOAD OK".green : "FAIL".red
));
14 console
.log("Serpentity.Node: " + (typeof Serpentity
!== "undefined" && Serpentity
.Node
? "LOAD OK".green : "FAIL".red
));
15 console
.log("Serpentity.NodeCollection: " + (typeof Serpentity
!== "undefined" && Serpentity
.NodeCollection
? "LOAD OK".green : "FAIL".red
));
17 //////////////////////
18 // Create test classes
19 //////////////////////
20 console
.log("\n## Creating Test Classes".bold
.black
);
21 Class("TestSystem").inherits(Serpentity
.System
)({
23 added : function added(engine
) {
24 this.testNodes
= engine
.getNodes(TestNode
);
25 console
.log("System added callback: " + "EXEC OK".green
);
28 removed : function removed(engine
) {
29 this.testNodes
= null;
30 console
.log("System removed callback: " + "EXEC OK".green
);
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
));
37 console
.log("System update callback: " + "EXEC OK".green
);
41 var testSystem
= new TestSystem();
43 Class("LowProTestSystem").inherits(Serpentity
.System
)({
45 added : function added(engine
) {
46 this.testNodes
= engine
.getNodes(TestNode
);
47 console
.log("System added callback: " + "EXEC OK".green
);
50 removed : function removed(engine
) {
51 this.testNodes
= null;
52 console
.log("System removed callback: " + "EXEC OK".green
);
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
));
59 console
.log("System update callback: " + "EXEC OK".green
);
63 var lowProTestSystem
= new LowProTestSystem();
64 console
.log("LowProTestSystem: " + "CREATE OK".green
)
66 Class("MidProTestSystem").inherits(Serpentity
.System
)({
68 added : function added(engine
) {
69 this.testNodes
= engine
.getNodes(TestNode
);
70 console
.log("System added callback: " + "EXEC OK".green
);
73 removed : function removed(engine
) {
74 this.testNodes
= null;
75 console
.log("System removed callback: " + "EXEC OK".green
);
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
));
82 console
.log("System update callback: " + "EXEC OK".green
);
86 var midProTestSystem
= new MidProTestSystem();
87 console
.log("MidProTestSystem: " + "CREATE OK".green
)
90 Class("TestComponent").inherits(Serpentity
.Component
)({
95 console
.log("TestComponent: " + "CREATE OK".green
)
97 Class("TestNode").inherits(Serpentity
.Node
)({
102 console
.log("TestNode: " + "CREATE OK".green
)
105 console
.log("\n## Adding system to the engine".bold
.black
)
107 var engine
= new Serpentity();
108 console
.log("engine: " + "CREATE OK".green
)
110 engine
.addSystem(testSystem
, 0);
112 console
.log("\n## Running update without any entities".bold
.black
)
115 console
.log("\n## Adding system to the engine and updating".bold
.black
)
116 var entity
= new Serpentity
.Entity();
117 entity
.add(new TestComponent());
118 engine
.addEntity(entity
);
121 console
.log("\n## Adding Low Priority System".bold
.black
)
122 engine
.addSystem(lowProTestSystem
, 10);
125 console
.log("\n## Adding Mid Priority System".bold
.black
)
126 engine
.addSystem(midProTestSystem
, 5);
129 console
.log("\n## Removing the system and readding".bold
.black
)
130 engine
.removeSystem(testSystem
);
132 engine
.addSystem(testSystem
, 0);
135 console
.log("\n## Adding a second entity".bold
.black
)
136 var entity
= new Serpentity
.Entity();
137 entity
.add(new TestComponent());
138 engine
.addEntity(entity
);
141 console
.log("\n## Removing entity".bold
.black
)
142 engine
.removeEntity(entity
)
145 console
.log("\n## Removing system".bold
.black
)
146 engine
.removeSystem(testSystem
)