LevelModel.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { JsonUtil } from "db://assets/core_tgx/base/utils/JsonUtil";
  2. import { Tablelevels_config } from "../../../module_basic/table/Tablelevels_config";
  3. import { GlobalConfig } from "../../../start/Config/GlobalConfig";
  4. import { sys } from "cc";
  5. import { CarColorsGlobalInstance } from "../CarColorsGlobalInstance";
  6. /**关卡数据模型
  7. */
  8. export class LevelModel {
  9. public levelConfig: Tablelevels_config;
  10. /** 当前关卡等级*/
  11. public level: number = 1;
  12. /** 每关星星结算*/
  13. public star: number = 3;
  14. /** 储存每关星星结算*/
  15. public levelStarsMap: Map<number, number> = new Map<number, number>();
  16. /** 保存可随机的关卡*/
  17. public randomLevelList: number[] = [];
  18. /** 输赢*/
  19. public isWin: boolean = false;
  20. /** 是否结束*/
  21. public isEnd: boolean = false;
  22. constructor() {
  23. this.levelConfig = new Tablelevels_config();
  24. this.getRandomLevelList();
  25. const isDebug = GlobalConfig.isDebug;
  26. if (isDebug) {
  27. this.level = GlobalConfig.initilizeLevel;
  28. } else {
  29. const level = sys.localStorage.getItem('level');
  30. if (!level) {
  31. this.level = 1;
  32. } else {
  33. if (level > GlobalConfig.levelTotal) {
  34. const randomLevel = this.randomLevelList[Math.floor(Math.random() * this.randomLevelList.length - 1)];
  35. this.level = randomLevel;
  36. } else {
  37. this.level = parseInt(level);
  38. }
  39. }
  40. };
  41. this.levelConfig.init(this.level);
  42. }
  43. /** 可随机的关卡合集*/
  44. getRandomLevelList() {
  45. const table = JsonUtil.get(Tablelevels_config.TableName);
  46. if (!table) {
  47. console.warn('Get level table is fail!');
  48. }
  49. this.randomLevelList = Object.values(table).filter(item => item['random'] == 1)
  50. .map(item => item['level']);
  51. // console.log('随机关卡列表:', this.randomLevelList);
  52. }
  53. /** 清除关卡数据*/
  54. clearLevel() {
  55. this.isWin = false;
  56. this.isEnd = false;
  57. this.star = 3;
  58. }
  59. }