@energy8platform/game-engine 0.7.1 → 0.9.0
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.
- package/README.md +178 -68
- package/dist/core.cjs.js +31 -7
- package/dist/core.cjs.js.map +1 -1
- package/dist/core.d.ts +8 -1
- package/dist/core.esm.js +31 -7
- package/dist/core.esm.js.map +1 -1
- package/dist/index.cjs.js +39 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.esm.js +39 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/react.cjs.js +470 -0
- package/dist/react.cjs.js.map +1 -0
- package/dist/react.d.ts +871 -0
- package/dist/react.esm.js +455 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/vite.cjs.js +5 -0
- package/dist/vite.cjs.js.map +1 -1
- package/dist/vite.esm.js +5 -0
- package/dist/vite.esm.js.map +1 -1
- package/package.json +25 -3
- package/src/core/GameApplication.ts +1 -0
- package/src/core/SceneManager.ts +33 -7
- package/src/react/EngineContext.ts +26 -0
- package/src/react/ReactScene.ts +88 -0
- package/src/react/applyProps.ts +107 -0
- package/src/react/catalogue.ts +17 -0
- package/src/react/createPixiRoot.ts +31 -0
- package/src/react/extendAll.ts +51 -0
- package/src/react/hooks.ts +46 -0
- package/src/react/index.ts +23 -0
- package/src/react/reconciler.ts +169 -0
- package/src/state/StateMachine.ts +11 -8
- package/src/types.ts +3 -0
- package/src/vite/index.ts +5 -0
|
@@ -58,10 +58,12 @@ interface StateMachineEvents {
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
export class StateMachine<TContext = Record<string, unknown>> extends EventEmitter<StateMachineEvents> {
|
|
61
|
+
private static MAX_TRANSITION_DEPTH = 10;
|
|
62
|
+
|
|
61
63
|
private _states = new Map<string, StateConfig<TContext>>();
|
|
62
64
|
private _guards = new Map<string, (ctx: TContext) => boolean>();
|
|
63
65
|
private _current: string | null = null;
|
|
64
|
-
private
|
|
66
|
+
private _transitionDepth = 0;
|
|
65
67
|
private _context: TContext;
|
|
66
68
|
|
|
67
69
|
constructor(context: TContext) {
|
|
@@ -76,7 +78,7 @@ export class StateMachine<TContext = Record<string, unknown>> extends EventEmitt
|
|
|
76
78
|
|
|
77
79
|
/** Whether a transition is in progress */
|
|
78
80
|
get isTransitioning(): boolean {
|
|
79
|
-
return this.
|
|
81
|
+
return this._transitionDepth > 0;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/** State machine context (shared data) */
|
|
@@ -131,9 +133,10 @@ export class StateMachine<TContext = Record<string, unknown>> extends EventEmitt
|
|
|
131
133
|
* @returns true if the transition succeeded, false if blocked by a guard
|
|
132
134
|
*/
|
|
133
135
|
async transition(to: string, data?: unknown): Promise<boolean> {
|
|
134
|
-
if (this.
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
if (this._transitionDepth >= StateMachine.MAX_TRANSITION_DEPTH) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
'[StateMachine] Max transition depth exceeded — possible infinite loop',
|
|
139
|
+
);
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
const from = this._current;
|
|
@@ -152,7 +155,7 @@ export class StateMachine<TContext = Record<string, unknown>> extends EventEmitt
|
|
|
152
155
|
throw new Error(`[StateMachine] State "${to}" not registered.`);
|
|
153
156
|
}
|
|
154
157
|
|
|
155
|
-
this.
|
|
158
|
+
this._transitionDepth++;
|
|
156
159
|
|
|
157
160
|
try {
|
|
158
161
|
// Exit current state
|
|
@@ -170,7 +173,7 @@ export class StateMachine<TContext = Record<string, unknown>> extends EventEmitt
|
|
|
170
173
|
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
171
174
|
throw err;
|
|
172
175
|
} finally {
|
|
173
|
-
this.
|
|
176
|
+
this._transitionDepth--;
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
return true;
|
|
@@ -213,7 +216,7 @@ export class StateMachine<TContext = Record<string, unknown>> extends EventEmitt
|
|
|
213
216
|
await state?.exit?.(this._context);
|
|
214
217
|
}
|
|
215
218
|
this._current = null;
|
|
216
|
-
this.
|
|
219
|
+
this._transitionDepth = 0;
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
/**
|
package/src/types.ts
CHANGED
|
@@ -150,6 +150,9 @@ export interface IScene {
|
|
|
150
150
|
/** Root display container for this scene */
|
|
151
151
|
readonly container: Container;
|
|
152
152
|
|
|
153
|
+
/** @internal GameApplication reference — set by SceneManager */
|
|
154
|
+
__engineApp?: any;
|
|
155
|
+
|
|
153
156
|
/** Called when the scene is entered */
|
|
154
157
|
onEnter?(data?: unknown): Promise<void> | void;
|
|
155
158
|
|
package/src/vite/index.ts
CHANGED
|
@@ -149,6 +149,9 @@ export function defineGameConfig(config: GameConfig = {}): UserConfig {
|
|
|
149
149
|
'@pixi/ui',
|
|
150
150
|
'yoga-layout',
|
|
151
151
|
'yoga-layout/load',
|
|
152
|
+
'react',
|
|
153
|
+
'react-dom',
|
|
154
|
+
'react-reconciler',
|
|
152
155
|
],
|
|
153
156
|
...userVite.resolve,
|
|
154
157
|
},
|
|
@@ -160,6 +163,8 @@ export function defineGameConfig(config: GameConfig = {}): UserConfig {
|
|
|
160
163
|
'@pixi/layout/components',
|
|
161
164
|
'@pixi/ui',
|
|
162
165
|
'yoga-layout/load',
|
|
166
|
+
'react',
|
|
167
|
+
'react-dom',
|
|
163
168
|
],
|
|
164
169
|
exclude: [
|
|
165
170
|
'yoga-layout',
|