]> git.r.bdr.sh - rbdr/serpentity/blob - browser_test/index.html
Prepare it for the browser
[rbdr/serpentity] / browser_test / index.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Serpentity Browser Test</title>
5 <script src="/node_modules/neon/neon.js"></script>
6 <script src="/lib/serpentity/serpentity.js"></script>
7 <script src="/lib/serpentity/entity.js"></script>
8 <script src="/lib/serpentity/node.js"></script>
9 <script src="/lib/serpentity/node_collection.js"></script>
10 <script src="/lib/serpentity/component.js"></script>
11 <script src="/lib/serpentity/system.js"></script>
12 <script type="application/javascript">
13 /////////////////
14 // Load the stuff
15 /////////////////
16 console.log("\n## Loading")
17 console.log("Serpentity: " + (typeof Serpentity !== "undefined" ? "LOAD OK" : "FAIL"));
18 console.log("Serpentity.Entity: " + (typeof Serpentity !== "undefined" && Serpentity.Entity ? "LOAD OK" : "FAIL"));
19 console.log("Serpentity.Component: " + (typeof Serpentity !== "undefined" && Serpentity.Component ? "LOAD OK" : "FAIL"));
20 console.log("Serpentity.System: " + (typeof Serpentity !== "undefined" && Serpentity.System ? "LOAD OK" : "FAIL"));
21 console.log("Serpentity.Node: " + (typeof Serpentity !== "undefined" && Serpentity.Node ? "LOAD OK" : "FAIL"));
22 console.log("Serpentity.NodeCollection: " + (typeof Serpentity !== "undefined" && Serpentity.NodeCollection ? "LOAD OK" : "FAIL"));
23
24 //////////////////////
25 // Create test classes
26 //////////////////////
27 console.log("\n## Creating Test Classes");
28 Class("TestSystem").inherits(Serpentity.System)({
29 prototype : {
30 added : function added(engine) {
31 this.testNodes = engine.getNodes(TestNode);
32 console.log("System added callback: " + "EXEC OK");
33 },
34
35 removed : function removed(engine) {
36 this.testNodes = null;
37 console.log("System removed callback: " + "EXEC OK");
38 },
39
40 update : function update(dt) {
41 this.testNodes.forEach(function (node) {
42 console.log("Running Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
43 });
44 console.log("System update callback: " + "EXEC OK");
45 }
46 }
47 });
48 var testSystem = new TestSystem();
49
50 Class("LowProTestSystem").inherits(Serpentity.System)({
51 prototype : {
52 added : function added(engine) {
53 this.testNodes = engine.getNodes(TestNode);
54 console.log("System added callback: " + "EXEC OK");
55 },
56
57 removed : function removed(engine) {
58 this.testNodes = null;
59 console.log("System removed callback: " + "EXEC OK");
60 },
61
62 update : function update(dt) {
63 this.testNodes.forEach(function (node) {
64 console.log("Running Low Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
65 });
66 console.log("System update callback: " + "EXEC OK");
67 }
68 }
69 });
70 var lowProTestSystem = new LowProTestSystem();
71 console.log("LowProTestSystem: " + "CREATE OK")
72
73 Class("MidProTestSystem").inherits(Serpentity.System)({
74 prototype : {
75 added : function added(engine) {
76 this.testNodes = engine.getNodes(TestNode);
77 console.log("System added callback: " + "EXEC OK");
78 },
79
80 removed : function removed(engine) {
81 this.testNodes = null;
82 console.log("System removed callback: " + "EXEC OK");
83 },
84
85 update : function update(dt) {
86 this.testNodes.forEach(function (node) {
87 console.log("Running Mid Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
88 });
89 console.log("System update callback: " + "EXEC OK");
90 }
91 }
92 });
93 var midProTestSystem = new MidProTestSystem();
94 console.log("MidProTestSystem: " + "CREATE OK")
95
96
97 Class("TestComponent").inherits(Serpentity.Component)({
98 prototype : {
99 testMessage : "test"
100 }
101 });
102 console.log("TestComponent: " + "CREATE OK")
103
104 Class("TestNode").inherits(Serpentity.Node)({
105 types : {
106 test : TestComponent
107 }
108 });
109 console.log("TestNode: " + "CREATE OK")
110
111
112 console.log("\n## Adding system to the engine")
113
114 var engine = new Serpentity();
115 console.log("engine: " + "CREATE OK")
116
117 engine.addSystem(testSystem, 0);
118
119 console.log("\n## Running update without any entities")
120 engine.update(10);
121
122 console.log("\n## Adding system to the engine and updating")
123 var entity = new Serpentity.Entity();
124 entity.add(new TestComponent());
125 engine.addEntity(entity);
126 engine.update(10);
127
128 console.log("\n## Adding Low Priority System")
129 engine.addSystem(lowProTestSystem, 10);
130 engine.update(10);
131
132 console.log("\n## Adding Mid Priority System")
133 engine.addSystem(midProTestSystem, 5);
134 engine.update(10);
135
136 console.log("\n## Removing the system and readding")
137 engine.removeSystem(testSystem);
138 engine.update(10);
139 engine.addSystem(testSystem, 0);
140 engine.update(10);
141
142 console.log("\n## Adding a second entity")
143 var entity = new Serpentity.Entity();
144 entity.add(new TestComponent());
145 engine.addEntity(entity);
146 engine.update(10);
147
148 console.log("\n## Removing entity")
149 engine.removeEntity(entity)
150 engine.update(10);
151
152 console.log("\n## Removing system")
153 engine.removeSystem(testSystem)
154 engine.update(10);
155 </script>
156 </head>
157 <body>
158 <h1>404 Droids Not Found</h1>
159 Look in your console...
160 </body>
161 </html>