import { sys } from "cc"; import PlatformMng, { Channel } from "./AdSdk/PlatformMng"; import AudioMng from "./AudioMng"; import GDSave from "./GDSave"; export default class GameData { static isInited: boolean = false; static isIdiomInited: boolean = false; public static game: GDSave = new GDSave(); public static GameFPS: number = 1 / 60; static FileName: string = "ChessGame_Save"; public static SaveGame(): void { var jsonString: string = JSON.stringify(GameData.game); sys.localStorage.setItem(GameData.FileName, jsonString); } public static LoadGame(): void { var jsonString = sys.localStorage.getItem(GameData.FileName); if (jsonString) { let saveobj = JSON.parse(jsonString); this.ContinueGame(saveobj); } else { this.NewGame(); this.SaveGame(); } this.Init() } public static Init(){ if(sys.platform==sys.Platform.WECHAT_GAME) PlatformMng.channo=Channel.wx PlatformMng.platform.init(); } //新的游戏 public static NewGame(): void { GameData.game = new GDSave(); AudioMng.Instance.InitSaveData(); console.log('新的游戏') } //继续游戏 public static ContinueGame(saveobj:any){ console.log('继续游戏') GameData.game = new GDSave(); GameData.game.loadfromSave(saveobj); console.log(GameData.game); } /** * 获取自定义数据 */ public static GetCustomData(dataname: string): number { var val = 0; var customData = GameData.game.customData; if (customData[dataname]) val = customData[dataname]; return val; } /** * 设置自定义数据 */ public static SetCustomData(dataname: string, val: number): void { GameData.game.customData[dataname] = val; GameData.SaveGame(); } }