diff --git a/public/libs/control.js b/public/libs/control.js index a09d7c3..6deb249 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -3398,7 +3398,9 @@ control.prototype.getPlayingSounds = function (name) { ////// 检查bgm状态 ////// control.prototype.checkBgm = function () { const bgm = Mota.require('var', 'bgm'); - if (!bgm.playing) { + if (bgm.disable) { + bgm.pause(); + } else if (!bgm.playing) { bgm.changeTo(bgm.now ?? main.startBgm); } }; diff --git a/src/core/audio/sound.ts b/src/core/audio/sound.ts index 4703512..5c3d9fb 100644 --- a/src/core/audio/sound.ts +++ b/src/core/audio/sound.ts @@ -51,6 +51,7 @@ export class SoundEffect extends AudioPlayer { }); this._stereo = stereo; + this.initAudio(stereo); } /** @@ -70,6 +71,8 @@ export class SoundEffect extends AudioPlayer { this.panner = null; this.merger = null; if (stereo) { + console.log(1); + this.panner = ac.createPanner(); this.panner.connect(this.gain); if (channel === 1) { @@ -131,6 +134,7 @@ export class SoundEffect extends AudioPlayer { */ setPanner(source: Partial, listener: Partial) { if (!this.panner) return; + console.log(2); for (const [key, value] of Object.entries(source)) { this.panner[key as keyof Panner].value = value; } @@ -149,12 +153,12 @@ export class SoundController extends ResourceController< /** * 添加一个新的音频 - * @param uri 音频的uri + * @param uri 音频的uri,由于音频也是一种资源,因此格式为`sounds.xxx` * @param data 音频的ArrayBuffer信息,会被解析为AudioBuffer */ add(uri: string, data: ArrayBuffer) { const stereo = resource.stereoSE.includes(uri); - const se = new SoundEffect(data, stereo); + const se = new SoundEffect(data, true); if (this.list[uri]) { console.warn(`Repeated sound effect: '${uri}'.`); } diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 74eaeeb..f6a835b 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -457,8 +457,8 @@ loading.once('coreInit', () => { 'screen.smoothView': !!storage.getValue('screen.smoothView', true), 'screen.criticalGem': !!storage.getValue('screen.criticalGem', false), 'action.fixed': !!storage.getValue('action.fixed', true), - 'audio.bgmEnabled': !!storage.getValue('sound.bgmEnabled', true), - 'audio.bgmVolume': storage.getValue('sound.bgmVolume', 80), + 'audio.bgmEnabled': !!storage.getValue('audio.bgmEnabled', true), + 'audio.bgmVolume': storage.getValue('audio.bgmVolume', 80), 'utils.betterLoad': !!storage.getValue('utils.betterLoad', true), 'utils.autoScale': !!storage.getValue('utils.autoScale', true), 'fx.paraLight': !!storage.getValue('fx.paraLight', true), diff --git a/src/core/main/storage.ts b/src/core/main/storage.ts index 2f56fbc..56db08b 100644 --- a/src/core/main/storage.ts +++ b/src/core/main/storage.ts @@ -1,3 +1,5 @@ +import { has } from '@/plugin/utils'; + export class GameStorage { static list: GameStorage[] = []; @@ -40,7 +42,7 @@ export class GameStorage { getValue(key: K, defaults: T[K]): T[K]; getValue(key: string, defaults?: T): T; getValue(key: K, defaults?: T[K]) { - if (this.data[key]) return this.data[key]; + if (has(this.data[key])) return this.data[key]; else { if (defaults !== void 0) { this.data[key] = defaults; diff --git a/src/ui/start.vue b/src/ui/start.vue index 8056198..5b5f40f 100644 --- a/src/ui/start.vue +++ b/src/ui/start.vue @@ -210,6 +210,8 @@ gameKey function bgm() { core.triggerBgm(); soundChecked.value = !soundChecked.value; + mainSetting.setValue('audio.bgmEnabled', soundChecked.value); + console.log(mainSetting.getValue('audio.bgmEnabled')); } async function setFullscreen() {