Fixed audio options not working
This commit is contained in:
parent
347b465bb8
commit
8d83c8371a
|
@ -29,8 +29,11 @@ module TK.SpaceTac {
|
||||||
session: GameSession
|
session: GameSession
|
||||||
session_token: string | null
|
session_token: string | null
|
||||||
|
|
||||||
|
// Audio manager
|
||||||
|
audio = new UI.Audio(this)
|
||||||
|
|
||||||
// Game options
|
// Game options
|
||||||
options!: UI.GameOptions
|
options = new UI.GameOptions(this)
|
||||||
|
|
||||||
// Storage used
|
// Storage used
|
||||||
storage: Storage
|
storage: Storage
|
||||||
|
@ -81,42 +84,10 @@ module TK.SpaceTac {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boot() {
|
|
||||||
super.boot();
|
|
||||||
this.options = new UI.GameOptions(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isTesting(): boolean {
|
get isTesting(): boolean {
|
||||||
return this.testmode;
|
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
|
* Reset the game session
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,10 +5,12 @@ module TK.SpaceTac.UI.Specs {
|
||||||
let testgame = setupEmptyView(test);
|
let testgame = setupEmptyView(test);
|
||||||
|
|
||||||
test.case("initializes variables", check => {
|
test.case("initializes variables", check => {
|
||||||
let view = nn(testgame.ui.getActiveScene());
|
let view = testgame.view;
|
||||||
|
|
||||||
check.equals(view.messages instanceof Messages, true);
|
check.instance(view, BaseView, "view should be a BaseView");
|
||||||
check.equals(view.inputs instanceof InputManager, true);
|
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.getWidth(), 1920);
|
||||||
check.equals(view.getHeight(), 1080);
|
check.equals(view.getHeight(), 1080);
|
||||||
|
|
|
@ -59,7 +59,7 @@ module TK.SpaceTac.UI {
|
||||||
this.animations = new Animations(this.tweens);
|
this.animations = new Animations(this.tweens);
|
||||||
this.particles = new UIParticles(this);
|
this.particles = new UIParticles(this);
|
||||||
this.inputs = new InputManager(this);
|
this.inputs = new InputManager(this);
|
||||||
this.audio = new Audio(this);
|
this.audio = this.gameui.audio;
|
||||||
this.debug = this.gameui.debug;
|
this.debug = this.gameui.debug;
|
||||||
|
|
||||||
this.input.setDefaultCursor("url(cursors/standard.cur), pointer");
|
this.input.setDefaultCursor("url(cursors/standard.cur), pointer");
|
||||||
|
|
|
@ -6,7 +6,7 @@ module TK.SpaceTac.UI.Specs {
|
||||||
let testgame = setupSingleView(test, () => [new Router({}), {}]);
|
let testgame = setupSingleView(test, () => [new Router({}), {}]);
|
||||||
|
|
||||||
test.case("loads correctly", check => {
|
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
|
// TODO test routing
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,29 +8,25 @@ module TK.SpaceTac.UI {
|
||||||
* Utility functions to play sounds and musics
|
* Utility functions to play sounds and musics
|
||||||
*/
|
*/
|
||||||
export class Audio {
|
export class Audio {
|
||||||
private static SETTINGS = new AudioSettings();
|
private static SETTINGS = new AudioSettings()
|
||||||
private music: Phaser.Sound.BaseSound | undefined
|
private music: Phaser.Sound.BaseSound | undefined
|
||||||
private music_playing_volume = 1
|
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
|
* Check if the sound system is active, and return a manager to operate with it
|
||||||
*/
|
*/
|
||||||
private getManager(): Phaser.Sound.BaseSoundManager | null {
|
private getManager(): Phaser.Sound.BaseSoundManager | null {
|
||||||
if (this.view) {
|
return this.game.sound;
|
||||||
return this.view.sound;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an audio key is present in cache
|
* Check if an audio key is present in cache
|
||||||
*/
|
*/
|
||||||
hasCache(key: string): boolean {
|
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;
|
let music = this.music;
|
||||||
if (music) {
|
if (music) {
|
||||||
// TODO Set music volume
|
// TODO Set music volume
|
||||||
if (value) {
|
if (Audio.SETTINGS.music_volume) {
|
||||||
music.resume();
|
music.resume();
|
||||||
} else {
|
} else {
|
||||||
music.pause();
|
music.pause();
|
||||||
|
|
Loading…
Reference in New Issue