123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- export default class UserDataMgr {
- private static instance: UserDataMgr = null;
- public static getInstance() {
- if (!UserDataMgr.instance) {
- UserDataMgr.instance = new UserDataMgr();
- UserDataMgr.instance.loadLocalData();
- }
- return UserDataMgr.instance;
- }
- /**
- * 当前解锁等级
- */
- levelId: number = 0;
- /**
- * 游戏局数
- */
- gameCount: number = 0;
- /**
- * 最高分数
- */
- maxScore: number = 0;
- /**
- * 消耗的卡路里数
- */
- calorie: number = 0;
- // 等级数据
- levelScoreData: { [key: number]: number } = {};
- isFirst: boolean = true;
- public loadLocalData() {
- //TODO app接口
- let data = Laya.LocalStorage.getJSON("gameData");
- this.setData(data);
- }
- public syncSaveData() {
- //TODO app存储接口
- Laya.LocalStorage.setJSON("gameData", this);
- }
- private setData(data: any) {
- if (data) {
- this.levelId = data.levelId;
- this.maxScore = data.maxScore;
- this.gameCount = data.gameCount;
- this.calorie = data.calorie;
- this.levelScoreData = data.levelScoreData || {};
- this.isFirst = data.isFirst;
- } else {
- this.syncSaveData();
- }
- }
- }
|