@energy8platform/platform-core 0.19.0 → 0.21.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 +238 -1
- package/dist/dev-bridge.cjs.js +104 -0
- package/dist/dev-bridge.cjs.js.map +1 -1
- package/dist/dev-bridge.d.ts +64 -1
- package/dist/dev-bridge.esm.js +104 -0
- package/dist/dev-bridge.esm.js.map +1 -1
- package/dist/index.cjs.js +2053 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +372 -2
- package/dist/index.esm.js +2051 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/shell.cjs.js +1993 -0
- package/dist/shell.cjs.js.map +1 -0
- package/dist/shell.d.ts +320 -0
- package/dist/shell.esm.js +1989 -0
- package/dist/shell.esm.js.map +1 -0
- package/package.json +7 -2
- package/scripts/build-shell-font.mjs +64 -0
- package/src/PlatformSession.ts +10 -0
- package/src/dev-bridge/DevBridge.ts +160 -2
- package/src/dev-bridge/index.ts +1 -1
- package/src/index.ts +17 -1
- package/src/shell/GameShell.ts +294 -0
- package/src/shell/INTER-LICENSE.txt +93 -0
- package/src/shell/colors.ts +32 -0
- package/src/shell/components/BottomBar.ts +217 -0
- package/src/shell/components/BuyBonus.ts +163 -0
- package/src/shell/components/GameInfo.ts +253 -0
- package/src/shell/components/Modal.ts +36 -0
- package/src/shell/components/ReplayModal.ts +56 -0
- package/src/shell/components/Settings.ts +60 -0
- package/src/shell/components/icons.ts +40 -0
- package/src/shell/components/pickers.ts +76 -0
- package/src/shell/components/primitives.ts +84 -0
- package/src/shell/fonts.ts +13 -0
- package/src/shell/format.ts +36 -0
- package/src/shell/i18n.ts +67 -0
- package/src/shell/index.ts +20 -0
- package/src/shell/motion.ts +43 -0
- package/src/shell/shell.css.ts +371 -0
- package/src/shell/state.ts +30 -0
- package/src/shell/theme.ts +56 -0
- package/src/shell/types.ts +191 -0
|
@@ -0,0 +1,294 @@
|
|
|
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 { createInitialState } from './state';
|
|
15
|
+
import { buildThemeVars } from './theme';
|
|
16
|
+
import { SHELL_CSS, SHELL_ROOT_ID } from './shell.css';
|
|
17
|
+
import { renderBottomBar } from './components/BottomBar';
|
|
18
|
+
import { openSettingsModal } from './components/Settings';
|
|
19
|
+
import { openGameInfoModal } from './components/GameInfo';
|
|
20
|
+
import { openBuyBonusOverlay } from './components/BuyBonus';
|
|
21
|
+
import { openBetModal, openAutoplayModal } from './components/pickers';
|
|
22
|
+
import { buildModal } from './components/Modal';
|
|
23
|
+
import { buildReplayModal } from './components/ReplayModal';
|
|
24
|
+
import { countUp } from './motion';
|
|
25
|
+
import { formatCurrency } from './format';
|
|
26
|
+
import { socialize } from './i18n';
|
|
27
|
+
|
|
28
|
+
const REMOVE_FADE_MS = 300;
|
|
29
|
+
|
|
30
|
+
export class GameShell extends EventEmitter<ShellEvents> {
|
|
31
|
+
readonly config: ShellConfig;
|
|
32
|
+
state: ShellState;
|
|
33
|
+
private root: HTMLElement;
|
|
34
|
+
private styleEl: HTMLStyleElement;
|
|
35
|
+
private barHost = document.createElement('div');
|
|
36
|
+
private modalHost = document.createElement('div');
|
|
37
|
+
private destroyed = false;
|
|
38
|
+
layout: 'wide' | 'mobile' = 'wide';
|
|
39
|
+
private ro: ResizeObserver | null = null;
|
|
40
|
+
private prevBalance = 0;
|
|
41
|
+
private prevWin = 0;
|
|
42
|
+
private moneyAnims: Array<() => void> = [];
|
|
43
|
+
private keysBound = false;
|
|
44
|
+
|
|
45
|
+
constructor(config: ShellConfig) {
|
|
46
|
+
super();
|
|
47
|
+
this.config = config;
|
|
48
|
+
this.state = createInitialState(config);
|
|
49
|
+
|
|
50
|
+
this.styleEl = document.createElement('style');
|
|
51
|
+
this.styleEl.textContent = SHELL_CSS;
|
|
52
|
+
|
|
53
|
+
this.root = document.createElement('div');
|
|
54
|
+
this.root.id = SHELL_ROOT_ID;
|
|
55
|
+
this.root.setAttribute('style', buildThemeVars(config.theme));
|
|
56
|
+
|
|
57
|
+
config.mount.append(this.styleEl, this.root);
|
|
58
|
+
this.barHost.className = 'ge-shell-barhost';
|
|
59
|
+
this.root.appendChild(this.barHost);
|
|
60
|
+
this.modalHost.className = 'ge-shell-modalhost';
|
|
61
|
+
this.root.appendChild(this.modalHost);
|
|
62
|
+
this.prevBalance = this.state.balance;
|
|
63
|
+
this.prevWin = this.state.win;
|
|
64
|
+
this.observeLayout();
|
|
65
|
+
if (typeof document !== 'undefined') {
|
|
66
|
+
document.addEventListener('keydown', this.handleKeyDown);
|
|
67
|
+
this.keysBound = true;
|
|
68
|
+
}
|
|
69
|
+
this.render();
|
|
70
|
+
// re-fit once the bundled webfont swaps in (text metrics change → row width changes)
|
|
71
|
+
if (typeof document !== 'undefined' && document.fonts) {
|
|
72
|
+
document.fonts.ready.then(() => { if (!this.destroyed) this.applyFitScale(); });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
render(): void {
|
|
77
|
+
if (this.destroyed) return;
|
|
78
|
+
this.cancelMoneyAnims(); // stop in-flight count-ups before their nodes are torn down below
|
|
79
|
+
this.root.classList.toggle('ge-mobile', this.layout === 'mobile');
|
|
80
|
+
this.barHost.innerHTML = '';
|
|
81
|
+
this.barHost.appendChild(renderBottomBar(this));
|
|
82
|
+
this.animateMoney();
|
|
83
|
+
this.applyFitScale();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private cancelMoneyAnims(): void {
|
|
87
|
+
for (const cancel of this.moneyAnims) cancel();
|
|
88
|
+
this.moneyAnims = [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Keep the WIN pill inline between the groups; float it above when it won't fit. */
|
|
92
|
+
/**
|
|
93
|
+
* Landscape bar fills the width when it fits. When it overflows, the WIN pill is
|
|
94
|
+
* lifted above the bar (unscaled, so it stays readable) and the remaining row is
|
|
95
|
+
* centred and scaled down to fit — keeping the controls as large as possible.
|
|
96
|
+
*/
|
|
97
|
+
private applyFitScale(): void {
|
|
98
|
+
if (this.destroyed) return;
|
|
99
|
+
const host = this.barHost;
|
|
100
|
+
const bar = host.querySelector('.ge-shell-bottom') as HTMLElement | null;
|
|
101
|
+
if (!bar) return;
|
|
102
|
+
// reset to baseline (idempotent — the pill may have been lifted on a prior pass)
|
|
103
|
+
const pill = host.querySelector('.ge-winpill') as HTMLElement | null;
|
|
104
|
+
if (pill && pill.parentElement === host) { // put a lifted pill back inline
|
|
105
|
+
const right = bar.querySelector('.ge-zone-right');
|
|
106
|
+
if (right) bar.insertBefore(pill, right); else bar.appendChild(pill);
|
|
107
|
+
pill.classList.remove('ge-up');
|
|
108
|
+
}
|
|
109
|
+
host.classList.remove('ge-fit');
|
|
110
|
+
host.style.transform = '';
|
|
111
|
+
if (this.layout === 'mobile') {
|
|
112
|
+
// shrink the whole stack to fit narrow phones (mobile-s, or large numbers in a row)
|
|
113
|
+
let need = 0;
|
|
114
|
+
for (const row of Array.from(bar.children) as HTMLElement[]) need = Math.max(need, row.scrollWidth);
|
|
115
|
+
const avail = bar.clientWidth;
|
|
116
|
+
if (need > avail + 1 && avail > 0) host.style.transform = `scale(${Math.max(0.7, avail / need).toFixed(4)})`;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (bar.scrollWidth <= bar.clientWidth + 1) return; // bar fits inline → leave it
|
|
120
|
+
// overflow: lift the pill onto its own row above the bar (flex column → real 8px gap)
|
|
121
|
+
if (pill) { host.insertBefore(pill, bar); pill.classList.add('ge-up'); }
|
|
122
|
+
if (bar.scrollWidth <= bar.clientWidth + 1) return; // bar now fits full-width, pill above
|
|
123
|
+
// still too wide → shrink the whole stack (pill + bar) to fit, anchored bottom-centre
|
|
124
|
+
host.classList.add('ge-fit');
|
|
125
|
+
const natural = bar.offsetWidth, avail = this.root.clientWidth - 12;
|
|
126
|
+
const s = natural > 0 && avail > 0 ? Math.min(1, avail / natural) : 1;
|
|
127
|
+
host.style.transform = `translateX(-50%) scale(${s.toFixed(4)})`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Spacebar starts a spin — same path as the spin disc. Ignored while a spin is running,
|
|
131
|
+
* while autoplay is active, outside base mode, when an overlay/modal is open, or when an
|
|
132
|
+
* editable element is focused. `repeat` (held key) is ignored so it can't spam. */
|
|
133
|
+
private handleKeyDown = (e: KeyboardEvent): void => {
|
|
134
|
+
if (this.destroyed || e.code !== 'Space' || e.repeat) return;
|
|
135
|
+
const t = e.target as HTMLElement | null;
|
|
136
|
+
if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
|
|
137
|
+
if (this.modalHost.childElementCount > 0) return; // an overlay/modal is open
|
|
138
|
+
if (this.state.mode !== 'base' || this.state.busy || this.state.autoplay.active) return;
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
this.emit('spin');
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
setLayout(layout: 'wide' | 'mobile'): void {
|
|
144
|
+
if (layout === this.layout) return;
|
|
145
|
+
this.layout = layout;
|
|
146
|
+
this.render();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Resolve a built-in shell string. English is the source; with `isSocial` it is run through
|
|
150
|
+
* the social-casino word-swap. Game-supplied strings should NOT be passed through this. */
|
|
151
|
+
t(text: string): string { return this.config.isSocial ? socialize(text) : text; }
|
|
152
|
+
|
|
153
|
+
/** Toggle the social vocabulary at runtime (re-renders the bar; reopen overlays to refresh them). */
|
|
154
|
+
setSocial(isSocial: boolean): void { this.config.isSocial = isSocial; this.render(); }
|
|
155
|
+
|
|
156
|
+
/** Recolour the shell at runtime (e.g. switch dark/light scheme). */
|
|
157
|
+
setTheme(theme: ThemeConfig): void {
|
|
158
|
+
this.config.theme = theme;
|
|
159
|
+
this.root.setAttribute('style', buildThemeVars(theme));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private observeLayout(): void {
|
|
163
|
+
const RO = (globalThis as { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;
|
|
164
|
+
if (typeof RO !== 'function') return; // jsdom: stays 'wide'
|
|
165
|
+
this.ro = new RO((entries) => {
|
|
166
|
+
const rect = entries[0]?.contentRect;
|
|
167
|
+
const w = rect?.width ?? 0, h = rect?.height ?? 0;
|
|
168
|
+
// portrait → stacked mobile; landscape (incl. popouts) → one row, scaled to fit if it overflows
|
|
169
|
+
this.setLayout(w !== 0 && h > w ? 'mobile' : 'wide');
|
|
170
|
+
this.applyFitScale();
|
|
171
|
+
this.fitModals(); // re-scale open card modals when the popout resizes
|
|
172
|
+
});
|
|
173
|
+
this.ro.observe(this.root);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private animateMoney(): void {
|
|
177
|
+
const fmt = (n: number) => formatCurrency(n, this.config.currency);
|
|
178
|
+
const bal = this.barHost.querySelector('[data-ge="balance"]') as HTMLElement | null;
|
|
179
|
+
const win = this.barHost.querySelector('[data-ge="win"]') as HTMLElement | null;
|
|
180
|
+
if (bal && this.state.balance !== this.prevBalance) this.moneyAnims.push(animateReadout(bal, this.prevBalance, this.state.balance, fmt));
|
|
181
|
+
if (win && this.state.win !== this.prevWin) this.moneyAnims.push(animateReadout(win, this.prevWin, this.state.win, fmt));
|
|
182
|
+
this.prevBalance = this.state.balance;
|
|
183
|
+
this.prevWin = this.state.win;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
setBalance(n: number): void { this.state.balance = n; this.render(); }
|
|
187
|
+
setWin(n: number): void { this.state.win = n; this.render(); }
|
|
188
|
+
setBet(n: number): void { this.state.bet = n; this.render(); }
|
|
189
|
+
setMode(mode: ShellMode): void { this.state.mode = mode; this.render(); }
|
|
190
|
+
setBusy(busy: boolean): void { this.state.busy = busy; this.render(); }
|
|
191
|
+
setAutoplay(a: AutoplayOptions): void { this.state.autoplay = a; this.render(); }
|
|
192
|
+
setTurbo(level: number): void { this.state.turbo = level; this.render(); }
|
|
193
|
+
setBuyBonusEnabled(enabled: boolean): void { this.state.buyBonusEnabled = enabled; this.render(); }
|
|
194
|
+
setFreeSpins(fs: FreeSpinsState): void { this.state.freeSpins = fs; this.render(); }
|
|
195
|
+
|
|
196
|
+
private showModal(el: HTMLElement): void {
|
|
197
|
+
this.modalHost.innerHTML = '';
|
|
198
|
+
this.modalHost.appendChild(el);
|
|
199
|
+
this.fitModals();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Uniformly scale every open centred card modal (`.ge-sheet`) down so it fits a short/narrow
|
|
203
|
+
* popout — the same idea as the bar's fit-scale. Covers the pickers, generic + replay modals,
|
|
204
|
+
* AND the buy-bonus confirm (which is hosted inside the overlay, not directly in modalHost).
|
|
205
|
+
* Full-screen overlays handle their own responsiveness (scroll + vh-clamp). */
|
|
206
|
+
fitModals(): void {
|
|
207
|
+
if (this.destroyed) return;
|
|
208
|
+
this.modalHost.querySelectorAll('.ge-sheet').forEach((el) => this.fitSheet(el as HTMLElement));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Fraction of the frame a card modal may occupy; the rest is breathing-room margin. Keeps
|
|
212
|
+
* modals from filling a small popout edge-to-edge (so even short pickers scale down there). */
|
|
213
|
+
private static readonly MODAL_FIT = 0.86;
|
|
214
|
+
|
|
215
|
+
private fitSheet(root: HTMLElement): void {
|
|
216
|
+
const card = root.querySelector('.ge-modal-card') as HTMLElement | null;
|
|
217
|
+
if (!card) return;
|
|
218
|
+
card.style.transform = ''; // reset before measuring the natural size
|
|
219
|
+
const availW = root.clientWidth, availH = root.clientHeight;
|
|
220
|
+
const w = card.offsetWidth, h = card.offsetHeight;
|
|
221
|
+
if (w <= 0 || h <= 0 || availW <= 0 || availH <= 0) return;
|
|
222
|
+
const fit = GameShell.MODAL_FIT;
|
|
223
|
+
const s = Math.min(1, (availW * fit) / w, (availH * fit) / h);
|
|
224
|
+
if (s < 0.999) card.style.transform = `scale(${s.toFixed(4)})`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Activate a `feature` option (e.g. Ante): the bar shows the effective bet, tinted with
|
|
228
|
+
* the feature accent, and BUY BONUS becomes DISABLE. */
|
|
229
|
+
activateFeature(bonus: BonusOption): void {
|
|
230
|
+
this.state.activeFeature = bonus;
|
|
231
|
+
this.emit('featureActivate', { id: bonus.id });
|
|
232
|
+
this.render();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Clear the active feature — reverts the bet readout and the BUY BONUS button. */
|
|
236
|
+
deactivateFeature(): void {
|
|
237
|
+
const prev = this.state.activeFeature;
|
|
238
|
+
if (!prev) return;
|
|
239
|
+
this.state.activeFeature = null;
|
|
240
|
+
this.emit('featureDeactivate', { id: prev.id });
|
|
241
|
+
this.render();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
openMenu(): void { this.emit('menuOpen'); this.openSettings(); }
|
|
245
|
+
openSettings(): void { this.emit('settingsOpen'); this.showModal(openSettingsModal(this)); }
|
|
246
|
+
openInfo(): void { this.emit('infoOpen'); this.showModal(openGameInfoModal(this)); }
|
|
247
|
+
openBuyBonus(): void {
|
|
248
|
+
const overlay = openBuyBonusOverlay(this);
|
|
249
|
+
if (overlay) this.showModal(overlay);
|
|
250
|
+
}
|
|
251
|
+
/** Open a generic, externally-driven modal (title + body + optional action buttons).
|
|
252
|
+
* Each action runs its `on` then closes; the ✕ shows when `availableClose` is true. */
|
|
253
|
+
openModal(opts: ModalOptions): void { this.showModal(buildModal(opts)); }
|
|
254
|
+
/** Open the non-dismissable replay summary modal (START REPLAY → onReplay → reopen). */
|
|
255
|
+
openReplay(opts: ReplayModalOptions): void {
|
|
256
|
+
if (this.destroyed) return;
|
|
257
|
+
this.showModal(buildReplayModal(this, opts));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Bet picker — list of available bets with an accent Confirm. */
|
|
261
|
+
openBetPicker(): void { this.showModal(openBetModal(this)); }
|
|
262
|
+
/** Autoplay picker — spin-count list; Confirm starts autoplay. */
|
|
263
|
+
openAutoplayPicker(): void { this.showModal(openAutoplayModal(this)); }
|
|
264
|
+
|
|
265
|
+
destroy(): Promise<void> {
|
|
266
|
+
if (this.destroyed) return Promise.resolve();
|
|
267
|
+
this.destroyed = true;
|
|
268
|
+
this.ro?.disconnect();
|
|
269
|
+
this.ro = null;
|
|
270
|
+
if (this.keysBound) { document.removeEventListener('keydown', this.handleKeyDown); this.keysBound = false; }
|
|
271
|
+
this.cancelMoneyAnims();
|
|
272
|
+
this.removeAllListeners();
|
|
273
|
+
this.root.classList.add('ge-shell-hidden');
|
|
274
|
+
return new Promise<void>((resolve) => {
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
this.root.remove();
|
|
277
|
+
this.styleEl.remove();
|
|
278
|
+
resolve();
|
|
279
|
+
}, REMOVE_FADE_MS);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Count-up the trailing text node of a .ge-rd readout (keeps its label span).
|
|
285
|
+
* Returns the count-up canceler so the shell can stop it before the node is replaced. */
|
|
286
|
+
function animateReadout(el: HTMLElement, from: number, to: number, fmt: (n: number) => string): () => void {
|
|
287
|
+
const textNode = el.lastChild;
|
|
288
|
+
if (!textNode || textNode.nodeType !== Node.TEXT_NODE) { el.textContent = fmt(to); return () => {}; }
|
|
289
|
+
const proxy = {
|
|
290
|
+
set textContent(v: string) { (textNode as Text).data = v; },
|
|
291
|
+
get textContent() { return (textNode as Text).data; },
|
|
292
|
+
} as unknown as HTMLElement;
|
|
293
|
+
return countUp(proxy, from, to, fmt);
|
|
294
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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.
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { GameShell } from '../GameShell';
|
|
2
|
+
import { formatCurrency } from '../format';
|
|
3
|
+
import { stepBet, nextTurbo } from '../state';
|
|
4
|
+
import { effectiveAccent, contrastText } from '../colors';
|
|
5
|
+
import { icon, type IconName } from './icons';
|
|
6
|
+
import { twoLine } from './primitives';
|
|
7
|
+
|
|
8
|
+
/** A floating labelled money readout (balance/win/bet). */
|
|
9
|
+
function readout(ge: string, label: string, value: string): HTMLElement {
|
|
10
|
+
const el = document.createElement('div');
|
|
11
|
+
el.dataset.ge = ge;
|
|
12
|
+
el.className = `ge-rd ge-${ge}`;
|
|
13
|
+
el.innerHTML = `<span class="ge-lbl">${label}</span>`;
|
|
14
|
+
el.append(document.createTextNode(value));
|
|
15
|
+
return el;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Resting icon is turbo1 (1 line, grey via .ge-iconbtn); engaging turbo adds the
|
|
19
|
+
// .ge-active class which paints it white. Higher levels add more speed lines.
|
|
20
|
+
// level: 0 → turbo1 (grey), 1 → turbo1 (white), 2 → turbo2, 3 → turbo3.
|
|
21
|
+
function turboIcon(level: number): IconName {
|
|
22
|
+
return (['turbo1', 'turbo1', 'turbo2', 'turbo3'] as const)[Math.max(0, Math.min(3, level))];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A borderless icon button. */
|
|
26
|
+
function iconBtn(ge: string, name: IconName, onClick: () => void, active = false): HTMLButtonElement {
|
|
27
|
+
const b = document.createElement('button');
|
|
28
|
+
b.className = `ge-iconbtn${active ? ' ge-active' : ''}`;
|
|
29
|
+
b.dataset.ge = ge;
|
|
30
|
+
b.innerHTML = icon(name);
|
|
31
|
+
b.addEventListener('click', () => { if (!b.disabled) onClick(); });
|
|
32
|
+
return b;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function renderBottomBar(shell: GameShell): HTMLElement {
|
|
36
|
+
const { state, config } = shell;
|
|
37
|
+
const fmt = (n: number) => formatCurrency(n, config.currency);
|
|
38
|
+
const mobile = shell.layout === 'mobile';
|
|
39
|
+
const bar = document.createElement('div');
|
|
40
|
+
bar.className = 'ge-shell-bottom';
|
|
41
|
+
bar.dataset.geMode = state.mode;
|
|
42
|
+
|
|
43
|
+
// menu icon button (always)
|
|
44
|
+
const menu = iconBtn('menu', 'menu', () => shell.openMenu());
|
|
45
|
+
|
|
46
|
+
// All three modes share the base plaque layout. FS/replay hide the controls that
|
|
47
|
+
// don't apply; FS puts the spins counter in the centre pill (where WIN normally is).
|
|
48
|
+
const isBase = state.mode === 'base';
|
|
49
|
+
const isFS = state.mode === 'freeSpins';
|
|
50
|
+
|
|
51
|
+
const balance = readout('balance', shell.t('Balance'), fmt(state.balance));
|
|
52
|
+
// With a feature active (e.g. Ante) the BET readout shows the effective stake, tinted with
|
|
53
|
+
// the feature accent; the base state.bet is unchanged and returns once the feature is off.
|
|
54
|
+
const feature = state.activeFeature;
|
|
55
|
+
const betShown = feature ? state.bet * feature.priceMultiplier : state.bet;
|
|
56
|
+
const betValue = readout('bet-value', shell.t('Bet'), fmt(betShown));
|
|
57
|
+
if (feature) { betValue.classList.add('ge-bet-feature'); betValue.style.color = effectiveAccent(feature); }
|
|
58
|
+
const turbo = config.features.turbo > 0
|
|
59
|
+
? iconBtn('turbo', turboIcon(state.turbo), () => onTurbo(shell), state.turbo > 0) : null;
|
|
60
|
+
|
|
61
|
+
// interactive controls — base mode only
|
|
62
|
+
let betDown: HTMLElement | null = null, betUp: HTMLElement | null = null;
|
|
63
|
+
let spin: HTMLElement | null = null, auto: HTMLElement | null = null, buy: HTMLElement | null = null;
|
|
64
|
+
if (isBase) {
|
|
65
|
+
betDown = iconBtn('bet-down', 'minus', () => onBet(shell, -1));
|
|
66
|
+
betUp = iconBtn('bet-up', 'plus', () => onBet(shell, 1));
|
|
67
|
+
betValue.classList.add('ge-betbtn'); // tap the stake → bet picker
|
|
68
|
+
betValue.addEventListener('click', () => { if (!betLocked(shell)) shell.openBetPicker(); });
|
|
69
|
+
spin = spinButton(shell);
|
|
70
|
+
auto = config.features.autoplay ? autoButton(shell) : null;
|
|
71
|
+
buy = config.features.buyBonus !== false ? buyBtn(shell) : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const winEl = state.win > 0 ? readout('win', shell.t('Win'), fmt(state.win)) : null;
|
|
75
|
+
// FS readouts — the spins counter plus the accumulated/last win for the round.
|
|
76
|
+
const fsCounter = isFS ? readout('fs-counter', shell.t('Free spins'), `${state.freeSpins.current} / ${state.freeSpins.total}`) : null;
|
|
77
|
+
const fsTotalWin = isFS ? readout('fs-totalwin', shell.t('Total win'), fmt(state.freeSpins.totalWin)) : null;
|
|
78
|
+
const fsLastWin = isFS ? readout('fs-lastwin', shell.t('Last win'), fmt(state.freeSpins.lastWin)) : null;
|
|
79
|
+
|
|
80
|
+
if (mobile) {
|
|
81
|
+
// rows: [balance · win/(FS last+total)] · [menu · auto · (spin | FS counter) · turbo · buy] · [− bet +]
|
|
82
|
+
bar.appendChild(plaque('ge-m-top ge-pl ge-pl-glass', compact([balance, winEl, fsLastWin, fsTotalWin])));
|
|
83
|
+
const center = isBase ? spin : fsCounter;
|
|
84
|
+
bar.appendChild(plaque('ge-m-controls ge-pl-dark', compact([menu, auto, center, turbo, buy])));
|
|
85
|
+
bar.appendChild(plaque('ge-m-bet ge-pl ge-pl-dark', compact([betDown, betValue, betUp])));
|
|
86
|
+
} else {
|
|
87
|
+
// LEFT: [menu] ⊐ BUY BONUS coin ⊏ [balance]
|
|
88
|
+
const menuPlaque = plaque('ge-pl ge-pl-dark ge-pl-menu', [menu]);
|
|
89
|
+
const balPlaque = plaque('ge-pl ge-pl-glass ge-pl-bal', [balance]);
|
|
90
|
+
const left = zone('ge-zone-left ge-zone-plaques', ...compact([menuPlaque, buy, balPlaque]));
|
|
91
|
+
|
|
92
|
+
// RIGHT: [bet (+ step)] · |divider| · [auto · SPIN · turbo]
|
|
93
|
+
const betKids: HTMLElement[] = [betValue];
|
|
94
|
+
if (betUp && betDown) {
|
|
95
|
+
const step = document.createElement('div'); step.className = 'ge-betstep'; step.append(betUp, betDown);
|
|
96
|
+
betKids.push(step);
|
|
97
|
+
}
|
|
98
|
+
const betPlaque = plaque('ge-pl ge-pl-dark ge-pl-bet', betKids);
|
|
99
|
+
const divider = document.createElement('div'); divider.className = 'ge-pl-divider';
|
|
100
|
+
const spinWrap = document.createElement('div'); spinWrap.className = 'ge-spinwrap ge-pl-dark';
|
|
101
|
+
spinWrap.append(...compact([auto, spin, turbo]));
|
|
102
|
+
const right = zone('ge-zone-right ge-zone-plaques', betPlaque, divider, spinWrap);
|
|
103
|
+
|
|
104
|
+
// MIDDLE: FS → last win · counter · total win plaque; base/replay → WIN pill (lifts on overflow)
|
|
105
|
+
let middle: HTMLElement | null = null;
|
|
106
|
+
if (isFS) middle = plaque('ge-pl ge-pl-glass ge-fscount', compact([fsLastWin, fsCounter, fsTotalWin]));
|
|
107
|
+
else if (winEl) { winEl.classList.add('ge-winpill'); middle = winEl; }
|
|
108
|
+
bar.append(...compact([left, middle, right]));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
applyBusy(shell, bar);
|
|
112
|
+
return bar;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function zone(cls: string, ...children: HTMLElement[]): HTMLElement {
|
|
116
|
+
const z = document.createElement('div');
|
|
117
|
+
z.className = `ge-zone ${cls}`;
|
|
118
|
+
z.append(...children);
|
|
119
|
+
return z;
|
|
120
|
+
}
|
|
121
|
+
/** A rounded background panel ("plaque") grouping a set of controls. */
|
|
122
|
+
function plaque(cls: string, children: HTMLElement[]): HTMLElement {
|
|
123
|
+
const d = document.createElement('div');
|
|
124
|
+
d.className = cls;
|
|
125
|
+
d.append(...children);
|
|
126
|
+
return d;
|
|
127
|
+
}
|
|
128
|
+
function compact(items: (HTMLElement | null)[]): HTMLElement[] { return items.filter((x): x is HTMLElement => x !== null); }
|
|
129
|
+
|
|
130
|
+
function buyBtn(shell: GameShell): HTMLButtonElement {
|
|
131
|
+
const buy = document.createElement('button');
|
|
132
|
+
buy.className = 'ge-shell-buybonus'; buy.dataset.ge = 'buybonus';
|
|
133
|
+
const feature = shell.state.activeFeature;
|
|
134
|
+
if (feature) {
|
|
135
|
+
// A feature is active → this button turns into DISABLE (tinted with the feature accent).
|
|
136
|
+
const accent = effectiveAccent(feature);
|
|
137
|
+
buy.classList.add('ge-disable');
|
|
138
|
+
buy.innerHTML = `<span>${shell.t('DISABLE')}</span>`;
|
|
139
|
+
buy.style.background = accent; buy.style.color = contrastText(accent);
|
|
140
|
+
buy.addEventListener('click', () => { if (!buy.disabled) shell.deactivateFeature(); });
|
|
141
|
+
} else {
|
|
142
|
+
buy.innerHTML = `<span>${twoLine(shell.t('BUY BONUS'))}</span>`;
|
|
143
|
+
buy.addEventListener('click', () => { if (!buy.disabled) shell.openBuyBonus(); });
|
|
144
|
+
}
|
|
145
|
+
return buy;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function onBet(shell: GameShell, dir: 1 | -1): void {
|
|
149
|
+
if (shell.state.busy) return;
|
|
150
|
+
const next = stepBet(shell.state, dir);
|
|
151
|
+
if (next !== shell.state.bet) { shell.state.bet = next; shell.emit('betChange', next); shell.render(); }
|
|
152
|
+
}
|
|
153
|
+
function onTurbo(shell: GameShell): void {
|
|
154
|
+
const next = nextTurbo(shell.state.turbo, shell.config.features.turbo);
|
|
155
|
+
shell.state.turbo = next; shell.emit('turboChange', next); shell.render();
|
|
156
|
+
}
|
|
157
|
+
function betLocked(shell: GameShell): boolean {
|
|
158
|
+
return shell.state.busy || shell.state.autoplay.active;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** SPIN disc — rotates while busy; becomes a STOP + countdown while autoplay runs. */
|
|
162
|
+
function spinButton(shell: GameShell): HTMLButtonElement {
|
|
163
|
+
const { state } = shell;
|
|
164
|
+
const sp = document.createElement('button');
|
|
165
|
+
sp.className = 'ge-shell-spin'; sp.dataset.ge = 'spin';
|
|
166
|
+
if (state.autoplay.active) {
|
|
167
|
+
sp.classList.add('ge-stop');
|
|
168
|
+
const rem = state.autoplay.remaining;
|
|
169
|
+
const label = Number.isFinite(rem) ? String(rem) : '∞';
|
|
170
|
+
sp.innerHTML = `<span class="ge-spin-stop">${icon('stop')}</span><span class="ge-spin-count">${label}</span>`;
|
|
171
|
+
sp.addEventListener('click', () => { if (!sp.disabled) stopAutoplay(shell); });
|
|
172
|
+
} else {
|
|
173
|
+
sp.innerHTML = icon('spin');
|
|
174
|
+
if (state.busy) sp.classList.add('ge-spinning');
|
|
175
|
+
sp.addEventListener('click', () => { if (!sp.disabled) shell.emit('spin'); });
|
|
176
|
+
}
|
|
177
|
+
return sp;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Autoplay icon button — opens the count picker; glows accent while running. */
|
|
181
|
+
function autoButton(shell: GameShell): HTMLButtonElement {
|
|
182
|
+
const active = shell.state.autoplay.active;
|
|
183
|
+
const b = iconBtn('autoplay', 'autoplay', () => onAutoplay(shell), active);
|
|
184
|
+
if (active) b.classList.add('ge-glow');
|
|
185
|
+
return b;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function onAutoplay(shell: GameShell): void {
|
|
189
|
+
if (shell.state.autoplay.active) stopAutoplay(shell);
|
|
190
|
+
else shell.openAutoplayPicker();
|
|
191
|
+
}
|
|
192
|
+
function stopAutoplay(shell: GameShell): void {
|
|
193
|
+
shell.state.autoplay = { active: false, remaining: 0 };
|
|
194
|
+
shell.emit('autoplayStop');
|
|
195
|
+
shell.render();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function applyBusy(shell: GameShell, bar: HTMLElement): void {
|
|
199
|
+
const { busy } = shell.state;
|
|
200
|
+
const auto = shell.state.autoplay.active;
|
|
201
|
+
const lockBet = busy || auto;
|
|
202
|
+
const disable = (ge: string, off: boolean) => {
|
|
203
|
+
const el = bar.querySelector(`[data-ge="${ge}"]`) as HTMLButtonElement | null;
|
|
204
|
+
if (el) el.disabled = off;
|
|
205
|
+
};
|
|
206
|
+
// also disable the stepper that's already at the end of the bet range
|
|
207
|
+
const i = shell.state.availableBets.indexOf(shell.state.bet);
|
|
208
|
+
disable('bet-up', lockBet || i >= shell.state.availableBets.length - 1);
|
|
209
|
+
disable('bet-down', lockBet || i <= 0);
|
|
210
|
+
disable('spin', busy && !auto); // keep the STOP disc clickable through autoplay
|
|
211
|
+
disable('autoplay', busy && !auto); // keep autoplay (stop) clickable through autoplay
|
|
212
|
+
const betVal = bar.querySelector('[data-ge="bet-value"]') as HTMLElement | null;
|
|
213
|
+
if (betVal) betVal.classList.toggle('ge-disabled', lockBet);
|
|
214
|
+
const buy = bar.querySelector('[data-ge="buybonus"]') as HTMLButtonElement | null;
|
|
215
|
+
// disabled for the whole autoplay run (not just per-spin busy) so it doesn't flicker/pulse
|
|
216
|
+
if (buy) buy.disabled = busy || auto || !shell.state.buyBonusEnabled;
|
|
217
|
+
}
|