@skewedaspect/sage 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,7 @@ export declare class SkewedAspectGameEngine {
37
37
  engines: Engines;
38
38
  eventBus: GameEventBus;
39
39
  logger: LoggingUtility;
40
+ started: boolean;
40
41
  private _log;
41
42
  private _beforeStartHook;
42
43
  private _onStartHook;
package/dist/sage.es.js CHANGED
@@ -23,6 +23,7 @@ class z {
23
23
  n(this, "engines");
24
24
  n(this, "eventBus");
25
25
  n(this, "logger");
26
+ n(this, "started", !1);
26
27
  n(this, "_log");
27
28
  // Lifecycle hooks
28
29
  n(this, "_beforeStartHook", null);
@@ -67,45 +68,48 @@ class z {
67
68
  * Starts the game engine.
68
69
  */
69
70
  async start() {
70
- this._log.info(`Starting SkewedAspect Game Engine (Version: ${m})...`), this._beforeStartHook && (this._log.debug("Executing beforeStart hook..."), await this._beforeStartHook(this)), await this.managers.gameManager.start(this.canvas), this._log.info("Game engine started successfully"), this._onStartHook && (this._log.debug("Executing onStart hook..."), await this._onStartHook(this));
71
+ this.started ? this._log.warn("Game engine is already started. Skipping start.") : (this._log.info(`Starting SkewedAspect Game Engine (Version: ${m})...`), this._beforeStartHook && (this._log.debug("Executing beforeStart hook..."), await this._beforeStartHook(this)), await this.managers.gameManager.start(this.canvas), this._log.info("Game engine started successfully"), this._onStartHook && (this._log.debug("Executing onStart hook..."), await this._onStartHook(this)), this.started = !0);
71
72
  }
72
73
  /**
73
74
  * Stops the game engine.
74
75
  */
75
76
  async stop() {
76
- this._log.info(`Stopping SkewedAspect Game Engine (Version: ${m})...`);
77
- let e = null;
78
- if (this._onTeardownHook)
77
+ if (this.started) {
78
+ this._log.info(`Stopping SkewedAspect Game Engine (Version: ${m})...`);
79
+ let e = null;
80
+ if (this._onTeardownHook)
81
+ try {
82
+ this._log.debug("Executing onTeardown hook..."), await this._onTeardownHook(this);
83
+ } catch (t) {
84
+ this._log.error(`Error in onTeardown hook: ${t}`), e = e || t;
85
+ }
86
+ for (const t of Object.keys(this.managers)) {
87
+ const i = this.managers[t];
88
+ if (typeof i.$teardown == "function")
89
+ try {
90
+ this._log.debug(`Tearing down manager: ${t}`), await i.$teardown();
91
+ } catch (s) {
92
+ this._log.error(`Error tearing down manager ${t}: ${s}`), e = e || s;
93
+ }
94
+ }
95
+ for (const t of Object.keys(this.engines)) {
96
+ const i = this.engines[t];
97
+ if (typeof i.$teardown == "function")
98
+ try {
99
+ this._log.debug(`Tearing down engine: ${t}`), await i.$teardown();
100
+ } catch (s) {
101
+ this._log.error(`Error tearing down engine ${t}: ${s}`), e = e || s;
102
+ }
103
+ }
79
104
  try {
80
- this._log.debug("Executing onTeardown hook..."), await this._onTeardownHook(this);
105
+ await this.managers.gameManager.stop();
81
106
  } catch (t) {
82
- this._log.error(`Error in onTeardown hook: ${t}`), e = e || t;
107
+ this._log.error(`Error stopping game manager: ${t}`), e = e || t;
83
108
  }
84
- for (const t of Object.keys(this.managers)) {
85
- const i = this.managers[t];
86
- if (typeof i.$teardown == "function")
87
- try {
88
- this._log.debug(`Tearing down manager: ${t}`), await i.$teardown();
89
- } catch (s) {
90
- this._log.error(`Error tearing down manager ${t}: ${s}`), e = e || s;
91
- }
92
- }
93
- for (const t of Object.keys(this.engines)) {
94
- const i = this.engines[t];
95
- if (typeof i.$teardown == "function")
96
- try {
97
- this._log.debug(`Tearing down engine: ${t}`), await i.$teardown();
98
- } catch (s) {
99
- this._log.error(`Error tearing down engine ${t}: ${s}`), e = e || s;
100
- }
101
- }
102
- try {
103
- await this.managers.gameManager.stop();
104
- } catch (t) {
105
- this._log.error(`Error stopping game manager: ${t}`), e = e || t;
106
- }
107
- if (this._log.info("Game engine stopped successfully"), e)
108
- throw e;
109
+ if (this._log.info("Game engine stopped successfully"), e)
110
+ throw e;
111
+ } else
112
+ this._log.warn("Game engine is not started. Skipping stop.");
109
113
  }
110
114
  }
111
115
  class P {