GameBasicSettings.ts
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { LocalStorage } from "simba-localstorage";
import { debounce } from "simba-utils";
import { SettingEvents } from "../../event/BaseEvents";
let musicVolume = LocalStorage.getFloat("_musicVolume", 1);
let soundVolume = LocalStorage.getFloat("_soundVolume", 1);
let enableVibration = LocalStorage.getBoolean("_enableVibration", true);
const saveMusicVolume = debounce(() => {
LocalStorage.setFloat("_musicVolume", musicVolume);
}, 500);
const saveSoundVolume = debounce(() => {
LocalStorage.setFloat("_soundVolume", soundVolume);
}, 500);
const saveEnableVibration = debounce(() => {
LocalStorage.setBoolean("_enableVibration", enableVibration);
}, 500);
export const GameBasicSettings = {
get musicVolume() { return musicVolume; },
set musicVolume(v: number) {
v = Math.min(1, Math.max(0, v));
if (v != musicVolume) {
musicVolume = v;
SettingEvents.MusicVolumeChange.emit(musicVolume);
saveMusicVolume();
}
},
get soundVolume() { return soundVolume; },
set soundVolume(v: number) {
v = Math.min(1, Math.max(0, v));
if (v != soundVolume) {
soundVolume = v;
SettingEvents.SoundVolumeChange.emit(soundVolume);
saveSoundVolume();
}
},
get enableVibration() { return enableVibration; },
set enableVibration(v: boolean) {
enableVibration = v;
saveEnableVibration();
}
}