GameControl.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /** @format */
  2. import {AudioManager} from './mgrs/AudioManager'
  3. import {EventManager} from './mgrs/EventManager'
  4. import {LocalStorageManager} from './mgrs/LocalStorageManager'
  5. import {PlatformManager} from './mgrs/PlatformManager'
  6. import {PrefabPoolManager} from './mgrs/PrefabPoolManager'
  7. import {ResourceManager} from './mgrs/ResourceManager'
  8. import {UIManager} from './mgrs/UIManager'
  9. import {NetManager} from './mgrs/NetManager'
  10. import {Log} from './utils/LogUtils'
  11. import {HttpManager} from './mgrs/HttpManager'
  12. import {GameData} from './data/GameData'
  13. import {MainData} from './data/MainData'
  14. import {UserData} from './data/UserData'
  15. import {I18nManager} from './mgrs/I18nManager'
  16. import {GoodsManager} from './mgrs/GoodsManager'
  17. import {DIS_ID, Language} from './enums/Enum'
  18. import {TimeManager} from './mgrs/TimeManager'
  19. import {GlobalManager} from './mgrs/GlobalManager'
  20. import {DataConfig} from './config/DataConfig'
  21. import {GameManager} from './mgrs/GameManager'
  22. import {ZumaData} from './data/ZumaData'
  23. export const Data = {
  24. game: new GameData(),
  25. main: new MainData(),
  26. user: new UserData(),
  27. zuma: new ZumaData(),
  28. init() {
  29. Data.game.init()
  30. Data.main.init()
  31. Data.user.init()
  32. },
  33. reset() {
  34. Data.user.reset()
  35. Data.main.reset()
  36. Data.game.reset()
  37. },
  38. }
  39. export const Mgr = {
  40. audio: new AudioManager(), // 音频管理器
  41. event: new EventManager(), // 事件管理器
  42. storage: new LocalStorageManager(), // 本地存储管理器
  43. platform: new PlatformManager(), // 平台管理器
  44. pool: new PrefabPoolManager(), // 节点池管理器
  45. res: new ResourceManager(), // 资源管理器
  46. ui: new UIManager(), // UI管理器
  47. net: new NetManager(), // Net管理器
  48. http: new HttpManager(), // HTTP管理器
  49. i18n: new I18nManager(), // 多语言管理器
  50. goods: new GoodsManager(), // 道具管理器
  51. time: new TimeManager(), // 时间管理器
  52. global: new GlobalManager(), // 全局管理器
  53. game: new GameManager(), // 战斗管理器
  54. async init() {
  55. cc.director.getCollisionManager().enabled = true
  56. // cc.director.getCollisionManager().enabledDebugDraw = true
  57. let isInit: boolean = true
  58. Mgr.platform.init()
  59. Mgr.net.init()
  60. isInit =
  61. isInit &&
  62. (await Mgr.audio.init()) &&
  63. (await Mgr.ui.init()) &&
  64. (await Mgr.i18n.init(DataConfig[DIS_ID.language].data1))
  65. if (!isInit) Log.warn('GameControl 框架初始化失败')
  66. return isInit
  67. },
  68. reset() {
  69. Mgr.event.reset()
  70. Mgr.ui.closeAll()
  71. Mgr.time.reset()
  72. Mgr.goods.reset()
  73. Mgr.net.reset()
  74. Mgr.global.reset()
  75. },
  76. }
  77. export class GameControl {
  78. public static async init() {
  79. Data.init()
  80. return await Mgr.init()
  81. }
  82. public static resetGame() {
  83. Mgr.net.stopReConnect()
  84. Data.reset()
  85. Mgr.reset()
  86. cc.director.loadScene('Main')
  87. }
  88. }
  89. CC_DEV && window && (window['Mgr'] = Mgr)
  90. CC_DEV && window && (window['Data'] = Data)