@energy8platform/game-engine 0.7.0 → 0.8.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.
@@ -5,6 +5,7 @@ import {
5
5
  type GameConfigData,
6
6
  type PlayResultData,
7
7
  type SessionData,
8
+ type PlayResultAckPayload,
8
9
  } from '@energy8platform/game-sdk';
9
10
 
10
11
  export interface DevBridgeConfig {
@@ -104,7 +105,7 @@ export class DevBridge {
104
105
  this.handlePlayRequest(payload, id);
105
106
  });
106
107
 
107
- this._bridge.on('PLAY_RESULT_ACK', (payload: unknown) => {
108
+ this._bridge.on('PLAY_RESULT_ACK', (payload: PlayResultAckPayload) => {
108
109
  this.handlePlayAck(payload);
109
110
  });
110
111
 
@@ -188,14 +189,15 @@ export class DevBridge {
188
189
  nextActions: customResult.nextActions ?? ['spin'],
189
190
  session: customResult.session ?? null,
190
191
  creditPending: false,
191
- currency: 'USD',
192
+ bonusFreeSpin: customResult.bonusFreeSpin ?? null,
193
+ currency: this._config.currency,
192
194
  gameId: this._config.gameConfig?.id ?? 'dev-game',
193
195
  };
194
196
 
195
197
  this.delayedSend('PLAY_RESULT', result, id);
196
198
  }
197
199
 
198
- private handlePlayAck(_payload: unknown): void {
200
+ private handlePlayAck(_payload: PlayResultAckPayload): void {
199
201
  if (this._config.debug) {
200
202
  console.log('[DevBridge] Play acknowledged');
201
203
  }
@@ -206,7 +208,7 @@ export class DevBridge {
206
208
  }
207
209
 
208
210
  private handleGetState(id?: string): void {
209
- this.delayedSend('STATE_RESPONSE', this._config.session, id);
211
+ this.delayedSend('STATE_RESPONSE', { session: this._config.session ?? null }, id);
210
212
  }
211
213
 
212
214
  private handleOpenDeposit(): void {
package/src/index.ts CHANGED
@@ -29,6 +29,11 @@ export type {
29
29
  SessionData,
30
30
  PlayParams,
31
31
  PlayResultData,
32
+ BalanceData,
33
+ SymbolData,
34
+ PaylineData,
35
+ WinLineData,
36
+ AnywhereWinData,
32
37
  } from './types';
33
38
 
34
39
  // ─── Assets ──────────────────────────────────────────────
@@ -37,6 +42,14 @@ export { AssetManager } from './assets/AssetManager';
37
42
  // ─── Audio ───────────────────────────────────────────────
38
43
  export { AudioManager } from './audio/AudioManager';
39
44
 
45
+ // ─── SDK Error Classes ───────────────────────────────────
46
+ export {
47
+ SDKError,
48
+ TimeoutError,
49
+ BridgeNotReadyError,
50
+ BridgeDestroyedError,
51
+ } from '@energy8platform/game-sdk';
52
+
40
53
  // ─── Viewport ────────────────────────────────────────────
41
54
  export { ViewportManager } from './viewport/ViewportManager';
42
55
 
@@ -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 _transitioning = false;
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._transitioning;
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._transitioning) {
135
- console.warn('[StateMachine] Transition already in progress');
136
- return false;
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._transitioning = true;
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._transitioning = false;
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._transitioning = false;
219
+ this._transitionDepth = 0;
217
220
  }
218
221
 
219
222
  /**
package/src/types.ts CHANGED
@@ -5,6 +5,11 @@ import type {
5
5
  SessionData,
6
6
  PlayParams,
7
7
  PlayResultData,
8
+ BalanceData,
9
+ SymbolData,
10
+ PaylineData,
11
+ WinLineData,
12
+ AnywhereWinData,
8
13
  } from '@energy8platform/game-sdk';
9
14
 
10
15
  // ─── Scale Modes ───────────────────────────────────────────
@@ -191,6 +196,8 @@ export interface GameEngineEvents {
191
196
  orientationChange: Orientation;
192
197
  /** Fired on scene change */
193
198
  sceneChange: { from: string | null; to: string };
199
+ /** Fired when player balance changes (forwarded from SDK) */
200
+ balanceUpdate: { balance: number };
194
201
  /** Fired on error */
195
202
  error: Error;
196
203
  /** Fired when engine is destroyed */
@@ -219,4 +226,9 @@ export type {
219
226
  SessionData,
220
227
  PlayParams,
221
228
  PlayResultData,
229
+ BalanceData,
230
+ SymbolData,
231
+ PaylineData,
232
+ WinLineData,
233
+ AnywhereWinData,
222
234
  };