AppKernel.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { ANDROID, HTML5, IOS } from 'cc/env';
  2. import type { AppEventMap } from './AppEvents';
  3. import { EventManager } from '../framework/event/EventManager';
  4. import { ResourceManager } from '../framework/resource/ResourceManager';
  5. import { RedpointManager } from '../framework/redpoint/RedpointManager';
  6. import { SceneNavigator } from '../framework/scene/SceneNavigator';
  7. import { UIManager } from '../framework/ui/UIManager';
  8. import { AndroidPlatformBridge } from '../platform/AndroidPlatformBridge';
  9. import { H5PlatformBridge } from '../platform/H5PlatformBridge';
  10. import { IOSPlatformBridge } from '../platform/IOSPlatformBridge';
  11. import { PlatformBridge } from '../platform/PlatformBridge';
  12. import { HotUpdateService } from '../services/hotupdate/HotUpdateService';
  13. import { VersionService } from '../services/version/VersionService';
  14. import * as stores from '../store';
  15. import * as services from '../services';
  16. import fb from '@scripts/platform/FaceBook/Facebook';
  17. import google from '@scripts/platform/Google/Google';
  18. import { AppRedPoint } from './AppRedpoint';
  19. export class AppKernel {
  20. private static instance: AppKernel | null = null;
  21. static initialize(): AppKernel {
  22. if (!this.instance) {
  23. this.instance = new AppKernel();
  24. }
  25. return this.instance;
  26. }
  27. static get Instance(): AppKernel {
  28. if (!this.instance) throw new Error('AppKernel has not been initialized');
  29. return this.instance;
  30. }
  31. static get events(): EventManager<AppEventMap> {
  32. return this.Instance.events;
  33. }
  34. static get resources(): ResourceManager {
  35. return this.Instance.resources;
  36. }
  37. static get redpoint(): RedpointManager {
  38. return this.Instance.redpoint;
  39. }
  40. static get ui(): UIManager {
  41. return this.Instance.ui;
  42. }
  43. static get scenes(): SceneNavigator {
  44. return this.Instance.scenes;
  45. }
  46. static get version(): VersionService {
  47. return this.Instance.version;
  48. }
  49. static get hotUpdate(): HotUpdateService {
  50. return this.Instance.hotUpdate;
  51. }
  52. static get platform(): PlatformBridge {
  53. return this.Instance.platform;
  54. }
  55. static get stores(): typeof stores {
  56. return this.Instance.stores;
  57. }
  58. static get services(): typeof services {
  59. return this.Instance.services;
  60. }
  61. static get appLobby(): typeof services.appLobby {
  62. return this.services.appLobby;
  63. }
  64. static get fb(): typeof fb {
  65. return this.Instance.fb;
  66. }
  67. static get google(): typeof google {
  68. return this.Instance.google;
  69. }
  70. readonly events = new EventManager<AppEventMap>();
  71. readonly redpoint = new RedpointManager();
  72. readonly resources = new ResourceManager();
  73. readonly ui = new UIManager(this.resources);
  74. readonly scenes = new SceneNavigator(this.resources);
  75. readonly version = new VersionService();
  76. readonly hotUpdate = new HotUpdateService();
  77. readonly platform: PlatformBridge;
  78. readonly stores = stores;
  79. readonly services = services;
  80. readonly fb = fb;
  81. readonly google = google;
  82. private constructor() {
  83. this.platform = this.createPlatformBridge();
  84. this.fb.init();
  85. this.google.init();
  86. }
  87. private createPlatformBridge(): PlatformBridge {
  88. if (ANDROID) return new AndroidPlatformBridge();
  89. if (IOS) return new IOSPlatformBridge();
  90. return new H5PlatformBridge();
  91. }
  92. }