diff --git a/src/MainUI.ts b/src/MainUI.ts index e06fb82..cbf86c8 100644 --- a/src/MainUI.ts +++ b/src/MainUI.ts @@ -29,8 +29,11 @@ module TK.SpaceTac { session: GameSession session_token: string | null + // Audio manager + audio = new UI.Audio(this) + // Game options - options!: UI.GameOptions + options = new UI.GameOptions(this) // Storage used storage: Storage @@ -81,42 +84,10 @@ module TK.SpaceTac { } } - boot() { - super.boot(); - this.options = new UI.GameOptions(this); - } - get isTesting(): boolean { return this.testmode; } - /** - * Get the audio manager for current scene - */ - get audio(): UI.Audio { - let scene = this.getActiveScene(); - if (scene) { - return scene.audio; - } else { - return new UI.Audio(null); - } - } - - /** - * Get the currently active scene - */ - getActiveScene(): UI.BaseView | null { - let active = first(keys(this.scene.scenes), key => this.scene.isActive(key)); - if (active) { - let scene = this.scene.getScene(active); - return (scene instanceof UI.BaseView) ? scene : null; - } else if (this.isTesting) { - return this.scene.scenes[0]; - } else { - return null; - } - } - /** * Reset the game session */ diff --git a/src/ui/BaseView.spec.ts b/src/ui/BaseView.spec.ts index 5c24ae5..1ee1718 100644 --- a/src/ui/BaseView.spec.ts +++ b/src/ui/BaseView.spec.ts @@ -5,10 +5,12 @@ module TK.SpaceTac.UI.Specs { let testgame = setupEmptyView(test); test.case("initializes variables", check => { - let view = nn(testgame.ui.getActiveScene()); + let view = testgame.view; - check.equals(view.messages instanceof Messages, true); - check.equals(view.inputs instanceof InputManager, true); + check.instance(view, BaseView, "view should be a BaseView"); + check.instance(view.messages, Messages, "view.messages should be a Messages"); + check.instance(view.inputs, InputManager, "view.inputs should be a InputManager"); + check.instance(view.audio, Audio, "view.audio should be an Audio"); check.equals(view.getWidth(), 1920); check.equals(view.getHeight(), 1080); diff --git a/src/ui/BaseView.ts b/src/ui/BaseView.ts index 82090c4..b93cb8c 100644 --- a/src/ui/BaseView.ts +++ b/src/ui/BaseView.ts @@ -59,7 +59,7 @@ module TK.SpaceTac.UI { this.animations = new Animations(this.tweens); this.particles = new UIParticles(this); this.inputs = new InputManager(this); - this.audio = new Audio(this); + this.audio = this.gameui.audio; this.debug = this.gameui.debug; this.input.setDefaultCursor("url(cursors/standard.cur), pointer"); diff --git a/src/ui/Router.spec.ts b/src/ui/Router.spec.ts index 20b02cd..ddb8d10 100644 --- a/src/ui/Router.spec.ts +++ b/src/ui/Router.spec.ts @@ -6,7 +6,7 @@ module TK.SpaceTac.UI.Specs { let testgame = setupSingleView(test, () => [new Router({}), {}]); test.case("loads correctly", check => { - check.instance(testgame.ui.getActiveScene(), Router, "active scene should be Router"); + check.instance(testgame.ui.scene.scenes[0], Router, "active scene should be Router"); // TODO test routing }); }); diff --git a/src/ui/common/Audio.ts b/src/ui/common/Audio.ts index b7a993a..ef40d4b 100644 --- a/src/ui/common/Audio.ts +++ b/src/ui/common/Audio.ts @@ -8,29 +8,25 @@ module TK.SpaceTac.UI { * Utility functions to play sounds and musics */ export class Audio { - private static SETTINGS = new AudioSettings(); + private static SETTINGS = new AudioSettings() private music: Phaser.Sound.BaseSound | undefined private music_playing_volume = 1 - constructor(private view: BaseView | null) { + constructor(private game: MainUI) { } /** * Check if the sound system is active, and return a manager to operate with it */ private getManager(): Phaser.Sound.BaseSoundManager | null { - if (this.view) { - return this.view.sound; - } else { - return null; - } + return this.game.sound; } /** * Check if an audio key is present in cache */ hasCache(key: string): boolean { - return this.view ? this.view.cache.audio.has(key) : false; + return this.game.cache.audio.has(key); } /** @@ -123,7 +119,7 @@ module TK.SpaceTac.UI { let music = this.music; if (music) { // TODO Set music volume - if (value) { + if (Audio.SETTINGS.music_volume) { music.resume(); } else { music.pause();