@energy8platform/game-engine 0.19.0 → 0.20.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/dist/host.cjs.js CHANGED
@@ -1517,34 +1517,20 @@ class Scene {
1517
1517
  }
1518
1518
 
1519
1519
  /**
1520
- * Build the loading scene variant of the logo SVG.
1521
- * Uses unique IDs (prefixed with 'ls') to avoid collisions with CSSPreloader.
1522
- */
1523
- function buildLoadingLogoSVG() {
1524
- return loading.buildLogoSVG({
1525
- idPrefix: 'ls',
1526
- svgStyle: 'width:100%;height:auto;',
1527
- clipRectId: 'ge-loader-rect',
1528
- textId: 'ge-loader-pct',
1529
- textContent: '0%',
1530
- });
1531
- }
1532
- /**
1533
- * Built-in loading screen using the Energy8 SVG logo with animated loader bar.
1520
+ * Built-in loading screen.
1534
1521
  *
1535
- * Renders as an HTML overlay on top of the canvas for crisp SVG quality.
1536
- * The loader bar fill width is driven by asset loading progress.
1522
+ * It does NOT render its own overlay the CSS preloader created at boot
1523
+ * (`createPlatformSession`/`GameApplication.start`) stays on screen, and this
1524
+ * scene merely drives it: asset-load progress → `setCSSPreloaderProgress`,
1525
+ * tap-to-start → `waitCSSPreloaderTap`, then fades it out via
1526
+ * `removeCSSPreloader` before entering the game. One continuous overlay from
1527
+ * boot to gameplay — no second logo, no mid-load flash.
1537
1528
  */
1538
1529
  class LoadingScene extends Scene {
1539
1530
  _engine;
1540
1531
  _targetScene;
1541
1532
  _targetData;
1542
1533
  _config;
1543
- // HTML overlay
1544
- _overlay = null;
1545
- _loaderRect = null;
1546
- _percentEl = null;
1547
- _tapToStartEl = null;
1548
1534
  // State
1549
1535
  _displayedProgress = 0;
1550
1536
  _targetProgress = 0;
@@ -1557,8 +1543,6 @@ class LoadingScene extends Scene {
1557
1543
  this._targetData = targetData;
1558
1544
  this._config = engine.config.loading ?? {};
1559
1545
  this._startTime = Date.now();
1560
- // Create the HTML overlay with the SVG logo
1561
- this.createOverlay();
1562
1546
  // Initialize asset manager
1563
1547
  await this._engine.assets.init();
1564
1548
  // Initialize audio manager
@@ -1604,110 +1588,29 @@ class LoadingScene extends Scene {
1604
1588
  // Final snap to 100%
1605
1589
  this._displayedProgress = 1;
1606
1590
  this.updateLoaderBar(1);
1607
- // Show "Tap to Start" or transition directly
1608
- if (this._config.tapToStart !== false) {
1609
- await this.showTapToStart();
1610
- }
1611
- else {
1612
- await this.transitionToGame();
1613
- }
1591
+ // Wait for the player's tap resolves immediately when tapToStart is
1592
+ // false (the preloader honours that flag) — then enter the game.
1593
+ await loading.waitCSSPreloaderTap();
1594
+ await this.transitionToGame();
1614
1595
  }
1615
1596
  onUpdate(dt) {
1616
- // Smooth progress bar fill via HTML (during active loading)
1597
+ // Smooth progress bar fill (during active loading)
1617
1598
  if (!this._loadingComplete && this._displayedProgress < this._targetProgress) {
1618
1599
  this._displayedProgress = Math.min(this._displayedProgress + dt * 1.5, this._targetProgress);
1619
1600
  this.updateLoaderBar(this._displayedProgress);
1620
1601
  }
1621
1602
  }
1622
1603
  onResize(_width, _height) {
1623
- // Overlay is CSS-based, auto-resizes
1604
+ // The preloader overlay is CSS-based and auto-resizes.
1624
1605
  }
1625
1606
  onDestroy() {
1626
- this.removeOverlay();
1627
- }
1628
- // ─── HTML Overlay ──────────────────────────────────────
1629
- createOverlay() {
1630
- const bgColor = typeof this._config.backgroundColor === 'string'
1631
- ? this._config.backgroundColor
1632
- : typeof this._config.backgroundColor === 'number'
1633
- ? `#${this._config.backgroundColor.toString(16).padStart(6, '0')}`
1634
- : '#0a0a1a';
1635
- const bgGradient = this._config.backgroundGradient ??
1636
- `linear-gradient(135deg, ${bgColor} 0%, #1a1a3e 100%)`;
1637
- this._overlay = document.createElement('div');
1638
- this._overlay.id = '__ge-loading-overlay__';
1639
- this._overlay.innerHTML = `
1640
- <div class="ge-loading-content">
1641
- ${buildLoadingLogoSVG()}
1642
- </div>
1643
- `;
1644
- const style = document.createElement('style');
1645
- style.id = '__ge-loading-style__';
1646
- style.textContent = `
1647
- #__ge-loading-overlay__ {
1648
- position: absolute;
1649
- top: 0; left: 0;
1650
- width: 100%; height: 100%;
1651
- background: ${bgGradient};
1652
- display: flex;
1653
- align-items: center;
1654
- justify-content: center;
1655
- z-index: 9999;
1656
- transition: opacity 0.5s ease-out;
1657
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
1658
- }
1659
- #__ge-loading-overlay__.ge-fade-out {
1660
- opacity: 0;
1661
- pointer-events: none;
1662
- }
1663
- .ge-loading-content {
1664
- display: flex;
1665
- flex-direction: column;
1666
- align-items: center;
1667
- width: 75%;
1668
- max-width: 650px;
1669
- }
1670
- .ge-loading-content svg {
1671
- filter: drop-shadow(0 0 40px rgba(121, 57, 194, 0.5));
1672
- cursor: default;
1673
- }
1674
-
1675
- .ge-svg-pulse {
1676
- animation: ge-tap-pulse 1.2s ease-in-out infinite;
1677
- }
1678
- @keyframes ge-tap-pulse {
1679
- 0%, 100% { opacity: 0.5; }
1680
- 50% { opacity: 1; }
1681
- }
1682
- `;
1683
- // Get the container that holds the canvas
1684
- const container = this._engine.app?.canvas?.parentElement;
1685
- if (container) {
1686
- container.style.position = container.style.position || 'relative';
1687
- container.appendChild(style);
1688
- container.appendChild(this._overlay);
1689
- }
1690
- // Cache the SVG loader rect for progress updates
1691
- this._loaderRect = this._overlay.querySelector('#ge-loader-rect');
1692
- this._percentEl = this._overlay.querySelector('#ge-loader-pct');
1693
- }
1694
- removeOverlay() {
1695
- this._overlay?.remove();
1696
- document.getElementById('__ge-loading-style__')?.remove();
1697
- this._overlay = null;
1698
- this._loaderRect = null;
1699
- this._percentEl = null;
1700
- this._tapToStartEl = null;
1607
+ // Defensive: ensure the preloader is gone even if we never transitioned
1608
+ // (e.g. the scene was popped externally). Idempotent.
1609
+ void loading.removeCSSPreloader(this.hostElement());
1701
1610
  }
1702
1611
  // ─── Progress ──────────────────────────────────────────
1703
1612
  updateLoaderBar(progress) {
1704
- if (this._loaderRect) {
1705
- this._loaderRect.setAttribute('width', String(loading.LOADER_BAR_MAX_WIDTH * progress));
1706
- }
1707
- if (this._percentEl) {
1708
- const pct = Math.round(progress * 100);
1709
- this._percentEl.textContent = `${pct}%`;
1710
- }
1613
+ loading.setCSSPreloaderProgress(Math.max(0, Math.min(1, progress)));
1711
1614
  }
1712
1615
  /**
1713
1616
  * Smoothly animate the displayed progress from its current value to `target`
@@ -1737,49 +1640,20 @@ class LoadingScene extends Scene {
1737
1640
  requestAnimationFrame(tick);
1738
1641
  });
1739
1642
  }
1740
- // ─── Tap to Start ─────────────────────────────────────
1741
- async showTapToStart() {
1742
- const tapText = this._config.tapToStartText ?? 'TAP TO START';
1743
- // Reuse the same SVG text element — replace percentage with tap text
1744
- if (this._percentEl) {
1745
- const el = this._percentEl;
1746
- el.textContent = tapText;
1747
- el.setAttribute('fill', '#ffffff');
1748
- el.classList.add('ge-svg-pulse');
1749
- this._tapToStartEl = el;
1750
- }
1751
- // Make overlay clickable
1752
- if (this._overlay) {
1753
- this._overlay.style.cursor = 'pointer';
1754
- }
1755
- // Wait for tap
1756
- return new Promise((resolve) => {
1757
- const handler = async () => {
1758
- this._overlay?.removeEventListener('click', handler);
1759
- await this.transitionToGame();
1760
- resolve();
1761
- };
1762
- // Listen on the full overlay for easier mobile tap
1763
- this._overlay?.addEventListener('click', handler);
1764
- });
1765
- }
1766
1643
  // ─── Transition ────────────────────────────────────────
1644
+ /** The DOM element hosting the canvas + preloader overlay. */
1645
+ hostElement() {
1646
+ return this._engine?.app?.canvas?.parentElement ?? document.body;
1647
+ }
1767
1648
  async transitionToGame() {
1768
- // Fade out the HTML overlay
1769
- if (this._overlay) {
1770
- this._overlay.classList.add('ge-fade-out');
1771
- await new Promise((resolve) => {
1772
- this._overlay.addEventListener('transitionend', () => resolve(), { once: true });
1773
- // Safety timeout
1774
- setTimeout(resolve, 600);
1775
- });
1776
- }
1777
- // Remove overlay
1778
- this.removeOverlay();
1649
+ // Fade out and remove the shared CSS preloader (resolves after the fade).
1650
+ await loading.removeCSSPreloader(this.hostElement());
1779
1651
  // Navigate to the target scene, always passing the engine reference
1780
1652
  await this._engine.scenes.goto(this._targetScene, {
1781
1653
  engine: this._engine,
1782
- ...(this._targetData && typeof this._targetData === 'object' ? this._targetData : { data: this._targetData }),
1654
+ ...(this._targetData && typeof this._targetData === 'object'
1655
+ ? this._targetData
1656
+ : { data: this._targetData }),
1783
1657
  });
1784
1658
  }
1785
1659
  }
@@ -2006,17 +1880,20 @@ class GameApplication extends EventEmitter {
2006
1880
  // 6. Initialize sub-systems
2007
1881
  this.initSubSystems();
2008
1882
  this.emit('initialized');
2009
- // 7. Remove CSS preloader, show Canvas loading screen
2010
- loading.removeCSSPreloader(this._container);
2011
- // 8. Load assets with loading screen
1883
+ // 7. Load assets. The CSS preloader stays on screen — LoadingScene drives
1884
+ // its progress/tap and removes it before entering the game, so there's
1885
+ // a single continuous overlay from boot to gameplay (no logo flash).
2012
1886
  await this.loadAssets(firstScene, sceneData);
2013
1887
  this.emit('loaded');
2014
- // 9. Start the game loop
1888
+ // 8. Start the game loop
2015
1889
  this._running = true;
2016
1890
  this.emit('started');
2017
1891
  }
2018
1892
  catch (err) {
2019
1893
  console.error('[GameEngine] Failed to start:', err);
1894
+ // Tear down the preloader so a failure doesn't strand the brand frame.
1895
+ if (this._container)
1896
+ loading.removeCSSPreloader(this._container);
2020
1897
  this.emit('error', err instanceof Error ? err : new Error(String(err)));
2021
1898
  throw err;
2022
1899
  }
@@ -2879,8 +2756,8 @@ async function createSlotGame(opts) {
2879
2756
  }
2880
2757
 
2881
2758
  // packages/game-engine/src/host/shellConfig.ts
2882
- // `socialize` is a runtime helper that pixi-shell does NOT re-export (its index only re-exports
2883
- // types), so it stays sourced from platform-core/shell; the shapes are structurally identical.
2759
+ // `socialize` / `createI18n` are runtime helpers sourced from platform-core/shell;
2760
+ // pixi-shell re-exports only types so we import directly from platform-core.
2884
2761
  /**
2885
2762
  * Apply jurisdiction restrictions over the resolved shell features, in place. A restriction ALWAYS
2886
2763
  * wins over the author's intent (a forbidden control must stay off even if the game enabled it).
@@ -2935,8 +2812,9 @@ function stakeForAction(model, action, bet) {
2935
2812
  const cost = (model.spec.actions?.[action]?.cost ?? 1);
2936
2813
  return cost * bet;
2937
2814
  }
2938
- /** Derive shell buy cards + ante toggles from the spec's buy/feature actions (SSOT). */
2939
- function toBonusOptions(model) {
2815
+ /** Derive shell buy cards + ante toggles from the spec's buy/feature actions (SSOT).
2816
+ * @param t Optional translator applied to `title` and `description` before they enter the shell. */
2817
+ function toBonusOptions(model, t = (s) => s) {
2940
2818
  const out = [];
2941
2819
  for (const [key, action] of Object.entries(model.spec.actions)) {
2942
2820
  const role = action.role ?? 'base';
@@ -2945,15 +2823,18 @@ function toBonusOptions(model) {
2945
2823
  out.push({
2946
2824
  id: key,
2947
2825
  type: role === 'buy' ? 'bonus' : 'feature',
2948
- title: action.title ?? key.replace(/_/g, ' ').toUpperCase(),
2949
- description: action.description ?? '',
2826
+ title: t(action.title ?? key.replace(/_/g, ' ').toUpperCase()),
2827
+ description: t(action.description ?? ''),
2950
2828
  priceMultiplier: action.cost ?? (role === 'buy' ? 100 : 1),
2829
+ // Volatility (1–5 bolts) is part of the spec action SSOT; forward it so the buy card shows it.
2830
+ ...(action.volatility != null ? { volatility: action.volatility } : {}),
2951
2831
  });
2952
2832
  }
2953
2833
  return out;
2954
2834
  }
2955
- /** Build a paytable section from the model's derived paytable view (multipliers per symbol count). */
2956
- function paytableSection(model) {
2835
+ /** Build a paytable section from the model's derived paytable view (multipliers per symbol count).
2836
+ * @param t Optional translator applied to symbol names before they enter the shell. */
2837
+ function paytableSection(model, t = (s) => s) {
2957
2838
  const symbols = model.paytable?.symbols ?? [];
2958
2839
  const rows = [];
2959
2840
  for (const s of symbols) {
@@ -2963,11 +2844,13 @@ function paytableSection(model) {
2963
2844
  .sort((a, b) => Number(a.count) - Number(b.count));
2964
2845
  if (!wins.length)
2965
2846
  continue;
2966
- rows.push({ symbol: { text: s.name ?? s.id }, wins });
2847
+ rows.push({ symbol: { text: t(s.name ?? s.id) }, wins });
2967
2848
  }
2968
2849
  if (!rows.length)
2969
2850
  return null;
2970
- return { type: 'paytable', title: 'PAYTABLE', rows };
2851
+ // No literal title — the shell renders `s.title ?? host.t('Paytable')`, so the heading is
2852
+ // localized (matching how the modes/wins sections rely on the shell's translated fallback).
2853
+ return { type: 'paytable', rows };
2971
2854
  }
2972
2855
  /** Build a "wins" illustration section sized to the grid; `kind` follows the spec mechanic hint. */
2973
2856
  function winsSection(model) {
@@ -3009,14 +2892,15 @@ function orderDisclaimerLast(sections) {
3009
2892
  * gets a real info panel for free (paytable, win illustration, controls, and the Stake
3010
2893
  * disclaimer when present). Author-supplied `opts.gameInfo` is MERGED over this set by
3011
2894
  * section identity (see `mergeGameInfo`), not wholesale-replaced.
2895
+ * @param t Optional translator applied to spec-derived player-facing strings (symbol names, mode titles, etc.).
3012
2896
  */
3013
- function defaultGameInfo(model, runtime) {
2897
+ function defaultGameInfo(model, runtime, t = (s) => s) {
3014
2898
  const sections = [];
3015
2899
  sections.push(winsSection(model));
3016
- const pay = paytableSection(model);
2900
+ const pay = paytableSection(model, t);
3017
2901
  if (pay)
3018
2902
  sections.push(pay);
3019
- const modes = modesSection(model);
2903
+ const modes = modesSection(model, t);
3020
2904
  if (modes)
3021
2905
  sections.push(modes);
3022
2906
  sections.push({ type: 'controls' });
@@ -3029,8 +2913,9 @@ function defaultGameInfo(model, runtime) {
3029
2913
  * (`model.mathModes` + `spec.actions`) that drives the buy cards and the math pipeline. Stake
3030
2914
  * compliance requires Cost / RTP / Max Win per mode; deriving it here means the author declares a
3031
2915
  * mode once (in game.spec) and the info table can't drift. `free` actions are excluded (mathModes
3032
- * already drops them — free spins are part of a bonus, not a purchasable mode). */
3033
- function modesSection(model) {
2916
+ * already drops them — free spins are part of a bonus, not a purchasable mode).
2917
+ * @param t Optional translator applied to row `title` and `description` before they enter the shell. */
2918
+ function modesSection(model, t = (s) => s) {
3034
2919
  const modes = model.mathModes ?? [];
3035
2920
  if (!modes.length)
3036
2921
  return null;
@@ -3038,7 +2923,7 @@ function modesSection(model) {
3038
2923
  const action = model.spec.actions[m.action];
3039
2924
  const isBase = (action?.role ?? 'base') === 'base' || m.mode === 'BASE';
3040
2925
  const row = {
3041
- title: action?.title ?? (isBase ? 'Base game' : m.mode.replace(/_/g, ' ')),
2926
+ title: t(action?.title ?? (isBase ? 'Base game' : m.mode.replace(/_/g, ' '))),
3042
2927
  maxWin: `${m.maxWin.toLocaleString('en-US')}×`,
3043
2928
  };
3044
2929
  // Cost is a bet-multiplier; a base spin (1×) reads as no premium, so only show it for buys/features.
@@ -3047,7 +2932,7 @@ function modesSection(model) {
3047
2932
  if (typeof m.rtp === 'number')
3048
2933
  row.rtp = Math.round(m.rtp * 1000) / 10; // 0.965 → 96.5 (%)
3049
2934
  if (action?.description)
3050
- row.description = action.description;
2935
+ row.description = t(action.description);
3051
2936
  return row;
3052
2937
  });
3053
2938
  return { type: 'modes', title: 'MODES', modes: rows };
@@ -3144,18 +3029,17 @@ function buildShellConfig(opts, model, runtime) {
3144
3029
  // host); opts.currency still wins. Fall back to the spec code, then a neutral euro.
3145
3030
  const currency = opts.currency ?? runtime.currency ?? resolveCurrency(null, model.spec.currency);
3146
3031
  const isSocial = runtime.social ?? false;
3147
- // Merge author sections over the host-derived defaults, THEN socialize the WHOLE merged set in
3148
- // social mode so restricted gambling vocabulary is rewritten in BOTH the built-in copy AND any
3149
- // author-supplied text (title + custom HTML). A game can no longer surface a forbidden word in
3150
- // social mode just because the author wrote it in their own info section. (Custom sections built
3151
- // from a raw DOM `node` can't be rewritten automatically author owns the node and can call the
3152
- // exported `socialize` from '@energy8platform/game-engine/host' on their own strings.)
3153
- // Author gameInfo may be a plain object or a `(t) => content` factory. `t` socializes when in
3154
- // social mode (identity otherwise) so authors can wrap copy explicitly; the full merged set is
3155
- // still socialized below as a safety net.
3156
- const t = isSocial ? shell.socialize : (text) => text;
3032
+ // Build the merged resolver: game i18n map + shell LOCALES (via createI18n), then socialize on
3033
+ // top for English social mode. For non-English languages, createI18n already handles the
3034
+ // translation lookup; social rewriting is English-only and applied separately after.
3035
+ // Author gameInfo may be a plain object or a `(t) => content` factory. `t` is the resolver so
3036
+ // authors can wrap player-facing copy explicitly; the full merged set is still socialized below
3037
+ // (section pass) as a safety net so restricted words can't slip through even if t() was missed.
3038
+ const { t } = shell.createI18n({ language: runtime.language ?? 'en', isSocial, messages: opts.i18n });
3157
3039
  const authored = typeof opts.gameInfo === 'function' ? opts.gameInfo(t) : opts.gameInfo;
3158
- let gameInfo = mergeGameInfo(defaultGameInfo(model, runtime), authored);
3040
+ // Pass t() through to spec-derived sections so symbol names, mode titles, and descriptions are
3041
+ // pre-translated before they reach the shell renderer.
3042
+ let gameInfo = mergeGameInfo(defaultGameInfo(model, runtime, t), authored);
3159
3043
  // The DISCLAIMER is required legal copy and must be shown VERBATIM — never socialized (its
3160
3044
  // wording is mandated, and word-swaps like "bet → play" would corrupt the legal text).
3161
3045
  if (isSocial) {
@@ -3165,8 +3049,8 @@ function buildShellConfig(opts, model, runtime) {
3165
3049
  }
3166
3050
  // The legal DISCLAIMER always renders LAST — author-merged or extra sections never push below it.
3167
3051
  gameInfo = { sections: orderDisclaimerLast(gameInfo.sections ?? []) };
3168
- // Buy-bonus cards: socialize the FINAL options (author override or spec-derived) in social mode.
3169
- const buyBonus = socializeBonusOptions(opts.buyBonus ?? toBonusOptions(model), isSocial);
3052
+ // Buy-bonus cards: apply t() to spec-derived options (pre-translate), then socialize for en+social.
3053
+ const buyBonus = socializeBonusOptions(opts.buyBonus ?? toBonusOptions(model, t), isSocial);
3170
3054
  // Features: defaults, then author overrides, THEN jurisdiction restrictions (a restriction wins).
3171
3055
  const features = {
3172
3056
  turbo: 0,