@energy8platform/game-engine 0.15.2 → 0.16.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 +22 -12
- package/dist/assets.d.ts +2 -14
- package/dist/core.cjs.js +16 -201
- package/dist/core.cjs.js.map +1 -1
- package/dist/core.d.ts +4 -35
- package/dist/core.esm.js +12 -197
- package/dist/core.esm.js.map +1 -1
- package/dist/debug.cjs.js +5 -233
- package/dist/debug.cjs.js.map +1 -1
- package/dist/debug.d.ts +2 -140
- package/dist/debug.esm.js +2 -233
- package/dist/debug.esm.js.map +1 -1
- package/dist/index.cjs.js +21 -432
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +10 -195
- package/dist/index.esm.js +14 -429
- package/dist/index.esm.js.map +1 -1
- package/dist/lua.cjs.js +7 -1493
- package/dist/lua.cjs.js.map +1 -1
- package/dist/lua.d.ts +1 -403
- package/dist/lua.esm.js +1 -1483
- package/dist/lua.esm.js.map +1 -1
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.d.ts +4 -35
- package/dist/react.esm.js.map +1 -1
- package/dist/vite.cjs.js +19 -175
- package/dist/vite.cjs.js.map +1 -1
- package/dist/vite.d.ts +8 -3
- package/dist/vite.esm.js +10 -173
- package/dist/vite.esm.js.map +1 -1
- package/package.json +6 -16
- package/src/core/GameApplication.ts +14 -18
- package/src/debug/index.ts +4 -2
- package/src/index.ts +3 -3
- package/src/loading/LoadingScene.ts +1 -1
- package/src/loading/index.ts +9 -2
- package/src/lua/index.ts +3 -31
- package/src/types.ts +16 -41
- package/src/vite/index.ts +13 -196
- package/bin/simulate.ts +0 -139
- package/scripts/install-simulate.mjs +0 -101
- package/src/debug/DevBridge.ts +0 -305
- package/src/loading/CSSPreloader.ts +0 -129
- package/src/loading/logo.ts +0 -95
- package/src/lua/ActionRouter.ts +0 -132
- package/src/lua/LuaEngine.ts +0 -412
- package/src/lua/LuaEngineAPI.ts +0 -314
- package/src/lua/NativeSimulationRunner.ts +0 -367
- package/src/lua/ParallelSimulationRunner.ts +0 -156
- package/src/lua/PersistentState.ts +0 -80
- package/src/lua/SessionManager.ts +0 -227
- package/src/lua/SimulationRunner.ts +0 -192
- package/src/lua/SimulationWorker.ts +0 -44
- package/src/lua/fengari.d.ts +0 -10
- package/src/lua/types.ts +0 -149
package/dist/vite.cjs.js
CHANGED
|
@@ -1,184 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vite plugin that auto-injects the DevBridge script into the
|
|
6
|
-
* HTML during development, so the game can communicate with a
|
|
7
|
-
* mock casino host without manual setup.
|
|
8
|
-
*/
|
|
9
|
-
const VIRTUAL_ID = '/@dev-bridge-entry.js';
|
|
10
|
-
function devBridgePlugin(configPath) {
|
|
11
|
-
let entrySrc = '';
|
|
12
|
-
let viteRoot = '';
|
|
13
|
-
let resolvedConfigPath = configPath;
|
|
14
|
-
return {
|
|
15
|
-
name: 'game-engine:dev-bridge',
|
|
16
|
-
apply: 'serve', // dev only
|
|
17
|
-
enforce: 'pre',
|
|
18
|
-
configResolved(config) {
|
|
19
|
-
viteRoot = config.root;
|
|
20
|
-
// Resolve relative config path against Vite root so the virtual
|
|
21
|
-
// module can import it with an absolute path.
|
|
22
|
-
if (configPath.startsWith('.')) {
|
|
23
|
-
resolvedConfigPath = config.root + '/' + configPath.replace(/^\.\//, '');
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
resolveId(id) {
|
|
27
|
-
if (id === VIRTUAL_ID)
|
|
28
|
-
return id;
|
|
29
|
-
},
|
|
30
|
-
load(id) {
|
|
31
|
-
if (id === VIRTUAL_ID) {
|
|
32
|
-
// This goes through Vite's pipeline so bare imports are resolved
|
|
33
|
-
return `
|
|
34
|
-
import { DevBridge } from '@energy8platform/game-engine/debug';
|
|
3
|
+
var vite = require('@energy8platform/platform-core/vite');
|
|
35
4
|
|
|
36
|
-
try {
|
|
37
|
-
const mod = await import('${resolvedConfigPath}');
|
|
38
|
-
const config = mod.default ?? mod.config ?? mod;
|
|
39
|
-
new DevBridge(config).start();
|
|
40
|
-
} catch (e) {
|
|
41
|
-
console.warn('[DevBridge] Failed to load config:', e);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await import('${entrySrc}');
|
|
45
|
-
`;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
transformIndexHtml(html) {
|
|
49
|
-
// Find the app's entry module script (skip Vite internal /@... scripts)
|
|
50
|
-
const scriptRegex = /<script\s+type="module"\s+src="((?!\/@)[^"]+)"\s*>\s*<\/script>/;
|
|
51
|
-
const match = html.match(scriptRegex);
|
|
52
|
-
if (!match) {
|
|
53
|
-
console.warn('[DevBridge] Could not find entry module script in index.html');
|
|
54
|
-
return html;
|
|
55
|
-
}
|
|
56
|
-
entrySrc = match[1];
|
|
57
|
-
if (entrySrc.startsWith('.')) {
|
|
58
|
-
entrySrc = viteRoot + '/' + entrySrc.replace(/^\.\//, '');
|
|
59
|
-
}
|
|
60
|
-
else if (entrySrc.startsWith('/')) {
|
|
61
|
-
entrySrc = viteRoot + entrySrc;
|
|
62
|
-
}
|
|
63
|
-
return html.replace(match[0], `<script type="module" src="${VIRTUAL_ID}"></script>`);
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
// ─── Lua Plugin ─────────────────────────────────────────
|
|
68
|
-
/**
|
|
69
|
-
* Vite plugin that:
|
|
70
|
-
* 1. Enables importing `.lua` files as raw strings with HMR
|
|
71
|
-
* 2. Runs a LuaEngine on the Vite dev server (Node.js) via `POST /__lua-play`
|
|
72
|
-
*
|
|
73
|
-
* fengari runs server-side only — no browser shims needed.
|
|
74
|
-
*/
|
|
75
|
-
function luaPlugin(configPath) {
|
|
76
|
-
let luaEngine = null;
|
|
77
|
-
let viteServer = null;
|
|
78
|
-
async function initEngine() {
|
|
79
|
-
if (!viteServer)
|
|
80
|
-
return;
|
|
81
|
-
try {
|
|
82
|
-
// Invalidate cached modules so HMR picks up changes
|
|
83
|
-
const root = viteServer.config.root;
|
|
84
|
-
const fullConfigPath = configPath.startsWith('.')
|
|
85
|
-
? root + '/' + configPath.replace(/^\.\//, '')
|
|
86
|
-
: configPath;
|
|
87
|
-
// Invalidate the config module and its dependencies
|
|
88
|
-
const configMod = viteServer.moduleGraph.getModuleById(fullConfigPath);
|
|
89
|
-
if (configMod)
|
|
90
|
-
viteServer.moduleGraph.invalidateModule(configMod);
|
|
91
|
-
// ssrLoadModule handles TS transpilation and resolves all imports
|
|
92
|
-
const mod = await viteServer.ssrLoadModule(fullConfigPath);
|
|
93
|
-
const config = mod.default ?? mod.config ?? mod;
|
|
94
|
-
if (!config.luaScript || !config.gameDefinition) {
|
|
95
|
-
console.log('[LuaPlugin] No luaScript/gameDefinition in config — Lua server disabled');
|
|
96
|
-
luaEngine = null;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
// Load LuaEngine via SSR (fengari runs natively in Node.js)
|
|
100
|
-
const luaMod = await viteServer.ssrLoadModule('@energy8platform/game-engine/lua');
|
|
101
|
-
const { LuaEngine } = luaMod;
|
|
102
|
-
if (luaEngine)
|
|
103
|
-
luaEngine.destroy();
|
|
104
|
-
luaEngine = new LuaEngine({
|
|
105
|
-
script: config.luaScript,
|
|
106
|
-
gameDefinition: config.gameDefinition,
|
|
107
|
-
seed: config.luaSeed,
|
|
108
|
-
});
|
|
109
|
-
console.log('[LuaPlugin] LuaEngine initialized (server-side)');
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
console.warn('[LuaPlugin] Failed to initialize LuaEngine:', e.message);
|
|
113
|
-
luaEngine = null;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
name: 'game-engine:lua',
|
|
118
|
-
apply: 'serve',
|
|
119
|
-
async configureServer(server) {
|
|
120
|
-
viteServer = server;
|
|
121
|
-
await initEngine();
|
|
122
|
-
// POST /__lua-play — execute Lua on the server
|
|
123
|
-
server.middlewares.use('/__lua-play', (req, res) => {
|
|
124
|
-
if (req.method !== 'POST') {
|
|
125
|
-
res.statusCode = 405;
|
|
126
|
-
res.end('Method Not Allowed');
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
let body = '';
|
|
130
|
-
req.on('data', (chunk) => { body += chunk; });
|
|
131
|
-
req.on('end', () => {
|
|
132
|
-
try {
|
|
133
|
-
if (!luaEngine) {
|
|
134
|
-
res.statusCode = 503;
|
|
135
|
-
res.setHeader('Content-Type', 'application/json');
|
|
136
|
-
res.end(JSON.stringify({ error: 'LuaEngine not initialized' }));
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const params = JSON.parse(body);
|
|
140
|
-
const result = luaEngine.execute(params);
|
|
141
|
-
res.statusCode = 200;
|
|
142
|
-
res.setHeader('Content-Type', 'application/json');
|
|
143
|
-
res.end(JSON.stringify(result));
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
res.statusCode = 500;
|
|
147
|
-
res.setHeader('Content-Type', 'application/json');
|
|
148
|
-
res.end(JSON.stringify({ error: e.message }));
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
transform(code, id) {
|
|
154
|
-
if (id.endsWith('.lua')) {
|
|
155
|
-
return {
|
|
156
|
-
code: `export default ${JSON.stringify(code)};`,
|
|
157
|
-
map: null,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
async handleHotUpdate({ file, server }) {
|
|
162
|
-
if (file.endsWith('.lua') || file.includes('dev.config')) {
|
|
163
|
-
console.log('[LuaPlugin] Reloading LuaEngine...');
|
|
164
|
-
// Invalidate all SSR modules so ssrLoadModule picks up fresh code
|
|
165
|
-
server.moduleGraph.invalidateAll();
|
|
166
|
-
await initEngine();
|
|
167
|
-
server.ws.send({ type: 'full-reload' });
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
5
|
// ─── defineGameConfig ────────────────────────────────────
|
|
174
6
|
/**
|
|
175
|
-
* Define a Vite configuration tailored for Energy8 casino games
|
|
7
|
+
* Define a Vite configuration tailored for Energy8 casino games on
|
|
8
|
+
* @energy8platform/game-engine (PixiJS).
|
|
176
9
|
*
|
|
177
10
|
* Merges sensible defaults for iGaming projects:
|
|
178
11
|
* - Build target: ESNext
|
|
179
12
|
* - Asset inlining threshold: 8KB
|
|
180
|
-
* -
|
|
181
|
-
* - Optional DevBridge auto-injection in dev mode
|
|
13
|
+
* - PixiJS-specific dedupe / chunk splitting / prebundle hints
|
|
14
|
+
* - Optional DevBridge auto-injection in dev mode (with Lua engine)
|
|
15
|
+
*
|
|
16
|
+
* For Phaser/Three/custom engines, import the bare plugins directly
|
|
17
|
+
* from `@energy8platform/platform-core/vite` and write your own config.
|
|
182
18
|
*
|
|
183
19
|
* @example
|
|
184
20
|
* ```ts
|
|
@@ -195,12 +31,12 @@ function defineGameConfig(config = {}) {
|
|
|
195
31
|
const plugins = [];
|
|
196
32
|
if (config.devBridge) {
|
|
197
33
|
const configPath = config.devBridgeConfig ?? './dev.config';
|
|
198
|
-
plugins.push(devBridgePlugin(configPath));
|
|
199
|
-
plugins.push(luaPlugin(configPath));
|
|
34
|
+
plugins.push(vite.devBridgePlugin(configPath));
|
|
35
|
+
plugins.push(vite.luaPlugin(configPath));
|
|
200
36
|
}
|
|
201
37
|
const userVite = config.vite ?? {};
|
|
202
38
|
return {
|
|
203
|
-
base: config.base ?? '
|
|
39
|
+
base: config.base ?? './',
|
|
204
40
|
plugins: [
|
|
205
41
|
...plugins,
|
|
206
42
|
...(userVite.plugins ?? []),
|
|
@@ -249,5 +85,13 @@ function defineGameConfig(config = {}) {
|
|
|
249
85
|
};
|
|
250
86
|
}
|
|
251
87
|
|
|
88
|
+
Object.defineProperty(exports, "devBridgePlugin", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return vite.devBridgePlugin; }
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "luaPlugin", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () { return vite.luaPlugin; }
|
|
95
|
+
});
|
|
252
96
|
exports.defineGameConfig = defineGameConfig;
|
|
253
97
|
//# sourceMappingURL=vite.cjs.js.map
|
package/dist/vite.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs.js","sources":["../src/vite/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.cjs.js","sources":["../src/vite/index.ts"],"sourcesContent":[null],"names":["devBridgePlugin","luaPlugin"],"mappings":";;;;AAuBA;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,SAAU,gBAAgB,CAAC,MAAA,GAAqB,EAAE,EAAA;IACtD,MAAM,OAAO,GAAa,EAAE;AAE5B,IAAA,IAAI,MAAM,CAAC,SAAS,EAAE;AACpB,QAAA,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,IAAI,cAAc;QAC3D,OAAO,CAAC,IAAI,CAACA,oBAAe,CAAC,UAAU,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAACC,cAAS,CAAC,UAAU,CAAC,CAAC;IACrC;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;AAEzB,QAAA,OAAO,EAAE;AACP,YAAA,GAAG,OAAO;AACV,YAAA,IAAK,QAAQ,CAAC,OAAoB,IAAI,EAAE,CAAC;AAC1C,SAAA;AAED,QAAA,KAAK,EAAE;AACL,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,iBAAiB,EAAE,IAAI;AACvB,YAAA,SAAS,EAAE,KAAK;AAChB,YAAA,aAAa,EAAE;AACb,gBAAA,MAAM,EAAE;AACN,oBAAA,YAAY,EAAE;wBACZ,IAAI,EAAE,CAAC,SAAS,CAAC;AAClB,qBAAA;AACF,iBAAA;AACF,aAAA;YACD,GAAG,QAAQ,CAAC,KAAK;AAClB,SAAA;AAED,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,IAAI;AACV,YAAA,IAAI,EAAE,IAAI;YACV,GAAG,QAAQ,CAAC,MAAM;AACnB,SAAA;AAED,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE;gBACN,SAAS;gBACT,OAAO;gBACP,WAAW;gBACX,kBAAkB;AACnB,aAAA;YACD,GAAG,QAAQ,CAAC,OAAO;AACpB,SAAA;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,OAAO,EAAE;gBACP,SAAS;gBACT,OAAO;gBACP,WAAW;AACZ,aAAA;AACD,YAAA,OAAO,EAAE;gBACP,SAAS;AACV,aAAA;AACD,YAAA,cAAc,EAAE;AACd,gBAAA,MAAM,EAAE,QAAQ;AACjB,aAAA;YACD,GAAG,QAAQ,CAAC,YAAY;AACzB,SAAA;KACF;AACH;;;;;;;;;;;;"}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UserConfig } from 'vite';
|
|
2
|
+
export { devBridgePlugin, luaPlugin } from '@energy8platform/platform-core/vite';
|
|
2
3
|
|
|
3
4
|
interface GameConfig {
|
|
4
5
|
/** Vite `base` path for deployment (default: '/') */
|
|
@@ -11,13 +12,17 @@ interface GameConfig {
|
|
|
11
12
|
vite?: UserConfig;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
|
-
* Define a Vite configuration tailored for Energy8 casino games
|
|
15
|
+
* Define a Vite configuration tailored for Energy8 casino games on
|
|
16
|
+
* @energy8platform/game-engine (PixiJS).
|
|
15
17
|
*
|
|
16
18
|
* Merges sensible defaults for iGaming projects:
|
|
17
19
|
* - Build target: ESNext
|
|
18
20
|
* - Asset inlining threshold: 8KB
|
|
19
|
-
* -
|
|
20
|
-
* - Optional DevBridge auto-injection in dev mode
|
|
21
|
+
* - PixiJS-specific dedupe / chunk splitting / prebundle hints
|
|
22
|
+
* - Optional DevBridge auto-injection in dev mode (with Lua engine)
|
|
23
|
+
*
|
|
24
|
+
* For Phaser/Three/custom engines, import the bare plugins directly
|
|
25
|
+
* from `@energy8platform/platform-core/vite` and write your own config.
|
|
21
26
|
*
|
|
22
27
|
* @example
|
|
23
28
|
* ```ts
|
package/dist/vite.esm.js
CHANGED
|
@@ -1,182 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Vite plugin that auto-injects the DevBridge script into the
|
|
4
|
-
* HTML during development, so the game can communicate with a
|
|
5
|
-
* mock casino host without manual setup.
|
|
6
|
-
*/
|
|
7
|
-
const VIRTUAL_ID = '/@dev-bridge-entry.js';
|
|
8
|
-
function devBridgePlugin(configPath) {
|
|
9
|
-
let entrySrc = '';
|
|
10
|
-
let viteRoot = '';
|
|
11
|
-
let resolvedConfigPath = configPath;
|
|
12
|
-
return {
|
|
13
|
-
name: 'game-engine:dev-bridge',
|
|
14
|
-
apply: 'serve', // dev only
|
|
15
|
-
enforce: 'pre',
|
|
16
|
-
configResolved(config) {
|
|
17
|
-
viteRoot = config.root;
|
|
18
|
-
// Resolve relative config path against Vite root so the virtual
|
|
19
|
-
// module can import it with an absolute path.
|
|
20
|
-
if (configPath.startsWith('.')) {
|
|
21
|
-
resolvedConfigPath = config.root + '/' + configPath.replace(/^\.\//, '');
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
resolveId(id) {
|
|
25
|
-
if (id === VIRTUAL_ID)
|
|
26
|
-
return id;
|
|
27
|
-
},
|
|
28
|
-
load(id) {
|
|
29
|
-
if (id === VIRTUAL_ID) {
|
|
30
|
-
// This goes through Vite's pipeline so bare imports are resolved
|
|
31
|
-
return `
|
|
32
|
-
import { DevBridge } from '@energy8platform/game-engine/debug';
|
|
1
|
+
import { devBridgePlugin, luaPlugin } from '@energy8platform/platform-core/vite';
|
|
2
|
+
export { devBridgePlugin, luaPlugin } from '@energy8platform/platform-core/vite';
|
|
33
3
|
|
|
34
|
-
try {
|
|
35
|
-
const mod = await import('${resolvedConfigPath}');
|
|
36
|
-
const config = mod.default ?? mod.config ?? mod;
|
|
37
|
-
new DevBridge(config).start();
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.warn('[DevBridge] Failed to load config:', e);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await import('${entrySrc}');
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
transformIndexHtml(html) {
|
|
47
|
-
// Find the app's entry module script (skip Vite internal /@... scripts)
|
|
48
|
-
const scriptRegex = /<script\s+type="module"\s+src="((?!\/@)[^"]+)"\s*>\s*<\/script>/;
|
|
49
|
-
const match = html.match(scriptRegex);
|
|
50
|
-
if (!match) {
|
|
51
|
-
console.warn('[DevBridge] Could not find entry module script in index.html');
|
|
52
|
-
return html;
|
|
53
|
-
}
|
|
54
|
-
entrySrc = match[1];
|
|
55
|
-
if (entrySrc.startsWith('.')) {
|
|
56
|
-
entrySrc = viteRoot + '/' + entrySrc.replace(/^\.\//, '');
|
|
57
|
-
}
|
|
58
|
-
else if (entrySrc.startsWith('/')) {
|
|
59
|
-
entrySrc = viteRoot + entrySrc;
|
|
60
|
-
}
|
|
61
|
-
return html.replace(match[0], `<script type="module" src="${VIRTUAL_ID}"></script>`);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
// ─── Lua Plugin ─────────────────────────────────────────
|
|
66
|
-
/**
|
|
67
|
-
* Vite plugin that:
|
|
68
|
-
* 1. Enables importing `.lua` files as raw strings with HMR
|
|
69
|
-
* 2. Runs a LuaEngine on the Vite dev server (Node.js) via `POST /__lua-play`
|
|
70
|
-
*
|
|
71
|
-
* fengari runs server-side only — no browser shims needed.
|
|
72
|
-
*/
|
|
73
|
-
function luaPlugin(configPath) {
|
|
74
|
-
let luaEngine = null;
|
|
75
|
-
let viteServer = null;
|
|
76
|
-
async function initEngine() {
|
|
77
|
-
if (!viteServer)
|
|
78
|
-
return;
|
|
79
|
-
try {
|
|
80
|
-
// Invalidate cached modules so HMR picks up changes
|
|
81
|
-
const root = viteServer.config.root;
|
|
82
|
-
const fullConfigPath = configPath.startsWith('.')
|
|
83
|
-
? root + '/' + configPath.replace(/^\.\//, '')
|
|
84
|
-
: configPath;
|
|
85
|
-
// Invalidate the config module and its dependencies
|
|
86
|
-
const configMod = viteServer.moduleGraph.getModuleById(fullConfigPath);
|
|
87
|
-
if (configMod)
|
|
88
|
-
viteServer.moduleGraph.invalidateModule(configMod);
|
|
89
|
-
// ssrLoadModule handles TS transpilation and resolves all imports
|
|
90
|
-
const mod = await viteServer.ssrLoadModule(fullConfigPath);
|
|
91
|
-
const config = mod.default ?? mod.config ?? mod;
|
|
92
|
-
if (!config.luaScript || !config.gameDefinition) {
|
|
93
|
-
console.log('[LuaPlugin] No luaScript/gameDefinition in config — Lua server disabled');
|
|
94
|
-
luaEngine = null;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
// Load LuaEngine via SSR (fengari runs natively in Node.js)
|
|
98
|
-
const luaMod = await viteServer.ssrLoadModule('@energy8platform/game-engine/lua');
|
|
99
|
-
const { LuaEngine } = luaMod;
|
|
100
|
-
if (luaEngine)
|
|
101
|
-
luaEngine.destroy();
|
|
102
|
-
luaEngine = new LuaEngine({
|
|
103
|
-
script: config.luaScript,
|
|
104
|
-
gameDefinition: config.gameDefinition,
|
|
105
|
-
seed: config.luaSeed,
|
|
106
|
-
});
|
|
107
|
-
console.log('[LuaPlugin] LuaEngine initialized (server-side)');
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.warn('[LuaPlugin] Failed to initialize LuaEngine:', e.message);
|
|
111
|
-
luaEngine = null;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
name: 'game-engine:lua',
|
|
116
|
-
apply: 'serve',
|
|
117
|
-
async configureServer(server) {
|
|
118
|
-
viteServer = server;
|
|
119
|
-
await initEngine();
|
|
120
|
-
// POST /__lua-play — execute Lua on the server
|
|
121
|
-
server.middlewares.use('/__lua-play', (req, res) => {
|
|
122
|
-
if (req.method !== 'POST') {
|
|
123
|
-
res.statusCode = 405;
|
|
124
|
-
res.end('Method Not Allowed');
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let body = '';
|
|
128
|
-
req.on('data', (chunk) => { body += chunk; });
|
|
129
|
-
req.on('end', () => {
|
|
130
|
-
try {
|
|
131
|
-
if (!luaEngine) {
|
|
132
|
-
res.statusCode = 503;
|
|
133
|
-
res.setHeader('Content-Type', 'application/json');
|
|
134
|
-
res.end(JSON.stringify({ error: 'LuaEngine not initialized' }));
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const params = JSON.parse(body);
|
|
138
|
-
const result = luaEngine.execute(params);
|
|
139
|
-
res.statusCode = 200;
|
|
140
|
-
res.setHeader('Content-Type', 'application/json');
|
|
141
|
-
res.end(JSON.stringify(result));
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
res.statusCode = 500;
|
|
145
|
-
res.setHeader('Content-Type', 'application/json');
|
|
146
|
-
res.end(JSON.stringify({ error: e.message }));
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
transform(code, id) {
|
|
152
|
-
if (id.endsWith('.lua')) {
|
|
153
|
-
return {
|
|
154
|
-
code: `export default ${JSON.stringify(code)};`,
|
|
155
|
-
map: null,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
async handleHotUpdate({ file, server }) {
|
|
160
|
-
if (file.endsWith('.lua') || file.includes('dev.config')) {
|
|
161
|
-
console.log('[LuaPlugin] Reloading LuaEngine...');
|
|
162
|
-
// Invalidate all SSR modules so ssrLoadModule picks up fresh code
|
|
163
|
-
server.moduleGraph.invalidateAll();
|
|
164
|
-
await initEngine();
|
|
165
|
-
server.ws.send({ type: 'full-reload' });
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
4
|
// ─── defineGameConfig ────────────────────────────────────
|
|
172
5
|
/**
|
|
173
|
-
* Define a Vite configuration tailored for Energy8 casino games
|
|
6
|
+
* Define a Vite configuration tailored for Energy8 casino games on
|
|
7
|
+
* @energy8platform/game-engine (PixiJS).
|
|
174
8
|
*
|
|
175
9
|
* Merges sensible defaults for iGaming projects:
|
|
176
10
|
* - Build target: ESNext
|
|
177
11
|
* - Asset inlining threshold: 8KB
|
|
178
|
-
* -
|
|
179
|
-
* - Optional DevBridge auto-injection in dev mode
|
|
12
|
+
* - PixiJS-specific dedupe / chunk splitting / prebundle hints
|
|
13
|
+
* - Optional DevBridge auto-injection in dev mode (with Lua engine)
|
|
14
|
+
*
|
|
15
|
+
* For Phaser/Three/custom engines, import the bare plugins directly
|
|
16
|
+
* from `@energy8platform/platform-core/vite` and write your own config.
|
|
180
17
|
*
|
|
181
18
|
* @example
|
|
182
19
|
* ```ts
|
|
@@ -198,7 +35,7 @@ function defineGameConfig(config = {}) {
|
|
|
198
35
|
}
|
|
199
36
|
const userVite = config.vite ?? {};
|
|
200
37
|
return {
|
|
201
|
-
base: config.base ?? '
|
|
38
|
+
base: config.base ?? './',
|
|
202
39
|
plugins: [
|
|
203
40
|
...plugins,
|
|
204
41
|
...(userVite.plugins ?? []),
|
package/dist/vite.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.esm.js","sources":["../src/vite/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.esm.js","sources":["../src/vite/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAuBA;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,SAAU,gBAAgB,CAAC,MAAA,GAAqB,EAAE,EAAA;IACtD,MAAM,OAAO,GAAa,EAAE;AAE5B,IAAA,IAAI,MAAM,CAAC,SAAS,EAAE;AACpB,QAAA,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,IAAI,cAAc;QAC3D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACrC;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE;IAElC,OAAO;AACL,QAAA,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;AAEzB,QAAA,OAAO,EAAE;AACP,YAAA,GAAG,OAAO;AACV,YAAA,IAAK,QAAQ,CAAC,OAAoB,IAAI,EAAE,CAAC;AAC1C,SAAA;AAED,QAAA,KAAK,EAAE;AACL,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,iBAAiB,EAAE,IAAI;AACvB,YAAA,SAAS,EAAE,KAAK;AAChB,YAAA,aAAa,EAAE;AACb,gBAAA,MAAM,EAAE;AACN,oBAAA,YAAY,EAAE;wBACZ,IAAI,EAAE,CAAC,SAAS,CAAC;AAClB,qBAAA;AACF,iBAAA;AACF,aAAA;YACD,GAAG,QAAQ,CAAC,KAAK;AAClB,SAAA;AAED,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,IAAI;AACV,YAAA,IAAI,EAAE,IAAI;YACV,GAAG,QAAQ,CAAC,MAAM;AACnB,SAAA;AAED,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE;gBACN,SAAS;gBACT,OAAO;gBACP,WAAW;gBACX,kBAAkB;AACnB,aAAA;YACD,GAAG,QAAQ,CAAC,OAAO;AACpB,SAAA;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,OAAO,EAAE;gBACP,SAAS;gBACT,OAAO;gBACP,WAAW;AACZ,aAAA;AACD,YAAA,OAAO,EAAE;gBACP,SAAS;AACV,aAAA;AACD,YAAA,cAAc,EAAE;AACd,gBAAA,MAAM,EAAE,QAAQ;AACjB,aAAA;YACD,GAAG,QAAQ,CAAC,YAAY;AACzB,SAAA;KACF;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@energy8platform/game-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Universal casino game engine built on PixiJS v8 and @energy8platform/game-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
7
7
|
"module": "./dist/index.esm.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"bin": {
|
|
10
|
-
"game-engine-simulate": "./bin/simulate.ts"
|
|
11
|
-
},
|
|
12
9
|
"exports": {
|
|
13
10
|
".": {
|
|
14
11
|
"import": "./dist/index.esm.js",
|
|
@@ -68,12 +65,9 @@
|
|
|
68
65
|
},
|
|
69
66
|
"files": [
|
|
70
67
|
"dist",
|
|
71
|
-
"src"
|
|
72
|
-
"bin/simulate.ts",
|
|
73
|
-
"scripts"
|
|
68
|
+
"src"
|
|
74
69
|
],
|
|
75
70
|
"scripts": {
|
|
76
|
-
"simulate": "tsx bin/simulate.ts",
|
|
77
71
|
"build": "rollup -c rollup.config.mjs",
|
|
78
72
|
"dev": "rollup -c rollup.config.mjs -w",
|
|
79
73
|
"lint": "eslint src/ --ext .ts",
|
|
@@ -81,12 +75,13 @@
|
|
|
81
75
|
"typecheck": "tsc --noEmit",
|
|
82
76
|
"test": "vitest run",
|
|
83
77
|
"test:watch": "vitest",
|
|
84
|
-
"postinstall": "node scripts/install-simulate.mjs",
|
|
85
78
|
"prepublishOnly": "npm run build"
|
|
86
79
|
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"@energy8platform/platform-core": "*"
|
|
82
|
+
},
|
|
87
83
|
"peerDependencies": {
|
|
88
84
|
"@energy8platform/game-sdk": "^2.7.0",
|
|
89
|
-
"fengari": "^0.1.4",
|
|
90
85
|
"pixi.js": "^8.16.0",
|
|
91
86
|
"react": ">=18.0.0",
|
|
92
87
|
"react-dom": ">=18.0.0",
|
|
@@ -107,9 +102,6 @@
|
|
|
107
102
|
},
|
|
108
103
|
"react-reconciler": {
|
|
109
104
|
"optional": true
|
|
110
|
-
},
|
|
111
|
-
"fengari": {
|
|
112
|
-
"optional": true
|
|
113
105
|
}
|
|
114
106
|
},
|
|
115
107
|
"devDependencies": {
|
|
@@ -120,11 +112,10 @@
|
|
|
120
112
|
"@types/node": "^25.6.0",
|
|
121
113
|
"@types/react": "^19.0.0",
|
|
122
114
|
"@types/react-dom": "^19.0.0",
|
|
115
|
+
"@types/react-reconciler": "^0.31.0",
|
|
123
116
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
124
117
|
"@typescript-eslint/parser": "^8.0.0",
|
|
125
118
|
"eslint": "^9.0.0",
|
|
126
|
-
"fengari": "^0.1.5",
|
|
127
|
-
"fengari-web": "^0.1.4",
|
|
128
119
|
"pixi.js": "^8.16.0",
|
|
129
120
|
"prettier": "^3.4.0",
|
|
130
121
|
"react": "^19.0.0",
|
|
@@ -133,7 +124,6 @@
|
|
|
133
124
|
"rollup": "^4.24.0",
|
|
134
125
|
"rollup-plugin-dts": "^6.1.0",
|
|
135
126
|
"tslib": "^2.8.0",
|
|
136
|
-
"tsx": "^4.21.0",
|
|
137
127
|
"typescript": "^5.6.0",
|
|
138
128
|
"vite": "^6.0.0",
|
|
139
129
|
"vitest": "^2.0.0"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Application, Assets, Ticker } from 'pixi.js';
|
|
2
|
-
import { CasinoGameSDK } from '@energy8platform/game-sdk';
|
|
2
|
+
import type { CasinoGameSDK } from '@energy8platform/game-sdk';
|
|
3
3
|
import type { InitData, GameConfigData, SessionData } from '@energy8platform/game-sdk';
|
|
4
|
+
import { createPlatformSession, type PlatformSession } from '@energy8platform/platform-core';
|
|
4
5
|
import type { GameApplicationConfig, GameEngineEvents, AssetManifest } from '../types';
|
|
5
6
|
import { ScaleMode, Orientation, TransitionType } from '../types';
|
|
6
7
|
import { EventEmitter } from './EventEmitter';
|
|
@@ -10,7 +11,7 @@ import { AudioManager } from '../audio/AudioManager';
|
|
|
10
11
|
import { InputManager } from '../input/InputManager';
|
|
11
12
|
import { ViewportManager } from '../viewport/ViewportManager';
|
|
12
13
|
import { LoadingScene } from '../loading/LoadingScene';
|
|
13
|
-
import { createCSSPreloader, removeCSSPreloader } from '
|
|
14
|
+
import { createCSSPreloader, removeCSSPreloader } from '@energy8platform/platform-core/loading';
|
|
14
15
|
import { FPSOverlay } from '../debug/FPSOverlay';
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -74,6 +75,9 @@ export class GameApplication extends EventEmitter<GameEngineEvents> {
|
|
|
74
75
|
/** Data received from SDK initialization */
|
|
75
76
|
public initData: InitData | null = null;
|
|
76
77
|
|
|
78
|
+
/** Platform session (SDK + optional DevBridge). null until start() runs. */
|
|
79
|
+
public platformSession: PlatformSession | null = null;
|
|
80
|
+
|
|
77
81
|
/** Configuration */
|
|
78
82
|
public readonly config: GameApplicationConfig;
|
|
79
83
|
|
|
@@ -190,7 +194,7 @@ export class GameApplication extends EventEmitter<GameEngineEvents> {
|
|
|
190
194
|
this.input?.destroy();
|
|
191
195
|
this.audio?.destroy();
|
|
192
196
|
this.viewport?.destroy();
|
|
193
|
-
this.
|
|
197
|
+
this.platformSession?.destroy();
|
|
194
198
|
this.app?.destroy(true, { children: true, texture: true });
|
|
195
199
|
|
|
196
200
|
this.emit('destroyed');
|
|
@@ -234,24 +238,16 @@ export class GameApplication extends EventEmitter<GameEngineEvents> {
|
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
private async initSDK(): Promise<void> {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
// Delegate the SDK handshake (and any optional in-process DevBridge
|
|
242
|
+
// wiring) to platform-core. The session forwards SDK events upward.
|
|
243
|
+
this.platformSession = await createPlatformSession({ sdk: this.config.sdk });
|
|
244
|
+
this.sdk = this.platformSession.sdk;
|
|
245
|
+
this.initData = this.platformSession.initData;
|
|
242
246
|
|
|
243
|
-
|
|
244
|
-
this.sdk = new CasinoGameSDK(sdkOpts);
|
|
245
|
-
|
|
246
|
-
// Perform the handshake
|
|
247
|
-
this.initData = await this.sdk.ready();
|
|
248
|
-
|
|
249
|
-
// Forward SDK events
|
|
250
|
-
this.sdk.on('error', (err: Error) => {
|
|
247
|
+
this.platformSession.on('error', (err) => {
|
|
251
248
|
this.emit('error', err);
|
|
252
249
|
});
|
|
253
|
-
|
|
254
|
-
this.sdk.on('balanceUpdate', (data) => {
|
|
250
|
+
this.platformSession.on('balanceUpdate', (data) => {
|
|
255
251
|
this.emit('balanceUpdate', data);
|
|
256
252
|
});
|
|
257
253
|
}
|
package/src/debug/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
// DevBridge has moved to @energy8platform/platform-core/dev-bridge.
|
|
2
|
+
// Re-export here so the @energy8platform/game-engine/debug sub-path stays stable.
|
|
3
|
+
export { DevBridge } from '@energy8platform/platform-core/dev-bridge';
|
|
4
|
+
export type { DevBridgeConfig } from '@energy8platform/platform-core/dev-bridge';
|
|
3
5
|
export { FPSOverlay } from './FPSOverlay';
|
package/src/index.ts
CHANGED
|
@@ -96,8 +96,8 @@ export type { ScrollContainerConfig, ScrollDirection } from './ui/ScrollContaine
|
|
|
96
96
|
export { LoadingScene } from './loading/LoadingScene';
|
|
97
97
|
|
|
98
98
|
// ─── Debug ───────────────────────────────────────────────
|
|
99
|
-
export { DevBridge } from '
|
|
100
|
-
export type { DevBridgeConfig } from '
|
|
99
|
+
export { DevBridge } from '@energy8platform/platform-core/dev-bridge';
|
|
100
|
+
export type { DevBridgeConfig } from '@energy8platform/platform-core/dev-bridge';
|
|
101
101
|
export { FPSOverlay } from './debug/FPSOverlay';
|
|
102
102
|
|
|
103
103
|
// ─── Lua ────────────────────────────────────────────────
|
|
@@ -110,4 +110,4 @@ export type {
|
|
|
110
110
|
TransitionRule,
|
|
111
111
|
LuaEngineConfig,
|
|
112
112
|
LuaPlayResult,
|
|
113
|
-
} from '
|
|
113
|
+
} from '@energy8platform/platform-core/lua';
|