import { SevBack } from "../common/Xys"; import AccountModel from "./model/Account/AccountModel"; import GuideModel from "./model/GuideModel"; import IDataModel from "./model/IDataModel"; import LoadingModel from "./model/LoadingModel"; import LoginModel from "./model/LoginModel"; import PlatformModel from "./model/PlatformModel"; import RedDotModel from "./model/RedDotModel"; import { AudioModel } from "./model/System/AudioModel"; import { SettingModel } from "./model/System/SettingModel"; import SystemModel from "./model/System/SystemModel"; import TaskModel from "./model/TaskModel"; import TimeModel from "./model/TimeModel"; import UserModel from "./model/UserModel"; import WindowModel from "./model/WindowModel"; class GameDataCenter { _tModel: Array = []; _rspModel: Map = new Map() sevBack: SevBack = null; account: AccountModel = null audio: AudioModel = null setting: SettingModel = null system: SystemModel = null login: LoginModel = null time: TimeModel = null window: WindowModel = null loading: LoadingModel = null plat: PlatformModel = null reddot: RedDotModel = null user: UserModel; guide: GuideModel; task: TaskModel; constructor() { if (CC_PREVIEW) window["gdc"] = this; } newModel(c: { new(): T }): T { let obj = new c() this._tModel.push(obj); return obj } clear() { this._tModel.forEach(m => { m.clear(); }); } //初始化登录需要的模块 initLoadModule() { this._tModel = [] this.sevBack = null this.audio = this.newModel(AudioModel) this.setting = this.newModel(SettingModel) this.user = this.newModel(UserModel) this.account = this.newModel(AccountModel) this.login = this.newModel(LoginModel) this.plat = this.newModel(PlatformModel) this.window = this.newModel(WindowModel) this.loading = this.newModel(LoadingModel) this.time = this.newModel(TimeModel) this.initLoadRspModel() } initModule() { this.system = this.newModel(SystemModel) this.task = this.newModel(TaskModel) this.guide = this.newModel(GuideModel) // 红点注册必须在其他model之后 this.reddot = this.newModel(RedDotModel); } initLoadRspModel() { this._rspModel.set("win", [this.window]) this._rspModel.set("time", [this.time]) } setRspModel(actName: string, model: IDataModel) { if (this._rspModel.has(actName)) { //该act已经有model监听,直接push let modelList = this._rspModel.get(actName) if (modelList.indexOf(model) < 0) { modelList.push(model) this._rspModel.set(actName, modelList) } else { console.warn("模块:", model.getModelName(), " 已注册了=>", actName) } } else { this._rspModel.set(actName, [model]) } } } export default new GameDataCenter();