@energy8platform/game-engine 0.10.1 → 0.10.3
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/bin/simulate.ts +0 -0
- package/dist/debug.cjs.js +64 -882
- package/dist/debug.cjs.js.map +1 -1
- package/dist/debug.d.ts +7 -9
- package/dist/debug.esm.js +64 -882
- package/dist/debug.esm.js.map +1 -1
- package/dist/index.cjs.js +64 -889
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +8 -165
- package/dist/index.esm.js +65 -883
- package/dist/index.esm.js.map +1 -1
- package/dist/lua.cjs.js +4 -4
- package/dist/lua.cjs.js.map +1 -1
- package/dist/lua.esm.js +4 -4
- package/dist/lua.esm.js.map +1 -1
- package/dist/vite.cjs.js +81 -17
- package/dist/vite.cjs.js.map +1 -1
- package/dist/vite.esm.js +81 -17
- package/dist/vite.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/debug/DevBridge.ts +71 -54
- package/src/index.ts +3 -8
- package/src/lua/LuaEngine.ts +2 -3
- package/src/lua/LuaEngineAPI.ts +1 -4
- package/src/lua/fengari.d.ts +10 -0
- package/src/vite/index.ts +89 -19
package/dist/index.d.ts
CHANGED
|
@@ -1904,7 +1904,7 @@ interface DevBridgeConfig {
|
|
|
1904
1904
|
networkDelay?: number;
|
|
1905
1905
|
/** Enable debug logging */
|
|
1906
1906
|
debug?: boolean;
|
|
1907
|
-
/** Lua script source code. When set,
|
|
1907
|
+
/** Lua script source code. When set, play requests are routed to the Vite dev server's LuaEngine. */
|
|
1908
1908
|
luaScript?: string;
|
|
1909
1909
|
/** Game definition for Lua engine (actions, transitions, etc.) */
|
|
1910
1910
|
gameDefinition?: GameDefinition;
|
|
@@ -1918,11 +1918,11 @@ interface DevBridgeConfig {
|
|
|
1918
1918
|
* `CasinoGameSDK` via a shared in-memory `MemoryChannel`, removing
|
|
1919
1919
|
* the need for postMessage and iframes.
|
|
1920
1920
|
*
|
|
1921
|
-
*
|
|
1921
|
+
* When `luaScript` is set, play requests are sent to the Vite dev server
|
|
1922
|
+
* which runs LuaEngine in Node.js — no fengari in the browser.
|
|
1922
1923
|
*
|
|
1923
1924
|
* @example
|
|
1924
1925
|
* ```ts
|
|
1925
|
-
* // In your dev entry point or vite plugin
|
|
1926
1926
|
* import { DevBridge } from '@energy8platform/game-engine/debug';
|
|
1927
1927
|
*
|
|
1928
1928
|
* const devBridge = new DevBridge({
|
|
@@ -1931,10 +1931,7 @@ interface DevBridgeConfig {
|
|
|
1931
1931
|
* gameConfig: { id: 'my-slot', type: 'slot', betLevels: [0.2, 0.5, 1, 2] },
|
|
1932
1932
|
* onPlay: ({ action, bet }) => ({
|
|
1933
1933
|
* totalWin: Math.random() > 0.5 ? bet * (Math.random() * 20) : 0,
|
|
1934
|
-
* data: {
|
|
1935
|
-
* matrix: generateRandomMatrix(5, 3, 10),
|
|
1936
|
-
* win_lines: [],
|
|
1937
|
-
* },
|
|
1934
|
+
* data: { matrix: [[1,2,3],[4,5,6],[7,8,9]] },
|
|
1938
1935
|
* }),
|
|
1939
1936
|
* });
|
|
1940
1937
|
* devBridge.start();
|
|
@@ -1945,7 +1942,7 @@ declare class DevBridge {
|
|
|
1945
1942
|
private _balance;
|
|
1946
1943
|
private _roundCounter;
|
|
1947
1944
|
private _bridge;
|
|
1948
|
-
private
|
|
1945
|
+
private _useLuaServer;
|
|
1949
1946
|
constructor(config?: DevBridgeConfig);
|
|
1950
1947
|
/** Current mock balance */
|
|
1951
1948
|
get balance(): number;
|
|
@@ -1957,9 +1954,10 @@ declare class DevBridge {
|
|
|
1957
1954
|
setBalance(balance: number): void;
|
|
1958
1955
|
/** Destroy the dev bridge */
|
|
1959
1956
|
destroy(): void;
|
|
1960
|
-
private initLuaEngine;
|
|
1961
1957
|
private handleGameReady;
|
|
1962
1958
|
private handlePlayRequest;
|
|
1959
|
+
private executeLuaOnServer;
|
|
1960
|
+
private buildFallbackResult;
|
|
1963
1961
|
private handlePlayAck;
|
|
1964
1962
|
private handleGetBalance;
|
|
1965
1963
|
private handleGetState;
|
|
@@ -1967,160 +1965,5 @@ declare class DevBridge {
|
|
|
1967
1965
|
private delayedSend;
|
|
1968
1966
|
}
|
|
1969
1967
|
|
|
1970
|
-
|
|
1971
|
-
* Runs Lua game scripts locally, replicating the platform's server-side execution.
|
|
1972
|
-
*
|
|
1973
|
-
* Implements the full lifecycle: action routing → state assembly → Lua execute() →
|
|
1974
|
-
* result extraction → transition evaluation → session management.
|
|
1975
|
-
*
|
|
1976
|
-
* @example
|
|
1977
|
-
* ```ts
|
|
1978
|
-
* const engine = new LuaEngine({
|
|
1979
|
-
* script: luaSource,
|
|
1980
|
-
* gameDefinition: { id: 'my-slot', type: 'SLOT', actions: { ... } },
|
|
1981
|
-
* });
|
|
1982
|
-
*
|
|
1983
|
-
* const result = engine.execute({ action: 'spin', bet: 1.0 });
|
|
1984
|
-
* // result.data.matrix, result.totalWin, result.nextActions, etc.
|
|
1985
|
-
* ```
|
|
1986
|
-
*/
|
|
1987
|
-
declare class LuaEngine {
|
|
1988
|
-
private L;
|
|
1989
|
-
private api;
|
|
1990
|
-
private actionRouter;
|
|
1991
|
-
private sessionManager;
|
|
1992
|
-
private persistentState;
|
|
1993
|
-
private gameDefinition;
|
|
1994
|
-
private variables;
|
|
1995
|
-
constructor(config: LuaEngineConfig);
|
|
1996
|
-
/** Current session data (if any) */
|
|
1997
|
-
get session(): SessionData | null;
|
|
1998
|
-
/** Current persistent state values */
|
|
1999
|
-
get persistentVars(): Record<string, number>;
|
|
2000
|
-
/**
|
|
2001
|
-
* Execute a play action — the main entry point.
|
|
2002
|
-
* This is what DevBridge calls on each PLAY_REQUEST.
|
|
2003
|
-
*/
|
|
2004
|
-
execute(params: PlayParams): LuaPlayResult;
|
|
2005
|
-
/** Reset all state (sessions, persistent vars, variables) */
|
|
2006
|
-
reset(): void;
|
|
2007
|
-
/** Destroy the Lua VM */
|
|
2008
|
-
destroy(): void;
|
|
2009
|
-
private loadScript;
|
|
2010
|
-
private callLuaExecute;
|
|
2011
|
-
private calculateMaxWinCap;
|
|
2012
|
-
private pickFromDistribution;
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
type RngFunction = () => number;
|
|
2016
|
-
/**
|
|
2017
|
-
* Seeded xoshiro128** PRNG for deterministic simulation/replay.
|
|
2018
|
-
* Period: 2^128 - 1
|
|
2019
|
-
*/
|
|
2020
|
-
declare function createSeededRng(seed: number): RngFunction;
|
|
2021
|
-
/**
|
|
2022
|
-
* Implements and registers all platform `engine.*` functions into a Lua state.
|
|
2023
|
-
*/
|
|
2024
|
-
declare class LuaEngineAPI {
|
|
2025
|
-
private rng;
|
|
2026
|
-
private logger;
|
|
2027
|
-
private gameDefinition;
|
|
2028
|
-
constructor(gameDefinition: GameDefinition, rng?: RngFunction, logger?: (level: string, msg: string) => void);
|
|
2029
|
-
/** Register `engine` global table on the Lua state */
|
|
2030
|
-
register(L: any): void;
|
|
2031
|
-
random(min: number, max: number): number;
|
|
2032
|
-
randomFloat(): number;
|
|
2033
|
-
randomWeighted(weights: number[]): number;
|
|
2034
|
-
shuffle<T>(arr: T[]): T[];
|
|
2035
|
-
getConfig(): Record<string, unknown>;
|
|
2036
|
-
private registerFunction;
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
interface TransitionMatch {
|
|
2040
|
-
rule: TransitionRule;
|
|
2041
|
-
nextActions: string[];
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Replicates the platform's action dispatch and transition evaluation.
|
|
2045
|
-
* Routes play requests to the correct action, evaluates transition conditions
|
|
2046
|
-
* against current variables to determine next actions and session operations.
|
|
2047
|
-
*/
|
|
2048
|
-
declare class ActionRouter {
|
|
2049
|
-
private actions;
|
|
2050
|
-
constructor(gameDefinition: GameDefinition);
|
|
2051
|
-
/** Look up action by name and validate prerequisites */
|
|
2052
|
-
resolveAction(actionName: string, hasSession: boolean): ActionDefinition;
|
|
2053
|
-
/** Evaluate transitions in order, return the first matching rule */
|
|
2054
|
-
evaluateTransitions(action: ActionDefinition, variables: Record<string, number>): TransitionMatch;
|
|
2055
|
-
}
|
|
2056
|
-
/**
|
|
2057
|
-
* Evaluates a transition condition expression against variables.
|
|
2058
|
-
*
|
|
2059
|
-
* Supports:
|
|
2060
|
-
* - "always" → true
|
|
2061
|
-
* - Simple comparisons: "var > 0", "var == 1", "var >= 10", "var != 0", "var < 5", "var <= 3"
|
|
2062
|
-
* - Logical connectives: "expr && expr", "expr || expr"
|
|
2063
|
-
*
|
|
2064
|
-
* This covers all patterns used by the platform's govaluate conditions.
|
|
2065
|
-
*/
|
|
2066
|
-
declare function evaluateCondition(condition: string, variables: Record<string, number>): boolean;
|
|
2067
|
-
|
|
2068
|
-
/**
|
|
2069
|
-
* Manages session lifecycle: creation, spin counting, retriggers, and completion.
|
|
2070
|
-
* Handles both slot sessions (fixed spin count) and table game sessions (unlimited).
|
|
2071
|
-
* Also manages _persist_ data roundtrip between Lua calls.
|
|
2072
|
-
*/
|
|
2073
|
-
declare class SessionManager {
|
|
2074
|
-
private session;
|
|
2075
|
-
get isActive(): boolean;
|
|
2076
|
-
get current(): SessionData | null;
|
|
2077
|
-
get sessionTotalWin(): number;
|
|
2078
|
-
/** Create a new session from a transition rule */
|
|
2079
|
-
createSession(rule: TransitionRule, variables: Record<string, number>, bet: number): SessionData;
|
|
2080
|
-
/** Update session after a spin: decrement counter, accumulate win, handle retrigger */
|
|
2081
|
-
updateSession(rule: TransitionRule, variables: Record<string, number>, spinWin: number): SessionData;
|
|
2082
|
-
/** Complete the session, return accumulated totalWin */
|
|
2083
|
-
completeSession(): {
|
|
2084
|
-
totalWin: number;
|
|
2085
|
-
session: SessionData;
|
|
2086
|
-
};
|
|
2087
|
-
/** Mark max win reached — stops the session */
|
|
2088
|
-
markMaxWinReached(): void;
|
|
2089
|
-
/** Store _persist_* data extracted from Lua result */
|
|
2090
|
-
storePersistData(data: Record<string, unknown>): void;
|
|
2091
|
-
/** Get _ps_* params to inject into next execute() call */
|
|
2092
|
-
getPersistentParams(): Record<string, unknown>;
|
|
2093
|
-
/** Reset all session state */
|
|
2094
|
-
reset(): void;
|
|
2095
|
-
private toSessionData;
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
/**
|
|
2099
|
-
* Manages cross-spin persistent state — variables that survive between base game spins.
|
|
2100
|
-
* Separate from session-scoped persistence (handled by SessionManager).
|
|
2101
|
-
*
|
|
2102
|
-
* Handles two mechanisms:
|
|
2103
|
-
* 1. Numeric vars declared in `persistent_state.vars` — stored in state.variables
|
|
2104
|
-
* 2. Complex data with `_persist_game_*` prefix — stored separately, injected as `_ps_*`
|
|
2105
|
-
*/
|
|
2106
|
-
declare class PersistentState {
|
|
2107
|
-
private config;
|
|
2108
|
-
private vars;
|
|
2109
|
-
private gameData;
|
|
2110
|
-
constructor(config?: PersistentStateConfig);
|
|
2111
|
-
/** Load persistent vars into variables map before execute() */
|
|
2112
|
-
loadIntoVariables(variables: Record<string, number>): void;
|
|
2113
|
-
/** Save persistent vars from variables map after execute() */
|
|
2114
|
-
saveFromVariables(variables: Record<string, number>): void;
|
|
2115
|
-
/** Extract _persist_game_* keys from Lua return data, store them */
|
|
2116
|
-
storeGameData(data: Record<string, unknown>): void;
|
|
2117
|
-
/** Get _ps_* params for next execute() call */
|
|
2118
|
-
getGameDataParams(): Record<string, unknown>;
|
|
2119
|
-
/** Get exposed vars for client data.persistent_state */
|
|
2120
|
-
getExposedVars(): Record<string, number> | undefined;
|
|
2121
|
-
/** Reset all state */
|
|
2122
|
-
reset(): void;
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
export { ActionRouter, AssetManager, AudioManager, BalanceDisplay, Button, DevBridge, Easing, EventEmitter, FPSOverlay, GameApplication, InputManager, Label, Layout, LoadingScene, LuaEngine, LuaEngineAPI, Modal, Orientation, Panel, PersistentState, ProgressBar, ScaleMode, Scene, SceneManager, ScrollContainer, SessionManager, SpineHelper, SpriteAnimation, StateMachine, Timeline, Toast, TransitionType, Tween, ViewportManager, WinDisplay, createSeededRng, evaluateCondition };
|
|
1968
|
+
export { AssetManager, AudioManager, BalanceDisplay, Button, DevBridge, Easing, EventEmitter, FPSOverlay, GameApplication, InputManager, Label, Layout, LoadingScene, Modal, Orientation, Panel, ProgressBar, ScaleMode, Scene, SceneManager, ScrollContainer, SpineHelper, SpriteAnimation, StateMachine, Timeline, Toast, TransitionType, Tween, ViewportManager, WinDisplay };
|
|
2126
1969
|
export type { ActionDefinition, AssetBundle, AssetEntry, AssetManifest, AudioConfig, BalanceDisplayConfig, ButtonConfig, ButtonState, DevBridgeConfig, EasingFunction, GameApplicationConfig, GameDefinition, GameEngineEvents, IScene, LabelConfig, LayoutAlignment, LayoutAnchor, LayoutConfig, LayoutDirection, LoadingScreenConfig, LuaEngineConfig, LuaPlayResult, ModalConfig, PanelConfig, ProgressBarConfig, SceneConstructor, ScrollContainerConfig, ScrollDirection, SpriteAnimationConfig, ToastConfig, ToastType, TransitionConfig, TransitionRule, TweenOptions, WinDisplayConfig };
|