@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/index.esm.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Ticker, Assets, Container, Text, Application, AnimatedSprite, Texture, Sprite, Graphics, NineSliceSprite } from 'pixi.js';
|
|
2
|
-
import {
|
|
2
|
+
import { createPlatformSession } from '@energy8platform/platform-core';
|
|
3
|
+
import { LOADER_BAR_MAX_WIDTH, buildLogoSVG, createCSSPreloader, removeCSSPreloader } from '@energy8platform/platform-core/loading';
|
|
3
4
|
export { BridgeDestroyedError, BridgeNotReadyError, SDKError, TimeoutError } from '@energy8platform/game-sdk';
|
|
5
|
+
export { DevBridge } from '@energy8platform/platform-core/dev-bridge';
|
|
4
6
|
|
|
5
7
|
// ─── Scale Modes ───────────────────────────────────────────
|
|
6
8
|
var ScaleMode;
|
|
@@ -1498,75 +1500,6 @@ class Scene {
|
|
|
1498
1500
|
}
|
|
1499
1501
|
}
|
|
1500
1502
|
|
|
1501
|
-
/**
|
|
1502
|
-
* Shared Energy8 SVG logo with an embedded loader bar.
|
|
1503
|
-
*
|
|
1504
|
-
* The loader bar fill is controlled via a `<clipPath>` whose `<rect>` width
|
|
1505
|
-
* is animatable. Different consumers customise gradient IDs and the clip
|
|
1506
|
-
* element's ID/class to avoid collisions when both CSSPreloader and
|
|
1507
|
-
* LoadingScene appear in the same DOM.
|
|
1508
|
-
*/
|
|
1509
|
-
/** SVG path data for the Energy8 wordmark — reused across loaders */
|
|
1510
|
-
const WORDMARK_PATHS = `
|
|
1511
|
-
<path d="m241 81.75h-19.28c-1.77 0-6.73 4.98-7.43 6.99l-4.36 12.22c-0.49 1.37 0.05 2.92 1.06 4.32-2.07 1.19-3.69 3.08-4.36 5.43l-3.25 10.41c-0.86 2.89 2.39 6.63 4.31 6.63h19.28c1.96 0 7.4-5.56 7.96-7.51l2.96-10.22c0.63-2.25 0.1-3.98-1.22-4.99 2.55-1.56 3.86-4.14 4.55-6.31l2.77-9.31c0.74-2.57-1.37-7.66-2.99-7.66zm-13.36 28.31-2.27 7.03h-8.28l2.58-8.28h8.28l-0.31 1.25zm4.06-16.97-2.11 6.7h-7.04l2.25-7.34h7.26l-0.36 0.64z" fill="url(#GID0)"/>
|
|
1512
|
-
<path d="m202.5 81.75-9.31 14.97-2.32-14.97h-11.82l4.32 25.15-0.57 4.91-8.64 26.44 15.31-12.76 5.63-16.48 19.96-27.26h-12.56z" fill="url(#GID1)"/>
|
|
1513
|
-
<path d="m174.2 81.75h-19.78l-5.75 5.16-10.79 33.2c-0.77 2.53 2.48 6.93 4.87 6.93h17.38c2.63 0 7.85-5.34 8.32-6.83l5.37-18.14h-15.17l-2.2 7.64h3.78l-2.25 7.2h-8.01l7.1-25.52h7.58l-1.48 8.4 12.78-5.98c1.28-0.63 1.97-3.99 1.61-6.61-0.36-2.34-1.64-5.45-3.36-5.45z" fill="url(#GID2)"/>
|
|
1514
|
-
<path d="m140.6 81.75h-70.6l-5.36 19.37-4.26-19.37h-46.76l2.95 5.88-10.58 39.28h26.84l2.95-9.52-15.63-0.13 2.55-8.34h8.74l8.47-9.81h-14.61l2.11-7.3h15.47l2.54-8.71 2.58 4.74-11.4 39.07h11.05l6.46-21.49 8.84 36.33 19.18-55.67-1.83-3.36 3.68 4.09-12.07 40.1h28.18l3.39-10.31h-17.01l2.67-8.03h9.98l7.58-9.52h-14.28l1.93-6.6h14.61l3.25-9.73 2.81 5.12-11.3 38.89h11.05l5.23-17.81h1.62l1.48 17.6h10.69l-1.48-16.81c4.75-1.28 7.52-5.9 8.64-9.81l2.95-11.3c0.86-2.73-1.43-6.85-3.3-6.85zm-9.8 17.3h-8.69l2.54-7.84h8.35l-2.2 7.84z" fill="url(#GID3)"/>
|
|
1515
|
-
<path d="m205.9 148.9h-122.6l-2.61-3.12h-32.4l-2.51 3.12h-1.59c-5.34 0-7.94 4.88-7.94 7.65v0.03c0 4.2 3.55 7.6 7.74 7.6h103.6l2.11 3.12h36.09l1.82-3.12h18.3c5.25 0 6.64-5.3 6.64-7.35v-0.25c0-4.23-2.9-7.68-6.64-7.68zm-0.7 12.83h-160.6c-3.69 0-6.11-2.58-6.11-5.47v-0.03c0-2.89 2.1-5.47 5.61-5.47h161.1c3.45 0 4.89 3.12 4.89 5.65v0.17c0 2.57-2.11 5.15-4.89 5.15z" fill="url(#GID4)"/>`;
|
|
1516
|
-
/** Gradient definitions template (gradient IDs are replaced per-consumer) */
|
|
1517
|
-
const GRADIENT_DEFS = `
|
|
1518
|
-
<linearGradient id="GID0" x1="223.7" x2="223.7" y1="81.75" y2="127.8" gradientUnits="userSpaceOnUse">
|
|
1519
|
-
<stop stop-color="#663BA6"/><stop stop-color="#7939C2" offset=".349"/><stop stop-color="#8A2FC0" offset=".6615"/><stop stop-color="#791BA3" offset="1"/>
|
|
1520
|
-
</linearGradient>
|
|
1521
|
-
<linearGradient id="GID1" x1="194.6" x2="194.6" y1="81.75" y2="138.3" gradientUnits="userSpaceOnUse">
|
|
1522
|
-
<stop stop-color="#663BA6"/><stop stop-color="#7939C2" offset=".349"/><stop stop-color="#8A2FC0" offset=".6615"/><stop stop-color="#791BA3" offset="1"/>
|
|
1523
|
-
</linearGradient>
|
|
1524
|
-
<linearGradient id="GID2" x1="157.8" x2="157.8" y1="81.75" y2="127" gradientUnits="userSpaceOnUse">
|
|
1525
|
-
<stop stop-color="#663BA6"/><stop stop-color="#7939C2" offset=".349"/><stop stop-color="#8A2FC0" offset=".6615"/><stop stop-color="#791BA3" offset="1"/>
|
|
1526
|
-
</linearGradient>
|
|
1527
|
-
<linearGradient id="GID3" x1="79.96" x2="79.96" y1="81.75" y2="141.8" gradientUnits="userSpaceOnUse">
|
|
1528
|
-
<stop stop-color="#663BA6"/><stop stop-color="#7939C2" offset=".349"/><stop stop-color="#8A2FC0" offset=".6615"/><stop stop-color="#791BA3" offset="1"/>
|
|
1529
|
-
</linearGradient>
|
|
1530
|
-
<linearGradient id="GID4" x1="36.18" x2="212.5" y1="156.6" y2="156.6" gradientUnits="userSpaceOnUse">
|
|
1531
|
-
<stop stop-color="#316FB0"/><stop stop-color="#1FCDE6" offset=".5"/><stop stop-color="#29FEE7" offset="1"/>
|
|
1532
|
-
</linearGradient>
|
|
1533
|
-
<linearGradient id="GID5" x1="40.27" x2="208.2" y1="156.4" y2="156.4" gradientUnits="userSpaceOnUse">
|
|
1534
|
-
<stop stop-color="#316FB0"/><stop stop-color="#1FCDE6" offset=".5"/><stop stop-color="#29FEE7" offset="1"/>
|
|
1535
|
-
</linearGradient>`;
|
|
1536
|
-
/** Max width of the loader bar in SVG units */
|
|
1537
|
-
const LOADER_BAR_MAX_WIDTH = 174;
|
|
1538
|
-
/**
|
|
1539
|
-
* Build the Energy8 SVG logo with a loader bar, using unique IDs.
|
|
1540
|
-
*
|
|
1541
|
-
* @param opts - Configuration to avoid element ID collisions
|
|
1542
|
-
* @returns SVG markup string
|
|
1543
|
-
*/
|
|
1544
|
-
function buildLogoSVG(opts) {
|
|
1545
|
-
const { idPrefix, svgClass, svgStyle, clipRectClass, clipRectId, textId, textContent, textClass } = opts;
|
|
1546
|
-
// Replace gradient ID placeholders with prefixed versions
|
|
1547
|
-
const paths = WORDMARK_PATHS.replace(/GID(\d)/g, `${idPrefix}$1`);
|
|
1548
|
-
const defs = GRADIENT_DEFS.replace(/GID(\d)/g, `${idPrefix}$1`);
|
|
1549
|
-
const clipId = `${idPrefix}-loader-clip`;
|
|
1550
|
-
const fillGradientId = `${idPrefix}5`;
|
|
1551
|
-
const classAttr = svgClass ? ` class="${svgClass}"` : '';
|
|
1552
|
-
const styleAttr = svgStyle ? ` style="${svgStyle}"` : '';
|
|
1553
|
-
const rectClassAttr = clipRectClass ? ` class="${clipRectClass}"` : '';
|
|
1554
|
-
const rectIdAttr = clipRectId ? ` id="${clipRectId}"` : '';
|
|
1555
|
-
const txtIdAttr = textId ? ` id="${textId}"` : '';
|
|
1556
|
-
const txtClassAttr = textClass ? ` class="${textClass}"` : '';
|
|
1557
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 250 200" fill="none"${classAttr}${styleAttr}>
|
|
1558
|
-
${paths}
|
|
1559
|
-
<clipPath id="${clipId}">
|
|
1560
|
-
<rect${rectIdAttr} x="37" y="148" width="0" height="20"${rectClassAttr}/>
|
|
1561
|
-
</clipPath>
|
|
1562
|
-
<path d="m204.5 152.6h-159.8c-2.78 0-4.45 1.69-4.45 3.99v0.11c0 2.04 1.42 3.43 3.64 3.43h160.6c2.88 0 3.67-2.07 3.67-3.43v-0.25c0-2.04-1.48-3.85-3.67-3.85z" fill="url(#${fillGradientId})" clip-path="url(#${clipId})"/>
|
|
1563
|
-
<text${txtIdAttr} x="125" y="196" text-anchor="middle" fill="rgba(255,255,255,0.6)" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif" font-size="8" font-weight="600" letter-spacing="1.5"${txtClassAttr}>${textContent ?? 'Loading...'}</text>
|
|
1564
|
-
<defs>
|
|
1565
|
-
${defs}
|
|
1566
|
-
</defs>
|
|
1567
|
-
</svg>`;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
1503
|
/**
|
|
1571
1504
|
* Build the loading scene variant of the logo SVG.
|
|
1572
1505
|
* Uses unique IDs (prefixed with 'ls') to avoid collisions with CSSPreloader.
|
|
@@ -1835,120 +1768,6 @@ class LoadingScene extends Scene {
|
|
|
1835
1768
|
}
|
|
1836
1769
|
}
|
|
1837
1770
|
|
|
1838
|
-
const PRELOADER_ID = '__ge-css-preloader__';
|
|
1839
|
-
/**
|
|
1840
|
-
* Inline SVG logo with animated loader bar.
|
|
1841
|
-
* The `#loader` path acts as the progress fill — animated via clipPath.
|
|
1842
|
-
*/
|
|
1843
|
-
const LOGO_SVG = buildLogoSVG({
|
|
1844
|
-
idPrefix: 'pl',
|
|
1845
|
-
svgClass: 'ge-logo-svg',
|
|
1846
|
-
clipRectClass: 'ge-clip-rect',
|
|
1847
|
-
textClass: 'ge-preloader-svg-text',
|
|
1848
|
-
});
|
|
1849
|
-
/**
|
|
1850
|
-
* Creates a lightweight CSS-only preloader that appears instantly,
|
|
1851
|
-
* BEFORE PixiJS/WebGL is initialized.
|
|
1852
|
-
*
|
|
1853
|
-
* Displays the Energy8 logo SVG with an animated loader bar.
|
|
1854
|
-
*/
|
|
1855
|
-
function createCSSPreloader(container, config) {
|
|
1856
|
-
if (document.getElementById(PRELOADER_ID))
|
|
1857
|
-
return;
|
|
1858
|
-
const bgColor = typeof config?.backgroundColor === 'string'
|
|
1859
|
-
? config.backgroundColor
|
|
1860
|
-
: typeof config?.backgroundColor === 'number'
|
|
1861
|
-
? `#${config.backgroundColor.toString(16).padStart(6, '0')}`
|
|
1862
|
-
: '#0a0a1a';
|
|
1863
|
-
const bgGradient = config?.backgroundGradient ?? `linear-gradient(135deg, ${bgColor} 0%, #1a1a3e 100%)`;
|
|
1864
|
-
const customHTML = config?.cssPreloaderHTML ?? '';
|
|
1865
|
-
const el = document.createElement('div');
|
|
1866
|
-
el.id = PRELOADER_ID;
|
|
1867
|
-
el.innerHTML = customHTML || `
|
|
1868
|
-
<div class="ge-preloader-content">
|
|
1869
|
-
${LOGO_SVG}
|
|
1870
|
-
</div>
|
|
1871
|
-
`;
|
|
1872
|
-
const style = document.createElement('style');
|
|
1873
|
-
style.textContent = `
|
|
1874
|
-
#${PRELOADER_ID} {
|
|
1875
|
-
position: absolute;
|
|
1876
|
-
top: 0; left: 0;
|
|
1877
|
-
width: 100%; height: 100%;
|
|
1878
|
-
background: ${bgGradient};
|
|
1879
|
-
display: flex;
|
|
1880
|
-
align-items: center;
|
|
1881
|
-
justify-content: center;
|
|
1882
|
-
z-index: 10000;
|
|
1883
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
1884
|
-
transition: opacity 0.4s ease-out;
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
#${PRELOADER_ID}.ge-preloader-hidden {
|
|
1888
|
-
opacity: 0;
|
|
1889
|
-
pointer-events: none;
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
.ge-preloader-content {
|
|
1893
|
-
display: flex;
|
|
1894
|
-
flex-direction: column;
|
|
1895
|
-
align-items: center;
|
|
1896
|
-
width: 80%;
|
|
1897
|
-
max-width: 700px;
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
.ge-logo-svg {
|
|
1901
|
-
width: 100%;
|
|
1902
|
-
height: auto;
|
|
1903
|
-
filter: drop-shadow(0 0 30px rgba(121, 57, 194, 0.4));
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
/* Animate the loader clip-rect to shimmer while waiting */
|
|
1907
|
-
.ge-clip-rect {
|
|
1908
|
-
animation: ge-loader-fill 2s ease-in-out infinite;
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
@keyframes ge-loader-fill {
|
|
1912
|
-
0% { width: 0; }
|
|
1913
|
-
50% { width: 174; }
|
|
1914
|
-
100% { width: 0; }
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
/* Animate the SVG text opacity */
|
|
1918
|
-
.ge-preloader-svg-text {
|
|
1919
|
-
animation: ge-pulse 1.5s ease-in-out infinite;
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
@keyframes ge-pulse {
|
|
1923
|
-
0%, 100% { opacity: 0.4; }
|
|
1924
|
-
50% { opacity: 1; }
|
|
1925
|
-
}
|
|
1926
|
-
`;
|
|
1927
|
-
container.style.position = container.style.position || 'relative';
|
|
1928
|
-
container.appendChild(style);
|
|
1929
|
-
container.appendChild(el);
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* Remove the CSS preloader with a smooth fade-out transition.
|
|
1933
|
-
*/
|
|
1934
|
-
function removeCSSPreloader(container) {
|
|
1935
|
-
const el = document.getElementById(PRELOADER_ID);
|
|
1936
|
-
if (!el)
|
|
1937
|
-
return;
|
|
1938
|
-
el.classList.add('ge-preloader-hidden');
|
|
1939
|
-
// Remove after transition
|
|
1940
|
-
el.addEventListener('transitionend', () => {
|
|
1941
|
-
el.remove();
|
|
1942
|
-
// Also remove the style element
|
|
1943
|
-
const styles = container.querySelectorAll('style');
|
|
1944
|
-
for (const style of styles) {
|
|
1945
|
-
if (style.textContent?.includes(PRELOADER_ID)) {
|
|
1946
|
-
style.remove();
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
});
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
1771
|
/**
|
|
1953
1772
|
* FPS overlay for debugging performance.
|
|
1954
1773
|
*
|
|
@@ -2090,6 +1909,8 @@ class GameApplication extends EventEmitter {
|
|
|
2090
1909
|
fpsOverlay = null;
|
|
2091
1910
|
/** Data received from SDK initialization */
|
|
2092
1911
|
initData = null;
|
|
1912
|
+
/** Platform session (SDK + optional DevBridge). null until start() runs. */
|
|
1913
|
+
platformSession = null;
|
|
2093
1914
|
/** Configuration */
|
|
2094
1915
|
config;
|
|
2095
1916
|
// ─── Private state ──────────────────────────────────────
|
|
@@ -2183,7 +2004,7 @@ class GameApplication extends EventEmitter {
|
|
|
2183
2004
|
this.input?.destroy();
|
|
2184
2005
|
this.audio?.destroy();
|
|
2185
2006
|
this.viewport?.destroy();
|
|
2186
|
-
this.
|
|
2007
|
+
this.platformSession?.destroy();
|
|
2187
2008
|
this.app?.destroy(true, { children: true, texture: true });
|
|
2188
2009
|
this.emit('destroyed');
|
|
2189
2010
|
this.removeAllListeners();
|
|
@@ -2219,20 +2040,15 @@ class GameApplication extends EventEmitter {
|
|
|
2219
2040
|
this.app.canvas.style.height = '100%';
|
|
2220
2041
|
}
|
|
2221
2042
|
async initSDK() {
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
this.sdk = new CasinoGameSDK(sdkOpts);
|
|
2229
|
-
// Perform the handshake
|
|
2230
|
-
this.initData = await this.sdk.ready();
|
|
2231
|
-
// Forward SDK events
|
|
2232
|
-
this.sdk.on('error', (err) => {
|
|
2043
|
+
// Delegate the SDK handshake (and any optional in-process DevBridge
|
|
2044
|
+
// wiring) to platform-core. The session forwards SDK events upward.
|
|
2045
|
+
this.platformSession = await createPlatformSession({ sdk: this.config.sdk });
|
|
2046
|
+
this.sdk = this.platformSession.sdk;
|
|
2047
|
+
this.initData = this.platformSession.initData;
|
|
2048
|
+
this.platformSession.on('error', (err) => {
|
|
2233
2049
|
this.emit('error', err);
|
|
2234
2050
|
});
|
|
2235
|
-
this.
|
|
2051
|
+
this.platformSession.on('balanceUpdate', (data) => {
|
|
2236
2052
|
this.emit('balanceUpdate', data);
|
|
2237
2053
|
});
|
|
2238
2054
|
}
|
|
@@ -5234,236 +5050,5 @@ class ScrollContainer extends Container {
|
|
|
5234
5050
|
}
|
|
5235
5051
|
}
|
|
5236
5052
|
|
|
5237
|
-
|
|
5238
|
-
balance: 10000,
|
|
5239
|
-
currency: 'USD',
|
|
5240
|
-
gameConfig: {
|
|
5241
|
-
id: 'dev-game',
|
|
5242
|
-
type: 'slot',
|
|
5243
|
-
version: '1.0.0',
|
|
5244
|
-
viewport: { width: 1920, height: 1080 },
|
|
5245
|
-
betLevels: [0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50],
|
|
5246
|
-
},
|
|
5247
|
-
assetsUrl: '/assets/',
|
|
5248
|
-
session: null,
|
|
5249
|
-
onPlay: () => ({}),
|
|
5250
|
-
networkDelay: 200,
|
|
5251
|
-
debug: true,
|
|
5252
|
-
};
|
|
5253
|
-
/**
|
|
5254
|
-
* Mock host bridge for local development.
|
|
5255
|
-
*
|
|
5256
|
-
* Uses the SDK's `Bridge` class in `devMode` to communicate with
|
|
5257
|
-
* `CasinoGameSDK` via a shared in-memory `MemoryChannel`, removing
|
|
5258
|
-
* the need for postMessage and iframes.
|
|
5259
|
-
*
|
|
5260
|
-
* When `luaScript` is set, play requests are sent to the Vite dev server
|
|
5261
|
-
* which runs LuaEngine in Node.js — no fengari in the browser.
|
|
5262
|
-
*
|
|
5263
|
-
* @example
|
|
5264
|
-
* ```ts
|
|
5265
|
-
* import { DevBridge } from '@energy8platform/game-engine/debug';
|
|
5266
|
-
*
|
|
5267
|
-
* const devBridge = new DevBridge({
|
|
5268
|
-
* balance: 5000,
|
|
5269
|
-
* currency: 'EUR',
|
|
5270
|
-
* gameConfig: { id: 'my-slot', type: 'slot', betLevels: [0.2, 0.5, 1, 2] },
|
|
5271
|
-
* onPlay: ({ action, bet }) => ({
|
|
5272
|
-
* totalWin: Math.random() > 0.5 ? bet * (Math.random() * 20) : 0,
|
|
5273
|
-
* data: { matrix: [[1,2,3],[4,5,6],[7,8,9]] },
|
|
5274
|
-
* }),
|
|
5275
|
-
* });
|
|
5276
|
-
* devBridge.start();
|
|
5277
|
-
* ```
|
|
5278
|
-
*/
|
|
5279
|
-
class DevBridge {
|
|
5280
|
-
_config;
|
|
5281
|
-
_balance;
|
|
5282
|
-
_roundCounter = 0;
|
|
5283
|
-
_bridge = null;
|
|
5284
|
-
_useLuaServer;
|
|
5285
|
-
constructor(config = {}) {
|
|
5286
|
-
this._config = { ...DEFAULT_CONFIG, ...config };
|
|
5287
|
-
this._balance = this._config.balance;
|
|
5288
|
-
this._useLuaServer = !!(this._config.luaScript && this._config.gameDefinition);
|
|
5289
|
-
}
|
|
5290
|
-
/** Current mock balance */
|
|
5291
|
-
get balance() {
|
|
5292
|
-
return this._balance;
|
|
5293
|
-
}
|
|
5294
|
-
/** Start listening for SDK messages */
|
|
5295
|
-
start() {
|
|
5296
|
-
if (this._bridge)
|
|
5297
|
-
return;
|
|
5298
|
-
console.debug('[DevBridge] Starting with config:', this._config);
|
|
5299
|
-
this._bridge = new Bridge({ devMode: true, debug: this._config.debug });
|
|
5300
|
-
this._bridge.on('GAME_READY', (_payload, id) => {
|
|
5301
|
-
this.handleGameReady(id);
|
|
5302
|
-
});
|
|
5303
|
-
this._bridge.on('PLAY_REQUEST', (payload, id) => {
|
|
5304
|
-
this.handlePlayRequest(payload, id);
|
|
5305
|
-
});
|
|
5306
|
-
this._bridge.on('PLAY_RESULT_ACK', (payload) => {
|
|
5307
|
-
this.handlePlayAck(payload);
|
|
5308
|
-
});
|
|
5309
|
-
this._bridge.on('GET_BALANCE', (_payload, id) => {
|
|
5310
|
-
this.handleGetBalance(id);
|
|
5311
|
-
});
|
|
5312
|
-
this._bridge.on('GET_STATE', (_payload, id) => {
|
|
5313
|
-
this.handleGetState(id);
|
|
5314
|
-
});
|
|
5315
|
-
this._bridge.on('OPEN_DEPOSIT', () => {
|
|
5316
|
-
this.handleOpenDeposit();
|
|
5317
|
-
});
|
|
5318
|
-
if (this._config.debug) {
|
|
5319
|
-
const mode = this._useLuaServer ? 'Lua (server-side)' : 'onPlay callback';
|
|
5320
|
-
console.log(`[DevBridge] Started — mode: ${mode}`);
|
|
5321
|
-
}
|
|
5322
|
-
}
|
|
5323
|
-
/** Stop listening */
|
|
5324
|
-
stop() {
|
|
5325
|
-
if (this._bridge) {
|
|
5326
|
-
this._bridge.destroy();
|
|
5327
|
-
this._bridge = null;
|
|
5328
|
-
}
|
|
5329
|
-
if (this._config.debug) {
|
|
5330
|
-
console.log('[DevBridge] Stopped');
|
|
5331
|
-
}
|
|
5332
|
-
}
|
|
5333
|
-
/** Set mock balance */
|
|
5334
|
-
setBalance(balance) {
|
|
5335
|
-
this._balance = balance;
|
|
5336
|
-
this._bridge?.send('BALANCE_UPDATE', { balance: this._balance });
|
|
5337
|
-
}
|
|
5338
|
-
/** Destroy the dev bridge */
|
|
5339
|
-
destroy() {
|
|
5340
|
-
this.stop();
|
|
5341
|
-
}
|
|
5342
|
-
// ─── Message Handling ──────────────────────────────────
|
|
5343
|
-
handleGameReady(id) {
|
|
5344
|
-
const initData = {
|
|
5345
|
-
balance: this._balance,
|
|
5346
|
-
currency: this._config.currency,
|
|
5347
|
-
config: this._config.gameConfig,
|
|
5348
|
-
session: this._config.session,
|
|
5349
|
-
assetsUrl: this._config.assetsUrl,
|
|
5350
|
-
};
|
|
5351
|
-
this.delayedSend('INIT', initData, id);
|
|
5352
|
-
}
|
|
5353
|
-
handlePlayRequest(payload, id) {
|
|
5354
|
-
const { action, bet, roundId, params } = payload;
|
|
5355
|
-
this._roundCounter++;
|
|
5356
|
-
if (this._useLuaServer) {
|
|
5357
|
-
// Debit bet (server deducts before Lua execution)
|
|
5358
|
-
// For session actions (free spins), debit is 0 — LuaEngine handles bet from session
|
|
5359
|
-
this._balance -= bet;
|
|
5360
|
-
this.executeLuaOnServer({ action, bet, roundId, params })
|
|
5361
|
-
.then((result) => {
|
|
5362
|
-
this._bridge?.send('PLAY_RESULT', result, id);
|
|
5363
|
-
})
|
|
5364
|
-
.catch((err) => {
|
|
5365
|
-
console.error('[DevBridge] Lua server error:', err);
|
|
5366
|
-
this._balance += bet;
|
|
5367
|
-
this._bridge?.send('PLAY_RESULT', this.buildFallbackResult(action, bet, roundId), id);
|
|
5368
|
-
});
|
|
5369
|
-
}
|
|
5370
|
-
else {
|
|
5371
|
-
// Fallback to onPlay callback
|
|
5372
|
-
const customResult = this._config.onPlay({ action, bet, roundId, params });
|
|
5373
|
-
const totalWin = customResult.totalWin ?? (Math.random() > 0.6 ? bet * (1 + Math.random() * 10) : 0);
|
|
5374
|
-
this._balance += totalWin;
|
|
5375
|
-
const result = {
|
|
5376
|
-
roundId: roundId ?? `dev-round-${this._roundCounter}`,
|
|
5377
|
-
action,
|
|
5378
|
-
balanceAfter: this._balance,
|
|
5379
|
-
totalWin: Math.round(totalWin * 100) / 100,
|
|
5380
|
-
data: customResult.data ?? {},
|
|
5381
|
-
nextActions: customResult.nextActions ?? ['spin'],
|
|
5382
|
-
session: customResult.session ?? null,
|
|
5383
|
-
creditPending: false,
|
|
5384
|
-
bonusFreeSpin: customResult.bonusFreeSpin ?? null,
|
|
5385
|
-
currency: this._config.currency,
|
|
5386
|
-
gameId: this._config.gameConfig?.id ?? 'dev-game',
|
|
5387
|
-
};
|
|
5388
|
-
this.delayedSend('PLAY_RESULT', result, id);
|
|
5389
|
-
}
|
|
5390
|
-
}
|
|
5391
|
-
async executeLuaOnServer(params) {
|
|
5392
|
-
const response = await fetch('/__lua-play', {
|
|
5393
|
-
method: 'POST',
|
|
5394
|
-
headers: { 'Content-Type': 'application/json' },
|
|
5395
|
-
body: JSON.stringify(params),
|
|
5396
|
-
});
|
|
5397
|
-
if (!response.ok) {
|
|
5398
|
-
const err = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
5399
|
-
throw new Error(err.error ?? `HTTP ${response.status}`);
|
|
5400
|
-
}
|
|
5401
|
-
const luaResult = await response.json();
|
|
5402
|
-
// Server credit logic:
|
|
5403
|
-
// shouldCredit = (no session) OR (session.completed)
|
|
5404
|
-
// creditAmount = result.totalWin
|
|
5405
|
-
const shouldCredit = !luaResult.session || luaResult.session.completed;
|
|
5406
|
-
if (shouldCredit && luaResult.totalWin > 0) {
|
|
5407
|
-
this._balance += luaResult.totalWin;
|
|
5408
|
-
}
|
|
5409
|
-
return {
|
|
5410
|
-
roundId: params.roundId ?? `dev-round-${this._roundCounter}`,
|
|
5411
|
-
action: params.action,
|
|
5412
|
-
balanceAfter: this._balance,
|
|
5413
|
-
totalWin: Math.round(luaResult.totalWin * 100) / 100,
|
|
5414
|
-
data: luaResult.data,
|
|
5415
|
-
nextActions: luaResult.nextActions,
|
|
5416
|
-
session: luaResult.session,
|
|
5417
|
-
creditPending: !shouldCredit,
|
|
5418
|
-
bonusFreeSpin: null,
|
|
5419
|
-
currency: this._config.currency,
|
|
5420
|
-
gameId: this._config.gameConfig?.id ?? 'dev-game',
|
|
5421
|
-
};
|
|
5422
|
-
}
|
|
5423
|
-
buildFallbackResult(action, bet, roundId) {
|
|
5424
|
-
return {
|
|
5425
|
-
roundId: roundId ?? `dev-round-${this._roundCounter}`,
|
|
5426
|
-
action,
|
|
5427
|
-
balanceAfter: this._balance,
|
|
5428
|
-
totalWin: 0,
|
|
5429
|
-
data: { error: 'Lua execution failed' },
|
|
5430
|
-
nextActions: ['spin'],
|
|
5431
|
-
session: null,
|
|
5432
|
-
creditPending: false,
|
|
5433
|
-
bonusFreeSpin: null,
|
|
5434
|
-
currency: this._config.currency,
|
|
5435
|
-
gameId: this._config.gameConfig?.id ?? 'dev-game',
|
|
5436
|
-
};
|
|
5437
|
-
}
|
|
5438
|
-
handlePlayAck(_payload) {
|
|
5439
|
-
if (this._config.debug) {
|
|
5440
|
-
console.log('[DevBridge] Play acknowledged');
|
|
5441
|
-
}
|
|
5442
|
-
}
|
|
5443
|
-
handleGetBalance(id) {
|
|
5444
|
-
this.delayedSend('BALANCE_UPDATE', { balance: this._balance }, id);
|
|
5445
|
-
}
|
|
5446
|
-
handleGetState(id) {
|
|
5447
|
-
this.delayedSend('STATE_RESPONSE', { session: this._config.session ?? null }, id);
|
|
5448
|
-
}
|
|
5449
|
-
handleOpenDeposit() {
|
|
5450
|
-
if (this._config.debug) {
|
|
5451
|
-
console.log('[DevBridge] Open deposit requested (mock: adding 1000)');
|
|
5452
|
-
}
|
|
5453
|
-
this._balance += 1000;
|
|
5454
|
-
this._bridge?.send('BALANCE_UPDATE', { balance: this._balance });
|
|
5455
|
-
}
|
|
5456
|
-
// ─── Communication ─────────────────────────────────────
|
|
5457
|
-
delayedSend(type, payload, id) {
|
|
5458
|
-
const delay = this._config.networkDelay;
|
|
5459
|
-
if (delay > 0) {
|
|
5460
|
-
setTimeout(() => this._bridge?.send(type, payload, id), delay);
|
|
5461
|
-
}
|
|
5462
|
-
else {
|
|
5463
|
-
this._bridge?.send(type, payload, id);
|
|
5464
|
-
}
|
|
5465
|
-
}
|
|
5466
|
-
}
|
|
5467
|
-
|
|
5468
|
-
export { AssetManager, AudioManager, BalanceDisplay, Button, DevBridge, Easing, EventEmitter, FPSOverlay, FlexContainer, GameApplication, InputManager, Label, Layout, LoadingScene, Modal, Orientation, Panel, ProgressBar, ScaleMode, Scene, SceneManager, ScrollContainer, SpineHelper, SpriteAnimation, StateMachine, Timeline, Toast, TransitionType, Tween, ViewportManager, WinDisplay };
|
|
5053
|
+
export { AssetManager, AudioManager, BalanceDisplay, Button, Easing, EventEmitter, FPSOverlay, FlexContainer, GameApplication, InputManager, Label, Layout, LoadingScene, Modal, Orientation, Panel, ProgressBar, ScaleMode, Scene, SceneManager, ScrollContainer, SpineHelper, SpriteAnimation, StateMachine, Timeline, Toast, TransitionType, Tween, ViewportManager, WinDisplay };
|
|
5469
5054
|
//# sourceMappingURL=index.esm.js.map
|