AccountModelSettingComp.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  2. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  3. import { VM } from "../../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
  4. import { VibrationManager } from "../../../platform/vibration/VibrationManager";
  5. @ecs.register('AccountModelSetting')
  6. export class AccountModelSettingComp extends ecs.Comp {
  7. /** 提供 VM 组件使用的数据 */
  8. vm: AccountSettingVM = new AccountSettingVM();
  9. vmAdd() {
  10. VM.add(this.vm, "AccountSetting");
  11. }
  12. get musicOn(): boolean {
  13. return this.vm.musicOn
  14. }
  15. set musicOn(val: boolean) {
  16. this.vm.musicOn = val
  17. oops.audio.switchMusic = val
  18. if (val) {
  19. // oops.audio.stopAll()
  20. // oops.audio.playerMusicLoop("common/audio/bgm");
  21. oops.audio.resumeAll()
  22. }else{
  23. oops.audio.pauseAll()
  24. }
  25. oops.storage.set("musicOn", val)
  26. }
  27. get effectOn(): boolean {
  28. return this.vm.effectOn
  29. }
  30. set effectOn(val: boolean) {
  31. this.vm.effectOn = val
  32. oops.audio.switchEffect = val
  33. oops.storage.set("effectOn", val)
  34. }
  35. get vibrationOn(): boolean {
  36. return this.vm.vibrationOn
  37. }
  38. set vibrationOn(val: boolean) {
  39. this.vm.vibrationOn = val
  40. VibrationManager.getInstance().switchVibration = val
  41. oops.storage.set("vibrationOn", val)
  42. }
  43. vmRemove() {
  44. this.vm.reset();
  45. VM.remove("AccountSetting");
  46. }
  47. reset() {
  48. this.vmRemove();
  49. }
  50. }
  51. class AccountSettingVM {
  52. /** 声音 */
  53. musicOn: boolean = true;
  54. /** 特效 */
  55. effectOn: boolean = true;
  56. /** 震动 */
  57. vibrationOn: boolean = true;
  58. reset() {
  59. this.musicOn = true;
  60. this.effectOn = true;
  61. this.vibrationOn = true;
  62. }
  63. }