mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-04-11 15:47:06 +08:00
feat: 音效音量
This commit is contained in:
parent
6153ca8b51
commit
e0c79e06bb
@ -3,13 +3,12 @@ import { EventEmitter } from '../common/eventEmitter';
|
||||
import { GameStorage } from './storage';
|
||||
import { has, triggerFullscreen } from '@/plugin/utils';
|
||||
import { createSettingComponents } from './init/settings';
|
||||
import { SoundEffect } from '../audio/sound';
|
||||
import settingsText from '@/data/settings.json';
|
||||
import { isMobile } from '@/plugin/use';
|
||||
import { fontSize } from '@/plugin/ui/statusBar';
|
||||
import { CustomToolbar } from './custom/toolbar';
|
||||
import { fixedUi } from './init/ui';
|
||||
import { bgmController } from '@/module';
|
||||
import { bgmController, soundPlayer } from '@/module';
|
||||
|
||||
export interface SettingComponentProps {
|
||||
item: MotaSettingItem;
|
||||
@ -390,9 +389,9 @@ function handleAudioSetting<T extends number | boolean>(
|
||||
} else if (key === 'bgmVolume') {
|
||||
bgmController.setVolume((n as number) / 100);
|
||||
} else if (key === 'soundEnabled') {
|
||||
SoundEffect.disable = !n;
|
||||
soundPlayer.setEnabled(n as boolean);
|
||||
} else if (key === 'soundVolume') {
|
||||
SoundEffect.volume = (n as number) / 100;
|
||||
soundPlayer.setVolume((n as number) / 100)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { audioPlayer, AudioPlayer } from './player';
|
||||
import { logger } from '@/core/common/logger';
|
||||
import { VolumeEffect } from './effect';
|
||||
|
||||
type LocationArray = [number, number, number];
|
||||
|
||||
@ -16,9 +17,32 @@ export class SoundPlayer<
|
||||
readonly buffer: Map<T, AudioBuffer> = new Map();
|
||||
/** 所有正在播放的音乐 */
|
||||
readonly playing: Set<number> = new Set();
|
||||
/** 音量节点 */
|
||||
readonly gain: VolumeEffect;
|
||||
|
||||
/** 是否已经启用 */
|
||||
enabled: boolean = true;
|
||||
|
||||
constructor(public readonly player: AudioPlayer) {
|
||||
super();
|
||||
this.gain = player.createVolumeEffect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否启用音效
|
||||
* @param enabled 是否启用音效
|
||||
*/
|
||||
setEnabled(enabled: boolean) {
|
||||
if (!enabled) this.stopAllSounds();
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置音量大小
|
||||
* @param volume 音量大小
|
||||
*/
|
||||
setVolume(volume: number) {
|
||||
this.gain.setVolume(volume);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,6 +70,7 @@ export class SoundPlayer<
|
||||
position: LocationArray = [0, 0, 0],
|
||||
orientation: LocationArray = [1, 0, 0]
|
||||
) {
|
||||
if (!this.enabled) return -1;
|
||||
const buffer = this.buffer.get(id);
|
||||
if (!buffer) {
|
||||
logger.warn(52, id);
|
||||
@ -58,7 +83,7 @@ export class SoundPlayer<
|
||||
const stereo = this.player.createStereoEffect();
|
||||
stereo.setPosition(position[0], position[1], position[2]);
|
||||
stereo.setOrientation(orientation[0], orientation[1], orientation[2]);
|
||||
route.addEffect(stereo);
|
||||
route.addEffect([stereo, this.gain]);
|
||||
this.player.addRoute(`sounds.${soundNum}`, route);
|
||||
route.play();
|
||||
source.output.addEventListener('ended', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user