@energy8platform/game-engine 0.36.0 → 0.37.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 +147 -0
- package/dist/host.cjs.js.map +1 -1
- package/dist/host.d.ts +59 -2
- package/dist/host.esm.js +145 -1
- package/dist/host.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/host/createSlotGame.ts +13 -0
- package/src/host/index.ts +2 -0
- package/src/host/settingsStore.ts +148 -0
- package/src/host/types.ts +7 -0
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());
|
|
@@ -3713,6 +3726,137 @@ var sceneStart = /*#__PURE__*/Object.freeze({
|
|
|
3713
3726
|
resolveStartScene: resolveStartScene
|
|
3714
3727
|
});
|
|
3715
3728
|
|
|
3729
|
+
function settingsKey(gameId) {
|
|
3730
|
+
return `e8:${gameId}:settings`;
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* `localStorage` is not reliably there and not reliably usable: Safari's private mode, a browser
|
|
3734
|
+
* configured to block storage, and a full quota can all make even a READ throw. A saved turbo level
|
|
3735
|
+
* is never worth failing a game boot over, so every access degrades to "no persistence".
|
|
3736
|
+
*/
|
|
3737
|
+
function resolveStorage(explicit) {
|
|
3738
|
+
if (explicit !== undefined)
|
|
3739
|
+
return explicit;
|
|
3740
|
+
try {
|
|
3741
|
+
return typeof localStorage === 'undefined' ? null : localStorage;
|
|
3742
|
+
}
|
|
3743
|
+
catch {
|
|
3744
|
+
return null;
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
/** A menu value is a boolean or a finite number — nothing else may reach the shell. */
|
|
3748
|
+
function isMenuValue(v) {
|
|
3749
|
+
return typeof v === 'boolean' || (typeof v === 'number' && Number.isFinite(v));
|
|
3750
|
+
}
|
|
3751
|
+
/**
|
|
3752
|
+
* Read and VALIDATE. Whatever is in `localStorage` is player-writable — anyone can open devtools
|
|
3753
|
+
* and put a string, an object, or `turbo: 99` in there. It is parsed as untrusted input: a bad
|
|
3754
|
+
* field is dropped, not coerced, and a bad blob yields nothing at all.
|
|
3755
|
+
*/
|
|
3756
|
+
function readSettings(storage, key) {
|
|
3757
|
+
if (!storage)
|
|
3758
|
+
return {};
|
|
3759
|
+
let raw;
|
|
3760
|
+
try {
|
|
3761
|
+
raw = storage.getItem(key);
|
|
3762
|
+
}
|
|
3763
|
+
catch {
|
|
3764
|
+
return {};
|
|
3765
|
+
}
|
|
3766
|
+
if (!raw)
|
|
3767
|
+
return {};
|
|
3768
|
+
let parsed;
|
|
3769
|
+
try {
|
|
3770
|
+
parsed = JSON.parse(raw);
|
|
3771
|
+
}
|
|
3772
|
+
catch {
|
|
3773
|
+
return {};
|
|
3774
|
+
}
|
|
3775
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
3776
|
+
return {};
|
|
3777
|
+
const src = parsed;
|
|
3778
|
+
const out = {};
|
|
3779
|
+
if (typeof src.turbo === 'number' && Number.isInteger(src.turbo) && src.turbo >= 0) {
|
|
3780
|
+
out.turbo = src.turbo;
|
|
3781
|
+
}
|
|
3782
|
+
if (src.menu && typeof src.menu === 'object' && !Array.isArray(src.menu)) {
|
|
3783
|
+
const menu = {};
|
|
3784
|
+
for (const [id, value] of Object.entries(src.menu)) {
|
|
3785
|
+
if (isMenuValue(value))
|
|
3786
|
+
menu[id] = value;
|
|
3787
|
+
}
|
|
3788
|
+
if (Object.keys(menu).length)
|
|
3789
|
+
out.menu = menu;
|
|
3790
|
+
}
|
|
3791
|
+
return out;
|
|
3792
|
+
}
|
|
3793
|
+
function writeSettings(storage, key, value) {
|
|
3794
|
+
if (!storage)
|
|
3795
|
+
return;
|
|
3796
|
+
try {
|
|
3797
|
+
storage.setItem(key, JSON.stringify(value));
|
|
3798
|
+
}
|
|
3799
|
+
catch {
|
|
3800
|
+
// Quota, private mode, or storage disabled mid-session. The player keeps playing; only the
|
|
3801
|
+
// memory of their preference is lost, and that is not worth an error in their face.
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
/**
|
|
3805
|
+
* Restore the stored preferences onto a freshly created shell, then keep them in step.
|
|
3806
|
+
*
|
|
3807
|
+
* Returns an unsubscribe function.
|
|
3808
|
+
*
|
|
3809
|
+
* Two things are deliberate here:
|
|
3810
|
+
*
|
|
3811
|
+
* - **`maxTurbo` clamps the restored level.** `features.turbo` is the CEILING the shell offers
|
|
3812
|
+
* (`applyJurisdiction` lowers it where super-turbo or turbo is forbidden), while `state.turbo`
|
|
3813
|
+
* is what the player currently has. Restoring a saved 3 into a jurisdiction capped at 1 would
|
|
3814
|
+
* hand back exactly what the restriction took away, so the stored value is clamped, never
|
|
3815
|
+
* trusted.
|
|
3816
|
+
* - **Subscription happens AFTER restoring.** `setMenuValue` emits `settingChange`, so subscribing
|
|
3817
|
+
* first would have the restore write back what it just read. (`setTurbo` is quiet — only the
|
|
3818
|
+
* bar tap emits `turboChange` — which is why restoring the level can't echo. Do not "fix" that
|
|
3819
|
+
* asymmetry without moving this subscription.)
|
|
3820
|
+
*/
|
|
3821
|
+
function attachSettingsStore(shell, opts) {
|
|
3822
|
+
const storage = resolveStorage(opts.storage);
|
|
3823
|
+
const key = settingsKey(opts.key);
|
|
3824
|
+
const stored = readSettings(storage, key);
|
|
3825
|
+
if (stored.turbo !== undefined) {
|
|
3826
|
+
shell.setTurbo(Math.min(stored.turbo, opts.maxTurbo ?? stored.turbo));
|
|
3827
|
+
}
|
|
3828
|
+
for (const [id, value] of Object.entries(stored.menu ?? {})) {
|
|
3829
|
+
// `setMenuValue` routes presets to their own homes (sound → setSound, music/sfx → setVolume)
|
|
3830
|
+
// and clamps custom ranges, so one loop covers every row and the shell owns the bounds.
|
|
3831
|
+
shell.setMenuValue(id, value);
|
|
3832
|
+
}
|
|
3833
|
+
const live = { ...stored };
|
|
3834
|
+
const flush = () => writeSettings(storage, key, live);
|
|
3835
|
+
const onTurbo = (level) => {
|
|
3836
|
+
live.turbo = level;
|
|
3837
|
+
flush();
|
|
3838
|
+
};
|
|
3839
|
+
const onSetting = ({ key: id, value }) => {
|
|
3840
|
+
if (!isMenuValue(value))
|
|
3841
|
+
return;
|
|
3842
|
+
live.menu = { ...live.menu, [id]: value };
|
|
3843
|
+
flush();
|
|
3844
|
+
};
|
|
3845
|
+
shell.on('turboChange', onTurbo);
|
|
3846
|
+
shell.on('settingChange', onSetting);
|
|
3847
|
+
return () => {
|
|
3848
|
+
shell.off('turboChange', onTurbo);
|
|
3849
|
+
shell.off('settingChange', onSetting);
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
|
|
3853
|
+
var settingsStore = /*#__PURE__*/Object.freeze({
|
|
3854
|
+
__proto__: null,
|
|
3855
|
+
attachSettingsStore: attachSettingsStore,
|
|
3856
|
+
readSettings: readSettings,
|
|
3857
|
+
settingsKey: settingsKey
|
|
3858
|
+
});
|
|
3859
|
+
|
|
3716
3860
|
function createWinReporter(paint) {
|
|
3717
3861
|
let accepting = false;
|
|
3718
3862
|
return {
|
|
@@ -4161,10 +4305,13 @@ Object.defineProperty(exports, "socialize", {
|
|
|
4161
4305
|
enumerable: true,
|
|
4162
4306
|
get: function () { return shell.socialize; }
|
|
4163
4307
|
});
|
|
4308
|
+
exports.attachSettingsStore = attachSettingsStore;
|
|
4164
4309
|
exports.buildShellConfig = buildShellConfig;
|
|
4165
4310
|
exports.createSlotGame = createSlotGame;
|
|
4166
4311
|
exports.createWinReporter = createWinReporter;
|
|
4312
|
+
exports.readSettings = readSettings;
|
|
4167
4313
|
exports.resolveReplayBonusId = resolveReplayBonusId;
|
|
4168
4314
|
exports.resolveStartScene = resolveStartScene;
|
|
4315
|
+
exports.settingsKey = settingsKey;
|
|
4169
4316
|
exports.stakeForAction = stakeForAction;
|
|
4170
4317
|
//# sourceMappingURL=host.cjs.js.map
|