-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.ts
96 lines (80 loc) · 3.01 KB
/
Main.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { GameStore } from "./store/GameStore"
import { GameTexts } from "./texts/GameTexts"
import { GameAnalyticsWrapper } from "./GameAnalyticsWrapper"
import { ToastsManager } from "./robowhale/phaser3/gameObjects/toast/ToastsManager"
import { SentryWrapper } from "./SentryWrapper"
import { Polyfills } from "./robowhale/Polyfills"
import { Phaser3Extensions } from "./robowhale/phaser3/Phaser3Extensions"
import { AudioType, createGameConfig, RendererType } from "./create-game-config"
import { SceneKey } from "./scenes/SceneKey"
import { GlobalScene } from "./scenes/global/GlobalScene"
import { Boot } from "./scenes/Boot"
import { Preloader } from "./scenes/preloader/Preloader"
import { HowlerWrapper } from "./audio/HowlerWrapper"
import { LoadingOverlay } from "./LoadingOverlay"
import { Howler } from "howler"
import { NineSliceEditor } from "./scenes/nineSliceEditor/NineSliceEditor"
import { GameStash } from "./stash/GameStash"
import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer
import { NotificationsManager } from "./NotificationsManager"
export class Main extends Phaser.Game {
public rendererType: RendererType
public audioType: AudioType
public audio: HowlerWrapper
public sentry: SentryWrapper
public texts: GameTexts
public store: GameStore
public globalScene: GlobalScene
public analytics: GameAnalyticsWrapper
public toasts: ToastsManager
constructor() {
Polyfills.polyfill()
Phaser3Extensions.extend()
super(createGameConfig())
this.webp = false
this.avif = false
this.audioType = this.getAudioType(Howler)
this.rendererType = this.getRendererType()
this.stash = new GameStash()
this.loadingScreen = new LoadingOverlay(this)
this.audio = new HowlerWrapper(this, { muteTrigger: "hidden" })
this.notifications = new NotificationsManager()
this.addScenes()
}
private getAudioType(howler: Howler): AudioType {
if (howler.noAudio) {
return AudioType.NO_AUDIO
}
return howler.usingWebAudio
? AudioType.WEB_AUDIO
: AudioType.HTML5_AUDIO
}
private getRendererType(): RendererType {
if (this.renderer instanceof WebGLRenderer) {
return RendererType.WEBGL
}
return RendererType.CANVAS
}
private addScenes() {
this.scene.add(SceneKey.GLOBAL, GlobalScene)
this.scene.add(SceneKey.BOOT, Boot, true)
this.scene.add(SceneKey.PRELOADER, Preloader)
this.scene.add(SceneKey.NINE_SLICE_EDITOR, NineSliceEditor)
}
public changeScene(currentSceneKey: SceneKey, newSceneKey: SceneKey, newSceneData?: object): void {
this.globalScene.sceneTransition.changeScene(currentSceneKey, newSceneKey, newSceneData)
}
public restartScene(currentScene: SceneKey, data?: object): void {
this.globalScene.sceneTransition.changeScene(currentScene, currentScene, data)
}
public injectIntoScenes(obj: any, key: string): void {
this.scene.scenes.forEach((scene) => {
let isKeyTaken: boolean = scene.hasOwnProperty(key)
if (isKeyTaken) {
console.warn(`Key ${key} is taken in ${scene.scene.key} scene!`)
return
}
scene[key] = obj
})
}
}