feat: 立体声音效

This commit is contained in:
unanmed 2024-02-04 16:31:11 +08:00
parent d580405037
commit cb761aede0
5 changed files with 16 additions and 6 deletions

View File

@ -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);
}
};

View File

@ -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<Panner>, listener: Partial<Listener>) {
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}'.`);
}

View File

@ -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),

View File

@ -1,3 +1,5 @@
import { has } from '@/plugin/utils';
export class GameStorage<T extends object = any> {
static list: GameStorage<any>[] = [];
@ -40,7 +42,7 @@ export class GameStorage<T extends object = any> {
getValue<K extends keyof T>(key: K, defaults: T[K]): T[K];
getValue<T>(key: string, defaults?: T): T;
getValue<K extends keyof T>(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;

View File

@ -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() {