123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import IDataModel from "../framework/data/model/IDataModel";
- import Global from "../framework/constant/Global";
- import { SingletonFactory } from "../framework/utils/SingletonFactory";
- import AccountModel from "../data/Account/AccountModel";
- import SystemModel from "../data/System/SystemModel";
- import Utils from "../framework/utils/utils";
- export default class GameDataCenter {
- static singleInstance: GameDataCenter = null;
- static getInstance(): GameDataCenter {
- if (GameDataCenter.singleInstance == null) {
- GameDataCenter.singleInstance = new GameDataCenter();
- }
- return GameDataCenter.singleInstance;
- }
- private _tModel: Array<IDataModel> = [];
- account: AccountModel = null; //用户数据
- system: SystemModel = null;
- staticData = {}; //表格数据保存
- constructor() {
- }
- newModel<T extends IDataModel>(c: { new(): T }): T {
- let obj = SingletonFactory.getInstance(c);
- this._tModel.push(obj);
- return obj
- }
- clear() {
- this._tModel.forEach(m => {
- m.clear();
- });
- }
- initModule() {
- AccountModel.getInstance();
- SystemModel.getInstance();
- }
- /**
- * 提前加载静态数据
- * @param callback
- */
- loadJsonData(callback) {
- // let resArr = [
- // "res/res_json/monster",
- // "res/res_json/monsterOut",
- // "res/res_json/stage",
- // "res/res_json/hero",
- // "res/res_json/weapon",
- // ]
- // bb.UILoader.loadResArr(resArr, function (asset) {
- // asset.forEach(element => {
- // let monsterName = element.name;
- // let monsterJson = element.json;
- // this.staticData[monsterName] = monsterJson;
- // });
- // this.pareData();
- // if (callback) {
- // callback()
- // }
- // }.bind(this))
- }
- /**
- * 初次 需要解析的数据
- */
- pareData() {
- for (const key in this.staticData[Global.ExcelJson.Stage]) {
- if (this.staticData[Global.ExcelJson.Stage].hasOwnProperty(key)) {
- const element = this.staticData[Global.ExcelJson.Stage][key];
- let stageId = element.id;
- element["monsterOut"] = {};
- for (const key1 in this.staticData[Global.ExcelJson.MonsterOut]) {
- if (this.staticData[Global.ExcelJson.MonsterOut].hasOwnProperty(key1)) {
- const element1 = this.staticData[Global.ExcelJson.MonsterOut][key1];
- if (element1.stageId == stageId) {
- if (!element["monsterOut"][element1.waves]) {
- element["monsterOut"][element1.waves] = [];
- }
- for (let index = 0; index < element1.monsterNum; index++) {
- element["monsterOut"][element1.waves].push(Utils.clone(element1))
- }
- }
- }
- }
- }
- }
- for (const key in this.staticData[Global.ExcelJson.Stage]) {
- if (this.staticData[Global.ExcelJson.Stage].hasOwnProperty(key)) {
- const element = this.staticData[Global.ExcelJson.Stage][key];
- let monsterNum = 0;
- for (const key1 in element["monsterOut"]) {
- if (element["monsterOut"].hasOwnProperty(key1)) {
- const element1 = element["monsterOut"][key1];
- monsterNum = monsterNum + element1.length;
- }
- }
- element.monsterNum = monsterNum;
- }
- }
- }
- /**
- *
- */
- GetDataByName(key: string) {
- return this.staticData[key];
- }
- }
|