@energy8platform/platform-core 0.20.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 +194 -0
- package/dist/index.cjs.js +1940 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +302 -2
- package/dist/index.esm.js +1938 -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 +6 -1
- package/scripts/build-shell-font.mjs +64 -0
- package/src/index.ts +16 -0
- 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,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
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { GameShell } from '../GameShell';
|
|
2
|
+
import type { BonusOption } from '../types';
|
|
3
|
+
import { formatCurrency } from '../format';
|
|
4
|
+
import { stepBet } from '../state';
|
|
5
|
+
import { effectiveAccent, contrastText } from '../colors';
|
|
6
|
+
import { createOverlay, createCardModal } from './primitives';
|
|
7
|
+
import { icon, type IconName } from './icons';
|
|
8
|
+
|
|
9
|
+
/** Buy-bonus overlay — a grid of art-forward cards, one per option. */
|
|
10
|
+
export function openBuyBonusOverlay(shell: GameShell): HTMLElement | null {
|
|
11
|
+
const bonuses = shell.config.features.buyBonus;
|
|
12
|
+
if (bonuses === false || bonuses.length === 0) return null;
|
|
13
|
+
|
|
14
|
+
const { root, body } = createOverlay({ title: shell.t('Buy bonus'), onClose: () => root.remove() });
|
|
15
|
+
root.dataset.ge = 'buybonus-overlay';
|
|
16
|
+
// Re-render the grid whenever the bet changes so every card's price stays live.
|
|
17
|
+
const renderGrid = () => {
|
|
18
|
+
body.innerHTML = '';
|
|
19
|
+
const grid = document.createElement('div'); grid.className = 'ge-bb-grid';
|
|
20
|
+
for (const bonus of bonuses) grid.appendChild(buildCard(shell, bonus, root));
|
|
21
|
+
body.appendChild(grid);
|
|
22
|
+
};
|
|
23
|
+
renderGrid();
|
|
24
|
+
root.appendChild(buildBetBar(shell, renderGrid)); // thin bottom footer, only as tall as the pill
|
|
25
|
+
return root;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Bet control — a compact −/+ pill around the live stake, in a thin footer at the screen bottom.
|
|
29
|
+
* Stepping repaints the value, re-prices the cards, and updates the control bar. */
|
|
30
|
+
function buildBetBar(shell: GameShell, onChange: () => void): HTMLElement {
|
|
31
|
+
const bar = document.createElement('div'); bar.className = 'ge-bb-betbar';
|
|
32
|
+
const pill = document.createElement('div'); pill.className = 'ge-bb-betpill';
|
|
33
|
+
const val = document.createElement('div'); val.className = 'ge-bb-betval';
|
|
34
|
+
const down = stepButton('bb-bet-down', 'minus');
|
|
35
|
+
const up = stepButton('bb-bet-up', 'plus');
|
|
36
|
+
// Mirror the control bar: disable a stepper at the end of the bet range, and lock both
|
|
37
|
+
// while busy — so changing the stake behaves identically here and on the bottom bar.
|
|
38
|
+
const paint = () => {
|
|
39
|
+
val.innerHTML = `<span>${shell.t('Bet')}</span><b>${formatCurrency(shell.state.bet, shell.config.currency)}</b>`;
|
|
40
|
+
const i = shell.state.availableBets.indexOf(shell.state.bet);
|
|
41
|
+
down.disabled = shell.state.busy || i <= 0;
|
|
42
|
+
up.disabled = shell.state.busy || i >= shell.state.availableBets.length - 1;
|
|
43
|
+
};
|
|
44
|
+
const step = (dir: 1 | -1) => () => {
|
|
45
|
+
const next = stepBet(shell.state, dir);
|
|
46
|
+
if (next === shell.state.bet) return;
|
|
47
|
+
shell.state.bet = next; shell.emit('betChange', next); shell.render();
|
|
48
|
+
paint(); onChange();
|
|
49
|
+
};
|
|
50
|
+
down.addEventListener('click', step(-1));
|
|
51
|
+
up.addEventListener('click', step(1));
|
|
52
|
+
paint();
|
|
53
|
+
pill.append(down, val, up);
|
|
54
|
+
bar.appendChild(pill);
|
|
55
|
+
return bar;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function stepButton(ge: string, name: IconName): HTMLButtonElement {
|
|
59
|
+
const b = document.createElement('button');
|
|
60
|
+
b.className = 'ge-bb-betstep'; b.dataset.ge = ge; b.innerHTML = icon(name);
|
|
61
|
+
return b;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A grid card: title → thumbnail → description → volatility → price → full-bleed CTA.
|
|
65
|
+
* Clicking (when affordable) opens the confirmation modal. */
|
|
66
|
+
function buildCard(shell: GameShell, bonus: BonusOption, overlay: HTMLElement): HTMLElement {
|
|
67
|
+
const accent = effectiveAccent(bonus);
|
|
68
|
+
const card = document.createElement('div');
|
|
69
|
+
card.className = 'ge-bonus-card'; card.dataset.ge = `bonus-card-${bonus.id}`;
|
|
70
|
+
card.style.setProperty('--card-acc', accent);
|
|
71
|
+
card.style.setProperty('--card-ink', contrastText(accent));
|
|
72
|
+
card.appendChild(cardBody(shell, bonus));
|
|
73
|
+
|
|
74
|
+
const cta = document.createElement('button');
|
|
75
|
+
cta.className = 'ge-bonus-cta'; cta.dataset.ge = `bonus-cta-${bonus.id}`;
|
|
76
|
+
cta.textContent = shell.t(actionLabel(bonus));
|
|
77
|
+
card.appendChild(cta);
|
|
78
|
+
|
|
79
|
+
const enabled = isAffordable(shell, bonus);
|
|
80
|
+
if (!enabled) {
|
|
81
|
+
card.classList.add('ge-bonus-off');
|
|
82
|
+
cta.disabled = true;
|
|
83
|
+
} else {
|
|
84
|
+
// Stack the confirm on top of the overlay grid (cancel returns to the grid).
|
|
85
|
+
card.addEventListener('click', () => { overlay.appendChild(buildConfirm(shell, bonus, overlay)); shell.fitModals(); });
|
|
86
|
+
}
|
|
87
|
+
return card;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The shared card interior (everything above the action area), reused by the confirm modal. */
|
|
91
|
+
function cardBody(shell: GameShell, bonus: BonusOption): HTMLElement {
|
|
92
|
+
const price = bonus.priceMultiplier * shell.state.bet;
|
|
93
|
+
const wrap = document.createElement('div'); wrap.className = 'ge-bonus-body';
|
|
94
|
+
wrap.innerHTML =
|
|
95
|
+
`<div class="ge-bonus-title">${bonus.title}</div>` +
|
|
96
|
+
`<div class="ge-bonus-thumb">${thumb(bonus)}</div>` +
|
|
97
|
+
`<div class="ge-bonus-desc">${bonus.description}</div>` +
|
|
98
|
+
`<div class="ge-bonus-spacer"></div>` +
|
|
99
|
+
(bonus.volatility ? `<div class="ge-bonus-vol">${volatility(bonus.volatility)}</div>` : '') +
|
|
100
|
+
`<div class="ge-bonus-price">${formatCurrency(price, shell.config.currency)}</div>`;
|
|
101
|
+
return wrap;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Confirmation modal — the shared card chrome (accent title heading, no ✕) with a bonus
|
|
105
|
+
* preview body and a full-bleed Cancel + action footer. */
|
|
106
|
+
function buildConfirm(shell: GameShell, bonus: BonusOption, overlay: HTMLElement): HTMLElement {
|
|
107
|
+
const accent = effectiveAccent(bonus);
|
|
108
|
+
const ui = createCardModal({ ge: 'bonus-confirm', title: bonus.title, accent, onClose: () => ui.root.remove() });
|
|
109
|
+
|
|
110
|
+
const price = bonus.priceMultiplier * shell.state.bet;
|
|
111
|
+
const preview = document.createElement('div'); preview.className = 'ge-confirm-preview';
|
|
112
|
+
preview.innerHTML =
|
|
113
|
+
`<div class="ge-bonus-thumb">${thumb(bonus)}</div>` +
|
|
114
|
+
`<div class="ge-bonus-desc">${bonus.description}</div>` +
|
|
115
|
+
(bonus.volatility ? `<div class="ge-bonus-vol">${volatility(bonus.volatility)}</div>` : '') +
|
|
116
|
+
`<div class="ge-bonus-price">${formatCurrency(price, shell.config.currency)}</div>`;
|
|
117
|
+
ui.body.appendChild(preview);
|
|
118
|
+
|
|
119
|
+
const actions = document.createElement('div'); actions.className = 'ge-modal-actions';
|
|
120
|
+
const cancel = document.createElement('button');
|
|
121
|
+
cancel.className = 'ge-modal-btn ge-modal-btn--ghost'; cancel.dataset.ge = 'bonus-confirm-cancel';
|
|
122
|
+
cancel.textContent = shell.t('Cancel');
|
|
123
|
+
cancel.addEventListener('click', () => ui.root.remove());
|
|
124
|
+
const buy = document.createElement('button');
|
|
125
|
+
buy.className = 'ge-modal-btn ge-modal-btn--accent'; buy.dataset.ge = 'bonus-confirm-buy';
|
|
126
|
+
buy.textContent = shell.t(actionLabel(bonus));
|
|
127
|
+
buy.style.color = contrastText(accent); // bg comes from --card-acc on the card
|
|
128
|
+
buy.addEventListener('click', () => {
|
|
129
|
+
// Re-check at click time: the confirm modal stays open across state changes, so a spin
|
|
130
|
+
// starting (busy), buy-bonus being disabled, or the balance dropping must block the purchase.
|
|
131
|
+
if (!isAffordable(shell, bonus)) return;
|
|
132
|
+
if (bonus.type === 'feature') shell.activateFeature(bonus);
|
|
133
|
+
else shell.emit('buyBonusSelect', { id: bonus.id });
|
|
134
|
+
ui.root.remove();
|
|
135
|
+
overlay.remove();
|
|
136
|
+
});
|
|
137
|
+
actions.append(cancel, buy);
|
|
138
|
+
ui.card.appendChild(actions);
|
|
139
|
+
|
|
140
|
+
return ui.root;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function thumb(bonus: BonusOption): string {
|
|
144
|
+
if (bonus.thumbnail) return `<img src="${bonus.thumbnail}" alt="${bonus.title}">`;
|
|
145
|
+
return `<span class="ge-bonus-thumb-ph">${icon('gift')}</span>`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Volatility as five lightning bolts (the supplied SVG); `level` lit in the accent, rest dimmed. */
|
|
149
|
+
function volatility(level: number): string {
|
|
150
|
+
const n = Math.max(0, Math.min(5, level));
|
|
151
|
+
const bolt = icon('lightning');
|
|
152
|
+
return `<span class="ge-bonus-vol-on">${bolt.repeat(n)}</span>` +
|
|
153
|
+
`<span class="ge-bonus-vol-off">${bolt.repeat(5 - n)}</span>`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function actionLabel(bonus: BonusOption): string {
|
|
157
|
+
return bonus.type === 'feature' ? 'Activate' : 'Buy';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function isAffordable(shell: GameShell, bonus: BonusOption): boolean {
|
|
161
|
+
if (shell.state.busy || !shell.state.buyBonusEnabled) return false;
|
|
162
|
+
return bonus.priceMultiplier * shell.state.bet <= shell.state.balance;
|
|
163
|
+
}
|