Refactor platform UI and data flow across core pages
All checks were successful
Build Org Website / build (push) Successful in 50s
All checks were successful
Build Org Website / build (push) Successful in 50s
This commit is contained in:
27
assets/scripts/pages/princess-lima-audio.js
Normal file → Executable file
27
assets/scripts/pages/princess-lima-audio.js
Normal file → Executable file
@@ -11,6 +11,7 @@
|
||||
function create(getState) {
|
||||
let scene = null;
|
||||
let ambience = null;
|
||||
let voice = null;
|
||||
let unlocked = false;
|
||||
|
||||
function attach(nextScene, region) {
|
||||
@@ -33,7 +34,7 @@
|
||||
const enabled = Boolean(unlocked && state && state.settings.soundEnabled);
|
||||
scene.sound.mute = !enabled;
|
||||
if (ambience) {
|
||||
ambience.setVolume((state.settings.master || 0) * (state.settings.music || 0));
|
||||
ambience.setVolume(state ? (state.settings.master || 0) * (state.settings.music || 0) : 0);
|
||||
if (enabled && !ambience.isPlaying) ambience.play();
|
||||
if (!enabled && ambience.isPlaying) ambience.pause();
|
||||
}
|
||||
@@ -41,10 +42,29 @@
|
||||
|
||||
function play(key, volume) {
|
||||
const state = getState();
|
||||
if (!scene || !unlocked || !state.settings.soundEnabled || !scene.cache.audio.exists(key)) return;
|
||||
if (!scene || !unlocked || !state || !state.settings.soundEnabled || !scene.cache.audio.exists(key)) return;
|
||||
scene.sound.play(key, { volume: state.settings.master * state.settings.effects * (volume || 1) });
|
||||
}
|
||||
|
||||
function playVoice(key) {
|
||||
const state = getState();
|
||||
stopVoice();
|
||||
if (!scene || !unlocked || !state || !state.settings.soundEnabled || !state.settings.narrationEnabled
|
||||
|| !scene.cache.audio.exists(key)) return null;
|
||||
voice = scene.sound.add(key, { volume: state.settings.master * state.settings.voice });
|
||||
voice.once("complete", () => { voice = null; });
|
||||
voice.play();
|
||||
return voice;
|
||||
}
|
||||
|
||||
function stopVoice() {
|
||||
if (voice) {
|
||||
voice.stop();
|
||||
voice.destroy();
|
||||
}
|
||||
voice = null;
|
||||
}
|
||||
|
||||
function suspend() {
|
||||
if (ambience && ambience.isPlaying) ambience.pause();
|
||||
}
|
||||
@@ -54,12 +74,13 @@
|
||||
}
|
||||
|
||||
function stop() {
|
||||
stopVoice();
|
||||
if (ambience) ambience.stop();
|
||||
ambience = null;
|
||||
scene = null;
|
||||
}
|
||||
|
||||
return Object.freeze({ attach, unlock, apply, play, suspend, resume, stop, isUnlocked: () => unlocked });
|
||||
return Object.freeze({ attach, unlock, apply, play, playVoice, stopVoice, suspend, resume, stop, isUnlocked: () => unlocked });
|
||||
}
|
||||
|
||||
root.PrincessLimaAudio = Object.freeze({ create, TRACKS });
|
||||
|
||||
Reference in New Issue
Block a user