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