Setting.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { PREVIEW } from "cc/env"
  2. import { StorageUtil } from "./util/StorageUtil"
  3. export class Setting {
  4. private static vibrateEnabled: boolean = true
  5. public static get VibrateEnabled(): boolean {
  6. return this.vibrateEnabled
  7. }
  8. public static set VibrateEnabled(v: boolean) {
  9. this.vibrateEnabled = v
  10. StorageUtil.setItem('vibrateEnabled', v)
  11. }
  12. private static sfxEnabled: boolean = true
  13. public static get SfxEnabled(): boolean {
  14. return this.sfxEnabled
  15. }
  16. public static set SfxEnabled(v: boolean) {
  17. this.sfxEnabled = v
  18. StorageUtil.setItem('sfxEnabled', v)
  19. }
  20. private static bgmEnabled: boolean = true
  21. public static get BgmEnabled(): boolean {
  22. return this.bgmEnabled
  23. }
  24. public static set BgmEnabled(v: boolean) {
  25. this.bgmEnabled = v
  26. StorageUtil.setItem('bgmEnabled', v)
  27. }
  28. public static init(): void {
  29. this.sfxEnabled = StorageUtil.getItem('sfxEnabled', true)
  30. this.bgmEnabled = StorageUtil.getItem('bgmEnabled', true)
  31. this.vibrateEnabled = StorageUtil.getItem('vibrateEnabled', true)
  32. }
  33. }
  34. if (PREVIEW) {
  35. globalThis.Setting = Setting
  36. }