GameDataCenter.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { SevBack } from "../common/Xys";
  2. import { GameServerModel } from "../server/GameServerModel";
  3. import { LoginServerModel } from "../server/LoginServerModel";
  4. import DialogModel from "./model/DialogModel";
  5. import GuideModel from "./model/GuideModel";
  6. import IDataModel from "../frameWork/model/IDataModel";
  7. import LoadingModel from "./model/LoadingModel";
  8. import LoginModel from "./model/Login/LoginModel";
  9. import PlatformModel from "./model/PlatformModel";
  10. import RedDotModel from "./model/RedDotModel";
  11. import { AudioModel } from "./model/System/AudioModel";
  12. import { SettingModel } from "./model/System/SettingModel";
  13. import SystemModel from "./model/System/SystemModel";
  14. import TaskModel from "./model/Task/TaskModel";
  15. import TimeModel from "./model/TimeModel";
  16. import UserModel from "./model/User/UserModel";
  17. import WindowModel from "./model/WindowModel";
  18. import BattleModel from "./model/Battle/BattleModel";
  19. import OrderModel from "./model/OrderModel";
  20. import ItemModel from "./model/Item/ItemModel";
  21. import PageModel from "./model/PageModel";
  22. import GridMapModel from "./model/GridMap/GridMapModel";
  23. class GameDataCenter {
  24. _tModel: Array<IDataModel> = [];
  25. _rspModel: Map<string, IDataModel[]> = new Map<string, IDataModel[]>()
  26. sevBack: SevBack = null;
  27. audio: AudioModel = null
  28. setting: SettingModel = null
  29. system: SystemModel = null
  30. login: LoginModel = null
  31. time: TimeModel = null
  32. window: WindowModel = null
  33. loading: LoadingModel = null
  34. plat: PlatformModel = null
  35. reddot: RedDotModel = null
  36. user: UserModel;
  37. guide: GuideModel;
  38. task: TaskModel;
  39. dialog: DialogModel;
  40. gameServer: GameServerModel;
  41. loginServer: LoginServerModel;
  42. battle: BattleModel;
  43. order: OrderModel;
  44. page: PageModel;
  45. item: ItemModel;
  46. gridMap: GridMapModel;
  47. constructor() {
  48. if (CC_PREVIEW) window["gdc"] = this;
  49. }
  50. newModel<T extends IDataModel>(c: { new(): T }): T {
  51. let obj = new c()
  52. this._tModel.push(obj);
  53. return obj
  54. }
  55. clear() {
  56. this._tModel.forEach(m => {
  57. m.clear();
  58. });
  59. }
  60. //初始化登录需要的模块
  61. initLoadModule() {
  62. this._tModel = []
  63. this.sevBack = null
  64. this.audio = this.newModel(AudioModel)
  65. this.setting = this.newModel(SettingModel)
  66. this.login = this.newModel(LoginModel)
  67. this.user = this.newModel(UserModel)
  68. this.plat = this.newModel(PlatformModel)
  69. this.window = this.newModel(WindowModel)
  70. this.loading = this.newModel(LoadingModel)
  71. this.time = this.newModel(TimeModel)
  72. this.loginServer = this.newModel(LoginServerModel);
  73. this.initLoadRspModel()
  74. }
  75. initModule() {
  76. this.system = this.newModel(SystemModel)
  77. this.order = this.newModel(OrderModel)
  78. this.task = this.newModel(TaskModel)
  79. this.item = this.newModel(ItemModel);
  80. this.guide = this.newModel(GuideModel)
  81. this.dialog = this.newModel(DialogModel)
  82. this.gameServer = this.newModel(GameServerModel);
  83. this.battle = this.newModel(BattleModel);
  84. this.page = this.newModel(PageModel)
  85. this.gridMap = this.newModel(GridMapModel)
  86. // 红点注册必须在其他model之后
  87. this.reddot = this.newModel(RedDotModel);
  88. }
  89. initLoadRspModel() {
  90. this._rspModel.set("win", [this.window])
  91. this._rspModel.set("time", [this.time])
  92. }
  93. setRspModel(actName: string, model: IDataModel) {
  94. if (this._rspModel.has(actName)) {
  95. //该act已经有model监听,直接push
  96. let modelList = this._rspModel.get(actName)
  97. if (modelList.indexOf(model) < 0) {
  98. modelList.push(model)
  99. this._rspModel.set(actName, modelList)
  100. } else {
  101. console.warn("模块:", model.getModelName(), " 已注册了=>", actName)
  102. }
  103. } else {
  104. this._rspModel.set(actName, [model])
  105. }
  106. }
  107. }
  108. export default new GameDataCenter();