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