-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameManager.mjs
50 lines (40 loc) · 1.07 KB
/
gameManager.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict'
import * as constants from '/game/constants'
import _ from '/user/lodash-es/lodash'
import Arena from '/user/arena'
import Stats from '/user/stats'
import TickCache from '/user/utils/tickCache'
import Sandbox from '/user/utils/sandbox'
class GameManager {
constructor() {
for (const globalKey in constants) {
global[globalKey] = constants[globalKey]
}
global._ = _
this.components = [
TickCache,
Arena,
Arena.strategy,
Stats,
Sandbox,
]
}
get isFirstTick() {
return Arena.time === 1
}
loop() {
if (this.isFirstTick) {
for (const component of this.components) {
if (typeof component.start === 'function') {
component.start()
}
}
}
for (const component of this.components) {
if (typeof component.update === 'function') {
component.update()
}
}
}
}
export default (new GameManager())