Fixed audio options not working
This commit is contained in:
parent
347b465bb8
commit
8d83c8371a
|
@ -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(<string[]>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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue