123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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<IDataModel> = [];
- _rspModel: Map<string, IDataModel[]> = new Map<string, IDataModel[]>()
- 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<T extends IDataModel>(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();
|