Fix scaling breaking text container when app container was smaller than text container.
Audio and volume controls work. Support for shake command. Text scrolling buttons.
This commit is contained in:
parent
bf5108bfe6
commit
5b5f3d83c2
10 changed files with 363 additions and 57 deletions
81
Js/Audio.js
81
Js/Audio.js
|
@ -61,15 +61,68 @@ class bufferLoader {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetAll() {
|
||||
this.bufferList = {};
|
||||
}
|
||||
}
|
||||
|
||||
class audioController {
|
||||
constructor() {
|
||||
constructor(utage) {
|
||||
this.utage = utage;
|
||||
this.volume = 1.0;
|
||||
this.muted = false;
|
||||
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
this.gainNode = this.audioCtx.createGain();
|
||||
this.gainNode.connect(this.audioCtx.destination);
|
||||
this.loader = undefined;
|
||||
this.sources = {};
|
||||
}
|
||||
|
||||
playSound(sound, type) {
|
||||
if(!this.loader.bufferList[sound]) {
|
||||
return;
|
||||
}
|
||||
let source = this.audioCtx.createBufferSource()
|
||||
this.sources[sound] = source;
|
||||
source.buffer = this.loader.bufferList[sound];
|
||||
source.loop = false;
|
||||
if(type === "bgm") {
|
||||
if(this.utage.bgmLoopData[this.utage.soundInfo[sound].origFileName]) {
|
||||
let loop = this.utage.bgmLoopData[this.utage.soundInfo[sound].origFileName];
|
||||
source.loopStart = loop["loop_start"]["seconds"];
|
||||
source.loopEnd = loop["loop_end"]["seconds"];
|
||||
source.loop = true;
|
||||
}
|
||||
}
|
||||
source.connect(this.gainNode);
|
||||
source.onended = () => {
|
||||
if(!this.sources[sound]) { return; }
|
||||
this.sources[sound].disconnect(this.gainNode);
|
||||
this.sources[sound] = undefined;
|
||||
}
|
||||
source.start(0);
|
||||
}
|
||||
|
||||
stopSound(sound) {
|
||||
if(sound === 'bgm') {
|
||||
for(let sKey of Object.keys(this.sources)) {
|
||||
try {
|
||||
if(!sKey.startsWith('bgm')) { continue; }
|
||||
let s = this.sources[sKey];
|
||||
s.stop();
|
||||
s.disconnect(this.gainNode);
|
||||
s = undefined;
|
||||
} catch (error) { }
|
||||
}
|
||||
} else {
|
||||
if(!this.sources[sound]) {
|
||||
return;
|
||||
}
|
||||
this.sources[sound].stop();
|
||||
this.sources[sound].disconnect(this.gainNode);
|
||||
this.sources[sound] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
changeVolume(vol) {
|
||||
|
@ -79,10 +132,14 @@ class audioController {
|
|||
}
|
||||
}
|
||||
|
||||
mute() {
|
||||
this.muted = !this.muted;
|
||||
mute(mute) {
|
||||
if(mute != undefined) {
|
||||
this.muted = mute;
|
||||
} else {
|
||||
this.muted = !this.muted;
|
||||
}
|
||||
if(this.muted) {
|
||||
this.gainNode.gain.setValueAtTime(0, athis.udioCtx.currentTime);
|
||||
this.gainNode.gain.setValueAtTime(0, this.audioCtx.currentTime);
|
||||
} else {
|
||||
this.gainNode.gain.setValueAtTime(this.volume, this.audioCtx.currentTime);
|
||||
}
|
||||
|
@ -96,4 +153,20 @@ class audioController {
|
|||
});
|
||||
this.loader.load();
|
||||
}
|
||||
|
||||
resetAll() {
|
||||
if(this.loader) {
|
||||
this.loader.resetAll();
|
||||
this.loader = undefined;
|
||||
}
|
||||
for(let sKey of Object.keys(this.sources)) {
|
||||
let s = this.sources[sKey];
|
||||
try {
|
||||
s.stop();
|
||||
s.disconnect(this.gainNode);
|
||||
s = undefined;
|
||||
} catch(error) { }
|
||||
}
|
||||
this.sources = {};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue