GameDataCenter.ts 4.1 KB

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