@energy8platform/game-engine 0.36.0 → 0.38.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
@@ -2624,6 +2624,7 @@ async function createSlotGame(opts) {
2624
2624
  };
2625
2625
  const { runRound } = await Promise.resolve().then(function () { return runRound$1; });
2626
2626
  const { createBalanceGate } = await Promise.resolve().then(function () { return balanceGate; });
2627
+ const { attachSettingsStore } = await Promise.resolve().then(function () { return settingsStore; });
2627
2628
  const { createFreeSpinsCounter } = await Promise.resolve().then(function () { return freeSpinsCounter; });
2628
2629
  const { resolvePlayError } = await Promise.resolve().then(function () { return playError; });
2629
2630
  // slotPlay references shell via closure — define it after shell is assigned below.
@@ -2738,6 +2739,18 @@ async function createSlotGame(opts) {
2738
2739
  // The game may swap in its own shell (a custom renderer over the same core) via shellFactory;
2739
2740
  // default is the built-in Pixi shell. The host drives whichever it gets through the Shell contract.
2740
2741
  shell = (opts.shellFactory ?? createPixiShell)(pixiShellCfg);
2742
+ // Opt-in, per game, and BEFORE `currentTurbo` is seeded from `shell.state.turbo` below — the
2743
+ // restored level has to be in place by the time the host reads it, or the first spin would run
2744
+ // at the default speed while the bar shows the remembered one. `features.turbo` is passed as the
2745
+ // ceiling so a jurisdiction that capped turbo still wins over whatever is in storage.
2746
+ if (opts.persistSettings) {
2747
+ const p = opts.persistSettings === true ? {} : opts.persistSettings;
2748
+ attachSettingsStore(shell, {
2749
+ key: p.key ?? opts.model.spec.id,
2750
+ storage: p.storage,
2751
+ maxTurbo: pixiShellCfg.features.turbo,
2752
+ });
2753
+ }
2741
2754
  // Scope the bar to the slot scene: show only when a SlotSceneController scene is current
2742
2755
  // (hidden over the intro / non-slot scenes). Applies in BOTH base and replay modes.
2743
2756
  shell.setVisible(!!gameScene());
@@ -3364,6 +3377,9 @@ function toBonusOptions(model, t = (s) => s) {
3364
3377
  // Hero art (SSOT) → card thumbnail. Passed verbatim: the shell loads it as-is, so no URL
3365
3378
  // resolver is needed (matches a static buyBonus `thumbnail`). Keeps i18n/price/accent/social.
3366
3379
  ...(action.art ? { thumbnail: action.art } : {}),
3380
+ // Variant grouping (SSOT): actions sharing the key share one card in the pixi shell, flipped
3381
+ // through with arrows. Each stays its own action, so the id on activate/buy is unambiguous.
3382
+ ...(action.groupedBy ? { groupedBy: action.groupedBy } : {}),
3367
3383
  });
3368
3384
  }
3369
3385
  return out;
@@ -3713,6 +3729,137 @@ var sceneStart = /*#__PURE__*/Object.freeze({
3713
3729
  resolveStartScene: resolveStartScene
3714
3730
  });
3715
3731
 
3732
+ function settingsKey(gameId) {
3733
+ return `e8:${gameId}:settings`;
3734
+ }
3735
+ /**
3736
+ * `localStorage` is not reliably there and not reliably usable: Safari's private mode, a browser
3737
+ * configured to block storage, and a full quota can all make even a READ throw. A saved turbo level
3738
+ * is never worth failing a game boot over, so every access degrades to "no persistence".
3739
+ */
3740
+ function resolveStorage(explicit) {
3741
+ if (explicit !== undefined)
3742
+ return explicit;
3743
+ try {
3744
+ return typeof localStorage === 'undefined' ? null : localStorage;
3745
+ }
3746
+ catch {
3747
+ return null;
3748
+ }
3749
+ }
3750
+ /** A menu value is a boolean or a finite number — nothing else may reach the shell. */
3751
+ function isMenuValue(v) {
3752
+ return typeof v === 'boolean' || (typeof v === 'number' && Number.isFinite(v));
3753
+ }
3754
+ /**
3755
+ * Read and VALIDATE. Whatever is in `localStorage` is player-writable — anyone can open devtools
3756
+ * and put a string, an object, or `turbo: 99` in there. It is parsed as untrusted input: a bad
3757
+ * field is dropped, not coerced, and a bad blob yields nothing at all.
3758
+ */
3759
+ function readSettings(storage, key) {
3760
+ if (!storage)
3761
+ return {};
3762
+ let raw;
3763
+ try {
3764
+ raw = storage.getItem(key);
3765
+ }
3766
+ catch {
3767
+ return {};
3768
+ }
3769
+ if (!raw)
3770
+ return {};
3771
+ let parsed;
3772
+ try {
3773
+ parsed = JSON.parse(raw);
3774
+ }
3775
+ catch {
3776
+ return {};
3777
+ }
3778
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
3779
+ return {};
3780
+ const src = parsed;
3781
+ const out = {};
3782
+ if (typeof src.turbo === 'number' && Number.isInteger(src.turbo) && src.turbo >= 0) {
3783
+ out.turbo = src.turbo;
3784
+ }
3785
+ if (src.menu && typeof src.menu === 'object' && !Array.isArray(src.menu)) {
3786
+ const menu = {};
3787
+ for (const [id, value] of Object.entries(src.menu)) {
3788
+ if (isMenuValue(value))
3789
+ menu[id] = value;
3790
+ }
3791
+ if (Object.keys(menu).length)
3792
+ out.menu = menu;
3793
+ }
3794
+ return out;
3795
+ }
3796
+ function writeSettings(storage, key, value) {
3797
+ if (!storage)
3798
+ return;
3799
+ try {
3800
+ storage.setItem(key, JSON.stringify(value));
3801
+ }
3802
+ catch {
3803
+ // Quota, private mode, or storage disabled mid-session. The player keeps playing; only the
3804
+ // memory of their preference is lost, and that is not worth an error in their face.
3805
+ }
3806
+ }
3807
+ /**
3808
+ * Restore the stored preferences onto a freshly created shell, then keep them in step.
3809
+ *
3810
+ * Returns an unsubscribe function.
3811
+ *
3812
+ * Two things are deliberate here:
3813
+ *
3814
+ * - **`maxTurbo` clamps the restored level.** `features.turbo` is the CEILING the shell offers
3815
+ * (`applyJurisdiction` lowers it where super-turbo or turbo is forbidden), while `state.turbo`
3816
+ * is what the player currently has. Restoring a saved 3 into a jurisdiction capped at 1 would
3817
+ * hand back exactly what the restriction took away, so the stored value is clamped, never
3818
+ * trusted.
3819
+ * - **Subscription happens AFTER restoring.** `setMenuValue` emits `settingChange`, so subscribing
3820
+ * first would have the restore write back what it just read. (`setTurbo` is quiet — only the
3821
+ * bar tap emits `turboChange` — which is why restoring the level can't echo. Do not "fix" that
3822
+ * asymmetry without moving this subscription.)
3823
+ */
3824
+ function attachSettingsStore(shell, opts) {
3825
+ const storage = resolveStorage(opts.storage);
3826
+ const key = settingsKey(opts.key);
3827
+ const stored = readSettings(storage, key);
3828
+ if (stored.turbo !== undefined) {
3829
+ shell.setTurbo(Math.min(stored.turbo, opts.maxTurbo ?? stored.turbo));
3830
+ }
3831
+ for (const [id, value] of Object.entries(stored.menu ?? {})) {
3832
+ // `setMenuValue` routes presets to their own homes (sound → setSound, music/sfx → setVolume)
3833
+ // and clamps custom ranges, so one loop covers every row and the shell owns the bounds.
3834
+ shell.setMenuValue(id, value);
3835
+ }
3836
+ const live = { ...stored };
3837
+ const flush = () => writeSettings(storage, key, live);
3838
+ const onTurbo = (level) => {
3839
+ live.turbo = level;
3840
+ flush();
3841
+ };
3842
+ const onSetting = ({ key: id, value }) => {
3843
+ if (!isMenuValue(value))
3844
+ return;
3845
+ live.menu = { ...live.menu, [id]: value };
3846
+ flush();
3847
+ };
3848
+ shell.on('turboChange', onTurbo);
3849
+ shell.on('settingChange', onSetting);
3850
+ return () => {
3851
+ shell.off('turboChange', onTurbo);
3852
+ shell.off('settingChange', onSetting);
3853
+ };
3854
+ }
3855
+
3856
+ var settingsStore = /*#__PURE__*/Object.freeze({
3857
+ __proto__: null,
3858
+ attachSettingsStore: attachSettingsStore,
3859
+ readSettings: readSettings,
3860
+ settingsKey: settingsKey
3861
+ });
3862
+
3716
3863
  function createWinReporter(paint) {
3717
3864
  let accepting = false;
3718
3865
  return {
@@ -4161,10 +4308,13 @@ Object.defineProperty(exports, "socialize", {
4161
4308
  enumerable: true,
4162
4309
  get: function () { return shell.socialize; }
4163
4310
  });
4311
+ exports.attachSettingsStore = attachSettingsStore;
4164
4312
  exports.buildShellConfig = buildShellConfig;
4165
4313
  exports.createSlotGame = createSlotGame;
4166
4314
  exports.createWinReporter = createWinReporter;
4315
+ exports.readSettings = readSettings;
4167
4316
  exports.resolveReplayBonusId = resolveReplayBonusId;
4168
4317
  exports.resolveStartScene = resolveStartScene;
4318
+ exports.settingsKey = settingsKey;
4169
4319
  exports.stakeForAction = stakeForAction;
4170
4320
  //# sourceMappingURL=host.cjs.js.map