From 793394335d196fa22850ae85762b69786548a4f5 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 4 Feb 2024 16:46:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9F=B3=E6=95=88=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- idea.md | 2 +- public/libs/control.js | 6 ------ src/core/audio/sound.ts | 12 ++++++++---- src/core/main/setting.ts | 9 +++++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/idea.md b/idea.md index 0aaf547..89d975b 100644 --- a/idea.md +++ b/idea.md @@ -108,7 +108,7 @@ dam4.png ---- 存档 59 [] 新的事件系统,并丰富自定义事件 [] 事件、eval 内容预编译 [] 新的存档系统,可以注册存档项 -[] 渐变切 bgm +[x] 渐变切 bgm [] 新的 Flag 系统,使用 for 申请变量,dispose 释放变量,可设为渲染进程与游戏进程共通变量 [] 注册可录像操作,比如可以在点击的时候执行,自动计入录像 [] 机关门显示绑定怪物 diff --git a/public/libs/control.js b/public/libs/control.js index 6deb249..d0a7cd6 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -3374,12 +3374,6 @@ control.prototype.triggerBgm = function () { ////// 播放音频 ////// control.prototype.playSound = function (sound, pitch, callback) { sound = core.getMappedName(sound); - if ( - main.mode != 'play' || - !core.musicStatus.soundStatus || - !core.material.sounds[sound] - ) - return; Mota.require('var', 'sound').play(sound, callback); }; diff --git a/src/core/audio/sound.ts b/src/core/audio/sound.ts index 5c3d9fb..699692f 100644 --- a/src/core/audio/sound.ts +++ b/src/core/audio/sound.ts @@ -11,6 +11,11 @@ type Listener = AudioParamOf; export class SoundEffect extends AudioPlayer { static playIndex = 0; + /** 音量 */ + static volume: number = 1; + /** 是否关闭音效 */ + static disable: boolean = false; + private playing: Record = {}; private _stopingAll: boolean = false; private playMap: Map = new Map(); @@ -22,10 +27,10 @@ export class SoundEffect extends AudioPlayer { merger: ChannelMergerNode | null = null; set volumn(value: number) { - this.gain.gain.value = value; + this.gain.gain.value = value * SoundEffect.volume; } get volumn(): number { - return this.gain.gain.value; + return this.gain.gain.value / SoundEffect.volume; } set stereo(value: boolean) { @@ -71,8 +76,6 @@ 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) { @@ -96,6 +99,7 @@ export class SoundEffect extends AudioPlayer { * @returns 音频的唯一id */ playSE() { + if (SoundEffect.disable) return; const node = this.play(); if (!node) return; const index = SoundEffect.playIndex++; diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index f6a835b..d73ec87 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -4,6 +4,7 @@ import { GameStorage } from './storage'; import { has, triggerFullscreen } from '@/plugin/utils'; import { createSettingComponents } from './init/settings'; import { bgm } from '../audio/bgm'; +import { SoundEffect } from '../audio/sound'; export interface SettingComponentProps { item: MotaSettingItem; @@ -378,6 +379,10 @@ function handleAudioSetting( core.checkBgm(); } else if (key === 'bgmVolume') { bgm.volume = (n as number) / 100; + } else if (key === 'soundEnabled') { + SoundEffect.disable = !n; + } else if (key === 'soundVolume') { + SoundEffect.volume = (n as number) / 100; } } @@ -417,6 +422,8 @@ mainSetting new MotaSetting() .register('bgmEnabled', '开启音乐', true, COM.Boolean) .register('bgmVolume', '音乐音量', 80, COM.Number, [0, 100, 5]) + .register('soundEnabled', '开启音效', true, COM.Boolean) + .register('soundVolume', '音效音量', 80, COM.Number, [0, 100, 5]) ) .register( 'utils', @@ -459,6 +466,8 @@ loading.once('coreInit', () => { 'action.fixed': !!storage.getValue('action.fixed', true), 'audio.bgmEnabled': !!storage.getValue('audio.bgmEnabled', true), 'audio.bgmVolume': storage.getValue('audio.bgmVolume', 80), + 'audio.soundEnabled': !!storage.getValue('audio.soundEnabled', true), + 'audio.soundVolume': storage.getValue('audio.soundVolume', 80), 'utils.betterLoad': !!storage.getValue('utils.betterLoad', true), 'utils.autoScale': !!storage.getValue('utils.autoScale', true), 'fx.paraLight': !!storage.getValue('fx.paraLight', true),