@energy8platform/platform-core 0.26.1 → 0.28.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/index.cjs.js +0 -3615
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -400
- package/dist/index.esm.js +1 -3613
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -9
- package/scripts/build-digit-font.mjs +72 -0
- package/src/index.ts +2 -17
- package/dist/shell.cjs.js +0 -3671
- package/dist/shell.cjs.js.map +0 -1
- package/dist/shell.d.ts +0 -433
- package/dist/shell.esm.js +0 -3664
- package/dist/shell.esm.js.map +0 -1
- package/scripts/gen-version.mjs +0 -21
- package/src/shell/GameShell.ts +0 -412
- package/src/shell/INTER-LICENSE.txt +0 -93
- package/src/shell/colors.ts +0 -32
- package/src/shell/components/BottomBar.ts +0 -237
- package/src/shell/components/BuyBonus.ts +0 -329
- package/src/shell/components/GameInfo.ts +0 -384
- package/src/shell/components/Modal.ts +0 -36
- package/src/shell/components/ReplayModal.ts +0 -57
- package/src/shell/components/Settings.ts +0 -59
- package/src/shell/components/icons.ts +0 -40
- package/src/shell/components/pickers.ts +0 -150
- package/src/shell/components/primitives.ts +0 -85
- package/src/shell/fonts.ts +0 -13
- package/src/shell/format.ts +0 -39
- package/src/shell/i18n.ts +0 -96
- package/src/shell/index.ts +0 -22
- package/src/shell/keyboard.ts +0 -229
- package/src/shell/locales.ts +0 -864
- package/src/shell/motion.ts +0 -43
- package/src/shell/shell.css.ts +0 -449
- package/src/shell/state.ts +0 -31
- package/src/shell/theme.ts +0 -54
- package/src/shell/types.ts +0 -262
- package/src/shell/version.ts +0 -3
package/src/shell/GameShell.ts
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from '../EventEmitter';
|
|
2
|
-
import type {
|
|
3
|
-
AutoplayOptions,
|
|
4
|
-
BonusOption,
|
|
5
|
-
FreeSpinsState,
|
|
6
|
-
ModalOptions,
|
|
7
|
-
ReplayModalOptions,
|
|
8
|
-
ShellConfig,
|
|
9
|
-
ShellEvents,
|
|
10
|
-
ShellMode,
|
|
11
|
-
ShellState,
|
|
12
|
-
ThemeConfig,
|
|
13
|
-
} from './types';
|
|
14
|
-
import { KeyboardController, type KeyboardHost } from './keyboard';
|
|
15
|
-
import { createInitialState, nextTurbo, stepBet } from './state';
|
|
16
|
-
import { buildThemeVars } from './theme';
|
|
17
|
-
import { SHELL_CSS, SHELL_ROOT_ID } from './shell.css';
|
|
18
|
-
import { renderBottomBar } from './components/BottomBar';
|
|
19
|
-
import { openSettingsModal } from './components/Settings';
|
|
20
|
-
import { openGameInfoModal } from './components/GameInfo';
|
|
21
|
-
import { openBuyBonusOverlay } from './components/BuyBonus';
|
|
22
|
-
import { openBetModal, openAutoplayModal } from './components/pickers';
|
|
23
|
-
import { buildModal } from './components/Modal';
|
|
24
|
-
import { buildReplayModal } from './components/ReplayModal';
|
|
25
|
-
import { countUp } from './motion';
|
|
26
|
-
import { formatCurrency } from './format';
|
|
27
|
-
import { createI18n, type I18n } from './i18n';
|
|
28
|
-
|
|
29
|
-
const REMOVE_FADE_MS = 300;
|
|
30
|
-
|
|
31
|
-
export class GameShell extends EventEmitter<ShellEvents> {
|
|
32
|
-
readonly config: ShellConfig;
|
|
33
|
-
state: ShellState;
|
|
34
|
-
private root: HTMLElement;
|
|
35
|
-
private styleEl: HTMLStyleElement;
|
|
36
|
-
private barHost = document.createElement('div');
|
|
37
|
-
private modalHost = document.createElement('div');
|
|
38
|
-
private destroyed = false;
|
|
39
|
-
layout: 'wide' | 'mobile' = 'wide';
|
|
40
|
-
private ro: ResizeObserver | null = null;
|
|
41
|
-
private prevBalance = 0;
|
|
42
|
-
private prevWin = 0;
|
|
43
|
-
private moneyAnims: Array<() => void> = [];
|
|
44
|
-
private kbd!: KeyboardController;
|
|
45
|
-
private i18n!: I18n;
|
|
46
|
-
/** onKey handler of the currently open modal/overlay, if any (set in showModal, cleared in closeModal). */
|
|
47
|
-
private modalOnKey: ((e: KeyboardEvent) => boolean) | undefined = undefined;
|
|
48
|
-
/** Shared sound on/off state — Settings speaker toggle and the Shift+M hotkey stay in sync. The
|
|
49
|
-
* game listens to `settingChange({ key: 'sound' })` to (un)mute audio. */
|
|
50
|
-
soundOn = true;
|
|
51
|
-
/** Set by the open Settings modal so Shift+M live-updates its speaker icon; cleared on close. */
|
|
52
|
-
private soundRefresh: ((on: boolean) => void) | null = null;
|
|
53
|
-
|
|
54
|
-
constructor(config: ShellConfig) {
|
|
55
|
-
super();
|
|
56
|
-
this.config = config;
|
|
57
|
-
this.i18n = createI18n({ language: config.language, isSocial: config.isSocial });
|
|
58
|
-
this.state = createInitialState(config);
|
|
59
|
-
|
|
60
|
-
this.styleEl = document.createElement('style');
|
|
61
|
-
this.styleEl.textContent = SHELL_CSS;
|
|
62
|
-
|
|
63
|
-
this.root = document.createElement('div');
|
|
64
|
-
this.root.id = SHELL_ROOT_ID;
|
|
65
|
-
this.root.setAttribute('style', buildThemeVars(config.theme));
|
|
66
|
-
|
|
67
|
-
config.mount.append(this.styleEl, this.root);
|
|
68
|
-
this.barHost.className = 'ge-shell-barhost';
|
|
69
|
-
this.root.appendChild(this.barHost);
|
|
70
|
-
this.modalHost.className = 'ge-shell-modalhost';
|
|
71
|
-
this.root.appendChild(this.modalHost);
|
|
72
|
-
this.prevBalance = this.state.balance;
|
|
73
|
-
this.prevWin = this.state.win;
|
|
74
|
-
this.observeLayout();
|
|
75
|
-
if (typeof document !== 'undefined') {
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
77
|
-
const shell = this;
|
|
78
|
-
const host: KeyboardHost = {
|
|
79
|
-
get state() { return shell.state; },
|
|
80
|
-
get hotkeysEnabled() { return shell.config.features.hotkeys !== false; },
|
|
81
|
-
get spacebarEnabled() { return shell.config.features.spacebar !== false; },
|
|
82
|
-
get turboLevels() { return shell.config.features.turbo; },
|
|
83
|
-
get autoplayEnabled() { return shell.config.features.autoplay != null; },
|
|
84
|
-
get buyBonusEnabled() { return shell.config.features.buyBonus !== false; },
|
|
85
|
-
hasOpenLayer: () => shell.modalHost.childElementCount > 0,
|
|
86
|
-
routeToLayer: (e) => shell.modalOnKey?.(e) ?? false,
|
|
87
|
-
spin: () => shell.emit('spin'),
|
|
88
|
-
stepBet: (dir) => {
|
|
89
|
-
const next = stepBet(shell.state, dir);
|
|
90
|
-
if (next === shell.state.bet) return;
|
|
91
|
-
shell.state.bet = next; shell.emit('betChange', next); shell.render();
|
|
92
|
-
},
|
|
93
|
-
toggleAutoplay: () => {
|
|
94
|
-
if (shell.state.autoplay.active) {
|
|
95
|
-
shell.state.autoplay = { active: false, remaining: 0 };
|
|
96
|
-
shell.emit('autoplayStop'); shell.render();
|
|
97
|
-
} else {
|
|
98
|
-
shell.openAutoplayPicker();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
cycleTurbo: () => {
|
|
102
|
-
const next = nextTurbo(shell.state.turbo, shell.config.features.turbo);
|
|
103
|
-
shell.state.turbo = next; shell.emit('turboChange', next); shell.render();
|
|
104
|
-
},
|
|
105
|
-
openBuyBonus: () => shell.openBuyBonus(),
|
|
106
|
-
openInfo: () => shell.openInfo(),
|
|
107
|
-
openMenu: () => shell.openMenu(),
|
|
108
|
-
toggleMute: () => shell.setSound(!shell.soundOn),
|
|
109
|
-
closeLayer: () => shell.closeModal(),
|
|
110
|
-
};
|
|
111
|
-
this.kbd = new KeyboardController(host);
|
|
112
|
-
this.kbd.attach();
|
|
113
|
-
// Stake serves the game in an iframe; on first paint focus is on the HOST page, so a `document`
|
|
114
|
-
// keydown never fires and Space scrolls the parent. Pull window focus into the iframe on the
|
|
115
|
-
// first pointer interaction so the spacebar shortcut works. Harmless on full-page Energy8.
|
|
116
|
-
document.addEventListener('pointerdown', this.pullFocus, true);
|
|
117
|
-
}
|
|
118
|
-
this.render();
|
|
119
|
-
// re-fit once the bundled webfont swaps in (text metrics change → row width changes)
|
|
120
|
-
if (typeof document !== 'undefined' && document.fonts) {
|
|
121
|
-
document.fonts.ready.then(() => { if (!this.destroyed) this.applyFitScale(); });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
render(): void {
|
|
126
|
-
if (this.destroyed) return;
|
|
127
|
-
this.cancelMoneyAnims(); // stop in-flight count-ups before their nodes are torn down below
|
|
128
|
-
this.root.classList.toggle('ge-mobile', this.layout === 'mobile');
|
|
129
|
-
this.barHost.innerHTML = '';
|
|
130
|
-
this.barHost.appendChild(renderBottomBar(this));
|
|
131
|
-
this.animateMoney();
|
|
132
|
-
this.applyFitScale();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private cancelMoneyAnims(): void {
|
|
136
|
-
for (const cancel of this.moneyAnims) cancel();
|
|
137
|
-
this.moneyAnims = [];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** Keep the WIN pill inline between the groups; float it above when it won't fit. */
|
|
141
|
-
/**
|
|
142
|
-
* Landscape bar fills the width when it fits. When it overflows, the WIN pill is
|
|
143
|
-
* lifted above the bar (unscaled, so it stays readable) and the remaining row is
|
|
144
|
-
* centred and scaled down to fit — keeping the controls as large as possible.
|
|
145
|
-
*/
|
|
146
|
-
private applyFitScale(): void {
|
|
147
|
-
if (this.destroyed) return;
|
|
148
|
-
const host = this.barHost;
|
|
149
|
-
const bar = host.querySelector('.ge-shell-bottom') as HTMLElement | null;
|
|
150
|
-
if (!bar) return;
|
|
151
|
-
// reset to baseline (idempotent — the pill may have been lifted on a prior pass)
|
|
152
|
-
const pill = host.querySelector('.ge-winpill') as HTMLElement | null;
|
|
153
|
-
if (pill && pill.parentElement === host) { // put a lifted pill back inline
|
|
154
|
-
const right = bar.querySelector('.ge-zone-right');
|
|
155
|
-
if (right) bar.insertBefore(pill, right); else bar.appendChild(pill);
|
|
156
|
-
pill.classList.remove('ge-up');
|
|
157
|
-
}
|
|
158
|
-
host.classList.remove('ge-fit');
|
|
159
|
-
host.style.transform = '';
|
|
160
|
-
host.style.transformOrigin = '';
|
|
161
|
-
// clear any per-zone scale/zoom from a prior pass
|
|
162
|
-
for (const el of host.querySelectorAll('.ge-zone, .ge-winpill')) {
|
|
163
|
-
(el as HTMLElement).style.transform = '';
|
|
164
|
-
(el as HTMLElement).style.transformOrigin = '';
|
|
165
|
-
(el as HTMLElement).style.removeProperty('zoom');
|
|
166
|
-
}
|
|
167
|
-
if (this.layout === 'mobile') {
|
|
168
|
-
// Shrink the whole stack to fit narrow phones (mobile-s, or big balance/win/total-win
|
|
169
|
-
// numbers in a row). The rows use space-between, so on overflow their content is
|
|
170
|
-
// left-anchored and spills off the RIGHT edge — scale from the bottom-left corner so
|
|
171
|
-
// `avail/need` fits it exactly. (The old centre-origin + 0.7 floor left large numbers
|
|
172
|
-
// running past the screen edge; the 0.4 floor only guards a degenerate near-zero bar.)
|
|
173
|
-
let need = 0;
|
|
174
|
-
for (const row of Array.from(bar.children) as HTMLElement[]) need = Math.max(need, row.scrollWidth);
|
|
175
|
-
const avail = bar.clientWidth;
|
|
176
|
-
if (need > avail + 1 && avail > 0) {
|
|
177
|
-
host.style.transformOrigin = 'bottom left';
|
|
178
|
-
host.style.transform = `scale(${Math.max(0.4, avail / need).toFixed(4)})`;
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// ONE fit-scale, from the SCREEN SIZE, applied identically in EVERY mode — switching base⇄replay
|
|
183
|
-
// must not resize the bar. The factor is the frame WIDTH vs the bar's design width, never the
|
|
184
|
-
// current mode's content width.
|
|
185
|
-
//
|
|
186
|
-
// It's applied with `zoom` (not `transform`): zoom shrinks the LAYOUT, so the zones genuinely
|
|
187
|
-
// take less room and still sit edge-to-edge (menu hard-left, controls hard-right) even when base's
|
|
188
|
-
// wide row would overflow a merely-visually-scaled bar — so there is no per-mode centred cluster
|
|
189
|
-
// and no width/mode branching. A wide WIN pill is still lifted above the row first so it can't
|
|
190
|
-
// shove the controls off-screen. (Mobile, above, keeps its own stacked fit.)
|
|
191
|
-
if (pill && bar.scrollWidth > bar.clientWidth + 1) { host.insertBefore(pill, bar); pill.classList.add('ge-up'); }
|
|
192
|
-
const zoomBar = (z: number): void => {
|
|
193
|
-
const v = z < 0.999 ? z.toFixed(4) : '';
|
|
194
|
-
for (const el of host.querySelectorAll('.ge-zone, .ge-winpill')) {
|
|
195
|
-
if (v) (el as HTMLElement).style.setProperty('zoom', v);
|
|
196
|
-
else (el as HTMLElement).style.removeProperty('zoom');
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
const s = Math.max(GameShell.BAR_MIN_SCALE, Math.min(1, this.root.clientWidth / GameShell.BAR_REF_WIDTH));
|
|
200
|
-
zoomBar(s);
|
|
201
|
-
// Safety: a pathologically long balance/win can still overflow the frame at the screen zoom —
|
|
202
|
-
// nudge the zoom down just enough that the far control (turbo) isn't clipped. Normal content
|
|
203
|
-
// never triggers this, so base and replay keep the SAME zoom (no size change on mode switch).
|
|
204
|
-
if (bar.scrollWidth > bar.clientWidth + 1 && bar.scrollWidth > 0) {
|
|
205
|
-
zoomBar(s * (bar.clientWidth / bar.scrollWidth));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** Pull window focus into the iframe on first pointer interaction so `document` keydown (the
|
|
210
|
-
* spacebar shortcut) fires. No-op / harmless when already focused or full-page. */
|
|
211
|
-
private pullFocus = (): void => { try { window.focus(); } catch { /* cross-origin / non-browser */ } };
|
|
212
|
-
|
|
213
|
-
setLayout(layout: 'wide' | 'mobile'): void {
|
|
214
|
-
if (layout === this.layout) return;
|
|
215
|
-
this.layout = layout;
|
|
216
|
-
this.render();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** Resolve a built-in shell string through the i18n resolver (translation + optional socialize). */
|
|
220
|
-
t(text: string): string { return this.i18n.t(text); }
|
|
221
|
-
|
|
222
|
-
/** Toggle the social vocabulary at runtime (rebuilds resolver, re-renders bar). */
|
|
223
|
-
setSocial(isSocial: boolean): void {
|
|
224
|
-
this.config.isSocial = isSocial;
|
|
225
|
-
this.i18n = createI18n({ language: this.config.language, isSocial });
|
|
226
|
-
this.render();
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** Swap the active language at runtime (rebuilds resolver, re-renders bar). */
|
|
230
|
-
setLanguage(lang: string): void {
|
|
231
|
-
this.config.language = lang;
|
|
232
|
-
this.i18n = createI18n({ language: lang, isSocial: this.config.isSocial });
|
|
233
|
-
this.render();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Recolour the shell at runtime (e.g. switch dark/light scheme). */
|
|
237
|
-
setTheme(theme: ThemeConfig): void {
|
|
238
|
-
this.config.theme = theme;
|
|
239
|
-
this.root.setAttribute('style', buildThemeVars(theme));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private observeLayout(): void {
|
|
243
|
-
const RO = (globalThis as { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;
|
|
244
|
-
if (typeof RO !== 'function') return; // jsdom: stays 'wide'
|
|
245
|
-
this.ro = new RO((entries) => {
|
|
246
|
-
const rect = entries[0]?.contentRect;
|
|
247
|
-
const w = rect?.width ?? 0, h = rect?.height ?? 0;
|
|
248
|
-
// portrait → stacked mobile; landscape (incl. popouts) → one row, scaled to fit if it overflows
|
|
249
|
-
this.setLayout(w !== 0 && h > w ? 'mobile' : 'wide');
|
|
250
|
-
this.applyFitScale();
|
|
251
|
-
this.fitModals(); // re-scale open card modals when the popout resizes
|
|
252
|
-
});
|
|
253
|
-
this.ro.observe(this.root);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private animateMoney(): void {
|
|
257
|
-
const fmt = (n: number) => formatCurrency(n, this.config.currency);
|
|
258
|
-
const fmtWin = (n: number) => formatCurrency(n, this.config.currency, true); // win: variable decimals
|
|
259
|
-
const bal = this.barHost.querySelector('[data-ge="balance"]') as HTMLElement | null;
|
|
260
|
-
const win = this.barHost.querySelector('[data-ge="win"]') as HTMLElement | null;
|
|
261
|
-
if (bal && this.state.balance !== this.prevBalance) this.moneyAnims.push(animateReadout(bal, this.prevBalance, this.state.balance, fmt));
|
|
262
|
-
if (win && this.state.win !== this.prevWin) this.moneyAnims.push(animateReadout(win, this.prevWin, this.state.win, fmtWin));
|
|
263
|
-
this.prevBalance = this.state.balance;
|
|
264
|
-
this.prevWin = this.state.win;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
setBalance(n: number): void { this.state.balance = n; this.render(); }
|
|
268
|
-
setWin(n: number): void { this.state.win = n; this.render(); }
|
|
269
|
-
setBet(n: number): void { this.state.bet = n; this.render(); }
|
|
270
|
-
setMode(mode: ShellMode): void {
|
|
271
|
-
if (mode === 'replay') this.state.replay = true; // sticky: a replay stays a replay across modes
|
|
272
|
-
this.state.mode = mode;
|
|
273
|
-
this.render();
|
|
274
|
-
}
|
|
275
|
-
setBusy(busy: boolean): void { this.state.busy = busy; this.render(); this.kbd?.notifyBusyChanged(busy); }
|
|
276
|
-
setAutoplay(a: AutoplayOptions): void { this.state.autoplay = a; this.render(); }
|
|
277
|
-
setTurbo(level: number): void { this.state.turbo = level; this.render(); }
|
|
278
|
-
/** Currency-aware money formatter for WIN amounts (variable decimals: 0.0041 stays 0.0041, not
|
|
279
|
-
* 0.00). The host hands this to a scene so games format money without knowing the currency. */
|
|
280
|
-
formatWin(value: number): string { return formatCurrency(value, this.config.currency, true); }
|
|
281
|
-
setBuyBonusEnabled(enabled: boolean): void { this.state.buyBonusEnabled = enabled; this.render(); }
|
|
282
|
-
setFreeSpins(fs: FreeSpinsState): void { this.state.freeSpins = fs; this.render(); }
|
|
283
|
-
|
|
284
|
-
private showModal(el: HTMLElement, onKey?: (e: KeyboardEvent) => boolean): void {
|
|
285
|
-
// The control that opened this overlay (menu/buy/auto) keeps DOM focus. Drop it, or a
|
|
286
|
-
// stray Space/Enter would natively re-activate that <button> and rebuild the modal — a
|
|
287
|
-
// visible flicker. Only relinquish focus we own (a shell control), never the host page's.
|
|
288
|
-
const active = document.activeElement as HTMLElement | null;
|
|
289
|
-
if (active && this.root.contains(active)) active.blur();
|
|
290
|
-
this.modalHost.innerHTML = '';
|
|
291
|
-
this.modalHost.appendChild(el);
|
|
292
|
-
this.modalOnKey = onKey;
|
|
293
|
-
this.fitModals();
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/** Uniformly scale every open centred card modal (`.ge-sheet`) down so it fits a short/narrow
|
|
297
|
-
* popout — the same idea as the bar's fit-scale. Covers the pickers, generic + replay modals,
|
|
298
|
-
* AND the buy-bonus confirm (which is hosted inside the overlay, not directly in modalHost).
|
|
299
|
-
* Full-screen overlays handle their own responsiveness (scroll + vh-clamp). */
|
|
300
|
-
fitModals(): void {
|
|
301
|
-
if (this.destroyed) return;
|
|
302
|
-
this.modalHost.querySelectorAll('.ge-sheet').forEach((el) => this.fitSheet(el as HTMLElement));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** Fraction of the frame a card modal may occupy; the rest is breathing-room margin. Keeps
|
|
306
|
-
* modals from filling a small popout edge-to-edge (so even short pickers scale down there). */
|
|
307
|
-
private static readonly MODAL_FIT = 0.86;
|
|
308
|
-
|
|
309
|
-
/** The bar's design width (px). When the frame is narrower, the bar fit-scales DOWN with the
|
|
310
|
-
* screen — the SAME factor in every mode, so replay/free-spins shrink like base instead of
|
|
311
|
-
* staying full-size on a popout. */
|
|
312
|
-
private static readonly BAR_REF_WIDTH = 840;
|
|
313
|
-
/** Lower bound on the bar fit-scale (guards a degenerate near-zero frame). */
|
|
314
|
-
private static readonly BAR_MIN_SCALE = 0.5;
|
|
315
|
-
|
|
316
|
-
private fitSheet(root: HTMLElement): void {
|
|
317
|
-
const card = root.querySelector('.ge-modal-card') as HTMLElement | null;
|
|
318
|
-
if (!card) return;
|
|
319
|
-
card.style.transform = ''; // reset before measuring the natural size
|
|
320
|
-
const availW = root.clientWidth, availH = root.clientHeight;
|
|
321
|
-
const w = card.offsetWidth, h = card.offsetHeight;
|
|
322
|
-
if (w <= 0 || h <= 0 || availW <= 0 || availH <= 0) return;
|
|
323
|
-
const fit = GameShell.MODAL_FIT;
|
|
324
|
-
const s = Math.min(1, (availW * fit) / w, (availH * fit) / h);
|
|
325
|
-
if (s < 0.999) card.style.transform = `scale(${s.toFixed(4)})`;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/** Activate a `feature` option (e.g. Ante): the bar shows the effective bet, tinted with
|
|
329
|
-
* the feature accent, and BUY BONUS becomes DISABLE. */
|
|
330
|
-
activateFeature(bonus: BonusOption): void {
|
|
331
|
-
this.state.activeFeature = bonus;
|
|
332
|
-
this.emit('featureActivate', { id: bonus.id });
|
|
333
|
-
this.render();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** Clear the active feature — reverts the bet readout and the BUY BONUS button. */
|
|
337
|
-
deactivateFeature(): void {
|
|
338
|
-
const prev = this.state.activeFeature;
|
|
339
|
-
if (!prev) return;
|
|
340
|
-
this.state.activeFeature = null;
|
|
341
|
-
this.emit('featureDeactivate', { id: prev.id });
|
|
342
|
-
this.render();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
openMenu(): void { this.emit('menuOpen'); this.openSettings(); }
|
|
346
|
-
openSettings(): void { this.emit('settingsOpen'); this.showModal(openSettingsModal(this)); }
|
|
347
|
-
openInfo(): void { this.emit('infoOpen'); const { root, onKey } = openGameInfoModal(this); this.showModal(root, onKey); }
|
|
348
|
-
openBuyBonus(): void {
|
|
349
|
-
if (this.config.onBonusBuy) { this.config.onBonusBuy(); return; } // game handles it (own UI)
|
|
350
|
-
const result = openBuyBonusOverlay(this);
|
|
351
|
-
if (result) this.showModal(result.root, result.onKey);
|
|
352
|
-
}
|
|
353
|
-
/** Open a generic, externally-driven modal (title + body + optional action buttons).
|
|
354
|
-
* Each action runs its `on` then closes; the ✕ shows when `availableClose` is true. */
|
|
355
|
-
openModal(opts: ModalOptions): void { this.showModal(buildModal(opts), opts.onKey); }
|
|
356
|
-
/** Programmatically dismiss whatever modal/overlay is currently shown (e.g. auto-close the
|
|
357
|
-
* reconnect overlay once the link is restored). No-op when nothing is open. */
|
|
358
|
-
closeModal(): void { this.modalOnKey = undefined; this.soundRefresh = null; this.modalHost.innerHTML = ''; }
|
|
359
|
-
|
|
360
|
-
/** Flip the shared sound state, notify the game (`settingChange({ key: 'sound' })`), and live-update
|
|
361
|
-
* the Settings speaker icon if that modal is open. Used by both the Settings toggle and Shift+M. */
|
|
362
|
-
setSound(on: boolean): void {
|
|
363
|
-
this.soundOn = on;
|
|
364
|
-
this.emit('settingChange', { key: 'sound', value: on });
|
|
365
|
-
this.soundRefresh?.(on);
|
|
366
|
-
}
|
|
367
|
-
/** The Settings modal registers an icon-updater while open (cleared on close). */
|
|
368
|
-
setSoundRefresh(fn: ((on: boolean) => void) | null): void { this.soundRefresh = fn; }
|
|
369
|
-
/** Open the non-dismissable replay summary modal (START REPLAY → onReplay → reopen). */
|
|
370
|
-
openReplay(opts: ReplayModalOptions): void {
|
|
371
|
-
if (this.destroyed) return;
|
|
372
|
-
this.showModal(buildReplayModal(this, opts));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/** Bet picker — list of available bets with an accent Confirm. */
|
|
376
|
-
openBetPicker(): void { const { root, onKey } = openBetModal(this); this.showModal(root, onKey); }
|
|
377
|
-
/** Autoplay picker — spin-count list; Confirm starts autoplay. */
|
|
378
|
-
openAutoplayPicker(): void { const { root, onKey } = openAutoplayModal(this); this.showModal(root, onKey); }
|
|
379
|
-
|
|
380
|
-
destroy(): Promise<void> {
|
|
381
|
-
if (this.destroyed) return Promise.resolve();
|
|
382
|
-
this.destroyed = true;
|
|
383
|
-
this.ro?.disconnect();
|
|
384
|
-
this.ro = null;
|
|
385
|
-
if (typeof document !== 'undefined') {
|
|
386
|
-
this.kbd?.detach();
|
|
387
|
-
document.removeEventListener('pointerdown', this.pullFocus, true);
|
|
388
|
-
}
|
|
389
|
-
this.cancelMoneyAnims();
|
|
390
|
-
this.removeAllListeners();
|
|
391
|
-
this.root.classList.add('ge-shell-hidden');
|
|
392
|
-
return new Promise<void>((resolve) => {
|
|
393
|
-
setTimeout(() => {
|
|
394
|
-
this.root.remove();
|
|
395
|
-
this.styleEl.remove();
|
|
396
|
-
resolve();
|
|
397
|
-
}, REMOVE_FADE_MS);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/** Count-up the trailing text node of a .ge-rd readout (keeps its label span).
|
|
403
|
-
* Returns the count-up canceler so the shell can stop it before the node is replaced. */
|
|
404
|
-
function animateReadout(el: HTMLElement, from: number, to: number, fmt: (n: number) => string): () => void {
|
|
405
|
-
const textNode = el.lastChild;
|
|
406
|
-
if (!textNode || textNode.nodeType !== Node.TEXT_NODE) { el.textContent = fmt(to); return () => {}; }
|
|
407
|
-
const proxy = {
|
|
408
|
-
set textContent(v: string) { (textNode as Text).data = v; },
|
|
409
|
-
get textContent() { return (textNode as Text).data; },
|
|
410
|
-
} as unknown as HTMLElement;
|
|
411
|
-
return countUp(proxy, from, to, fmt);
|
|
412
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) Inter-Italic[opsz,wght].ttf: Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
|
2
|
-
|
|
3
|
-
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
-
This license is copied below, and is also available with a FAQ at:
|
|
5
|
-
http://scripts.sil.org/OFL
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-----------------------------------------------------------
|
|
9
|
-
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
-
-----------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
PREAMBLE
|
|
13
|
-
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
-
development of collaborative font projects, to support the font creation
|
|
15
|
-
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
-
open framework in which fonts may be shared and improved in partnership
|
|
17
|
-
with others.
|
|
18
|
-
|
|
19
|
-
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
-
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
-
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
-
redistributed and/or sold with any software provided that any reserved
|
|
23
|
-
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
-
however, cannot be released under any other type of license. The
|
|
25
|
-
requirement for fonts to remain under this license does not apply
|
|
26
|
-
to any document created using the fonts or their derivatives.
|
|
27
|
-
|
|
28
|
-
DEFINITIONS
|
|
29
|
-
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
-
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
-
include source files, build scripts and documentation.
|
|
32
|
-
|
|
33
|
-
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
-
copyright statement(s).
|
|
35
|
-
|
|
36
|
-
"Original Version" refers to the collection of Font Software components as
|
|
37
|
-
distributed by the Copyright Holder(s).
|
|
38
|
-
|
|
39
|
-
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
-
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
-
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
-
new environment.
|
|
43
|
-
|
|
44
|
-
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
-
writer or other person who contributed to the Font Software.
|
|
46
|
-
|
|
47
|
-
PERMISSION & CONDITIONS
|
|
48
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
-
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
-
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
-
Software, subject to the following conditions:
|
|
52
|
-
|
|
53
|
-
1) Neither the Font Software nor any of its individual components,
|
|
54
|
-
in Original or Modified Versions, may be sold by itself.
|
|
55
|
-
|
|
56
|
-
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
-
redistributed and/or sold with any software, provided that each copy
|
|
58
|
-
contains the above copyright notice and this license. These can be
|
|
59
|
-
included either as stand-alone text files, human-readable headers or
|
|
60
|
-
in the appropriate machine-readable metadata fields within text or
|
|
61
|
-
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
-
|
|
63
|
-
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
-
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
-
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
-
presented to the users.
|
|
67
|
-
|
|
68
|
-
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
-
Software shall not be used to promote, endorse or advertise any
|
|
70
|
-
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
-
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
-
permission.
|
|
73
|
-
|
|
74
|
-
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
-
must be distributed entirely under this license, and must not be
|
|
76
|
-
distributed under any other license. The requirement for fonts to
|
|
77
|
-
remain under this license does not apply to any document created
|
|
78
|
-
using the Font Software.
|
|
79
|
-
|
|
80
|
-
TERMINATION
|
|
81
|
-
This license becomes null and void if any of the above conditions are
|
|
82
|
-
not met.
|
|
83
|
-
|
|
84
|
-
DISCLAIMER
|
|
85
|
-
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
-
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
-
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
-
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
-
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
-
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
-
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/src/shell/colors.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { BonusOption } from './types';
|
|
2
|
-
|
|
3
|
-
/** The single brand accent (purple). The bar accent default (theme.ts) and the buy-a-bonus
|
|
4
|
-
* card default both derive from this, so a rebrand only touches one constant. */
|
|
5
|
-
export const BRAND_ACCENT = '#8b5cf6';
|
|
6
|
-
|
|
7
|
-
/** Type-default accents for bonus options. A per-option `accentColor` overrides these. */
|
|
8
|
-
export const ACCENT_BONUS = BRAND_ACCENT; // brand purple — buy a bonus round
|
|
9
|
-
export const ACCENT_FEATURE = '#f0b429'; // gold — activate a base-game feature (e.g. Ante)
|
|
10
|
-
|
|
11
|
-
/** The accent a card/button/bet-tint uses: explicit override, else the type default. */
|
|
12
|
-
export function effectiveAccent(b: Pick<BonusOption, 'type' | 'accentColor'>): string {
|
|
13
|
-
return b.accentColor ?? (b.type === 'feature' ? ACCENT_FEATURE : ACCENT_BONUS);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Readable text colour for a solid accent button: dark on light accents, white on dark.
|
|
17
|
-
* Only #rgb / #rrggbb are measured; anything else (named, var(), etc.) → white. */
|
|
18
|
-
export function contrastText(accent: string): string {
|
|
19
|
-
const rgb = parseHex(accent);
|
|
20
|
-
if (!rgb) return '#ffffff';
|
|
21
|
-
// Relative luminance (sRGB, perceptual-ish). >0.6 → use dark ink.
|
|
22
|
-
const lum = (0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]) / 255;
|
|
23
|
-
return lum > 0.6 ? '#1a1205' : '#ffffff';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function parseHex(hex: string): [number, number, number] | null {
|
|
27
|
-
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
|
|
28
|
-
if (!m) return null;
|
|
29
|
-
let h = m[1];
|
|
30
|
-
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
|
31
|
-
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
32
|
-
}
|