@wasm-gaming/blastem-wasm 0.1.3 → 0.2.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/blastem/app/app.css +4 -0
- package/dist/blastem/app/app.js +260 -68
- package/dist/blastem/blastem.controls.d.ts +58 -0
- package/dist/blastem/blastem.controls.d.ts.map +1 -0
- package/dist/blastem/blastem.controls.js +82 -0
- package/dist/blastem/blastem.controls.js.map +1 -0
- package/dist/blastem/blastem.options.d.ts.map +1 -1
- package/dist/blastem/blastem.options.js +6 -0
- package/dist/blastem/blastem.options.js.map +1 -1
- package/dist/blastem/blastem.sdk.d.ts +9 -1
- package/dist/blastem/blastem.sdk.d.ts.map +1 -1
- package/dist/blastem/blastem.sdk.js +51 -1
- package/dist/blastem/blastem.sdk.js.map +1 -1
- package/dist/blastem/blastem.wasm +0 -0
- package/dist/blastem/engine-specs.js +2218 -0
- package/package.json +2 -2
- package/src/app/app.css +4 -0
- package/src/app/app.js +260 -68
- package/src/blastem.options.ts +6 -0
- package/src/blastem.sdk.ts +50 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wasm-gaming/blastem-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "BlastEm (Sega Mega Drive / Genesis emulator) compiled to WebAssembly, with a self-contained JS SDK implementing the wasm-gaming engine contract.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/blastem/blastem.sdk.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"scripts": {},
|
|
32
32
|
"comment:dependencies": "engine-specs is the one wasm-gaming package an engine depends on. Its runtime is also copied into dist/blastem/ and imported relatively, so the built SDK loads without a bundler or an import map; the dependency carries the types.",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@wasm-gaming/engine-specs": "^0.
|
|
34
|
+
"@wasm-gaming/engine-specs": "^0.6.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.5.0"
|
package/src/app/app.css
CHANGED
|
@@ -163,3 +163,7 @@
|
|
|
163
163
|
@media (prefers-reduced-motion: reduce) {
|
|
164
164
|
.point, .point-frame, .bem-boot img, .bem-toast { transition: none; animation: none; }
|
|
165
165
|
}
|
|
166
|
+
|
|
167
|
+
/* Ajustes (engine-specs createSettingsScreen): over the pause menu, inside the safe areas. */
|
|
168
|
+
.bem-settings { padding: max(16px, var(--wg-safe-top, 0px)) 16px max(16px, var(--wg-safe-bottom, 0px)); }
|
|
169
|
+
.bem-settings .wg-settings { max-height: 100%; }
|
package/src/app/app.js
CHANGED
|
@@ -15,9 +15,96 @@
|
|
|
15
15
|
//
|
|
16
16
|
// Plain JS and DOM: it ships next to the SDK and imports nothing else.
|
|
17
17
|
|
|
18
|
-
import BlastemSDK, { AUTO_STATE_SLOT, STATE_SLOTS } from '../blastem.sdk.js';
|
|
18
|
+
import BlastemSDK, { AUTO_STATE_SLOT, BLASTEM_CONTROLS, STATE_SLOTS } from '../blastem.sdk.js';
|
|
19
|
+
import {
|
|
20
|
+
SHARED_SETTINGS,
|
|
21
|
+
controlsModel,
|
|
22
|
+
createFullscreenToggle,
|
|
23
|
+
createPerfCounter,
|
|
24
|
+
createSettingsScreen,
|
|
25
|
+
createWakeLock,
|
|
26
|
+
loadSettings,
|
|
27
|
+
resolveLocale,
|
|
28
|
+
saveSettings,
|
|
29
|
+
settingsDefaults,
|
|
30
|
+
settingsModel,
|
|
31
|
+
} from '../engine-specs.js';
|
|
19
32
|
|
|
20
33
|
const OWNER = 'app';
|
|
34
|
+
const ENGINE_ID = 'blastem';
|
|
35
|
+
|
|
36
|
+
/** The app's words, in English and Spanish (engine-specs UX.md, "Languages"). */
|
|
37
|
+
const STRINGS = {
|
|
38
|
+
booting: { en: 'Starting the engine…', es: 'Arrancando el motor…' },
|
|
39
|
+
today: { en: 'Today · {time}', es: 'Hoy · {time}' },
|
|
40
|
+
yesterday: { en: 'Yesterday · {time}', es: 'Ayer · {time}' },
|
|
41
|
+
slot: { en: 'slot', es: 'hueco' },
|
|
42
|
+
saveHere: { en: 'save here', es: 'guardar aquí' },
|
|
43
|
+
cancelHint: { en: 'cancel', es: 'cancelar' },
|
|
44
|
+
choose: { en: 'choose', es: 'elegir' },
|
|
45
|
+
playHint: { en: 'play', es: 'jugar' },
|
|
46
|
+
saveToSlot: { en: 'save to a slot', es: 'guardar en un hueco' },
|
|
47
|
+
options: { en: 'options', es: 'opciones' },
|
|
48
|
+
backHint: { en: 'back', es: 'volver' },
|
|
49
|
+
quitHint: { en: 'quit', es: 'salir' },
|
|
50
|
+
saveHereOrOptions: { en: 'options', es: 'opciones' },
|
|
51
|
+
continueHint: { en: 'continue', es: 'continuar' },
|
|
52
|
+
fromStart: { en: 'From the beginning', es: 'Desde el principio' },
|
|
53
|
+
unsaved: { en: 'Unsaved', es: 'Sin guardar' },
|
|
54
|
+
empty: { en: 'Empty', es: 'Vacío' },
|
|
55
|
+
bootFailed: { en: 'Could not start', es: 'No se pudo arrancar' },
|
|
56
|
+
back: { en: 'Back', es: 'Volver' },
|
|
57
|
+
whichSlot: { en: 'Which slot does it go in?', es: '¿En qué hueco lo guardas?' },
|
|
58
|
+
points: { en: 'Suspend points', es: 'Puntos de suspensión' },
|
|
59
|
+
paused: { en: 'Paused', es: 'Pausa' },
|
|
60
|
+
point: { en: 'Point {n}', es: 'Punto {n}' },
|
|
61
|
+
continue: { en: 'Continue', es: 'Continuar' },
|
|
62
|
+
restart: { en: 'Restart', es: 'Reiniciar' },
|
|
63
|
+
restartHint: { en: 'console reset', es: 'reset de la consola' },
|
|
64
|
+
settings: { en: 'Settings', es: 'Ajustes' },
|
|
65
|
+
fullscreen: { en: 'Fullscreen', es: 'Pantalla completa' },
|
|
66
|
+
fullscreenHint: { en: 'Alt+Enter · Select + Y', es: 'Alt+Enter · Select + Y' },
|
|
67
|
+
fullscreenHintMac: { en: 'Cmd+Enter · Select + Y', es: 'Cmd+Enter · Select + Y' },
|
|
68
|
+
exit: { en: 'Back to the launcher', es: 'Volver al lanzador' },
|
|
69
|
+
exitHint: { en: 'a suspend point is kept', es: 'se queda un punto de suspensión' },
|
|
70
|
+
savedIn: { en: 'Saved in slot {n}', es: 'Guardado en el hueco {n}' },
|
|
71
|
+
loadFailed: { en: 'Could not load that point', es: 'No se pudo cargar ese punto' },
|
|
72
|
+
slotLocked: { en: 'That slot is locked', es: 'Ese hueco está bloqueado' },
|
|
73
|
+
allLocked: { en: 'The four slots are locked', es: 'Los cuatro huecos están bloqueados' },
|
|
74
|
+
load: { en: 'Load', es: 'Cargar' },
|
|
75
|
+
saveHereItem: { en: 'Save here', es: 'Guardar aquí' },
|
|
76
|
+
unlockFirst: { en: 'unlock it first', es: 'desbloquéalo antes' },
|
|
77
|
+
replaces: { en: 'replaces what is there', es: 'sustituye lo que hay' },
|
|
78
|
+
overwriteAsk: { en: 'Overwrite point {n}?', es: '¿Sobrescribir el punto {n}?' },
|
|
79
|
+
overwrite: { en: 'Overwrite', es: 'Sobrescribir' },
|
|
80
|
+
cancel: { en: 'Cancel', es: 'Cancelar' },
|
|
81
|
+
unlock: { en: 'Unlock', es: 'Desbloquear' },
|
|
82
|
+
lock: { en: 'Lock', es: 'Bloquear' },
|
|
83
|
+
unlockHint: { en: 'it can be overwritten and deleted', es: 'se podrá sobrescribir y borrar' },
|
|
84
|
+
lockHint: { en: 'so it is not overwritten or deleted', es: 'que no se sobrescriba ni se borre' },
|
|
85
|
+
delete: { en: 'Delete', es: 'Borrar' },
|
|
86
|
+
deleteAsk: { en: 'Delete point {n}?', es: '¿Borrar el punto {n}?' },
|
|
87
|
+
noUndo: { en: 'This cannot be undone.', es: 'No se puede deshacer.' },
|
|
88
|
+
saving: { en: 'Saving the suspend point…', es: 'Guardando el punto de suspensión…' },
|
|
89
|
+
leaveAsk: { en: 'Back to the launcher?', es: '¿Volver al lanzador?' },
|
|
90
|
+
leave: { en: 'Leave', es: 'Salir' },
|
|
91
|
+
stay: { en: 'Stay', es: 'Seguir' },
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const DIRECTIONS = {
|
|
95
|
+
up: { en: 'Up', es: 'Arriba' },
|
|
96
|
+
down: { en: 'Down', es: 'Abajo' },
|
|
97
|
+
left: { en: 'Left', es: 'Izquierda' },
|
|
98
|
+
right: { en: 'Right', es: 'Derecha' },
|
|
99
|
+
};
|
|
100
|
+
/** The Mega Drive pad's buttons, for Ajustes → Controles. */
|
|
101
|
+
const BUTTONS = BLASTEM_CONTROLS.map((c) => ({ id: c.id, label: DIRECTIONS[c.id] ?? c.label }));
|
|
102
|
+
const DEFAULT_CONTROLS = Object.fromEntries(BLASTEM_CONTROLS.map((c) => [c.id, { code: c.code, button: c.button }]));
|
|
103
|
+
/** Bindings (engine-specs) → what `play.setControls()` takes. */
|
|
104
|
+
const toBlastemControls = (bindings) => ({
|
|
105
|
+
keys: Object.fromEntries(Object.entries(bindings).filter(([, b]) => b.code).map(([id, b]) => [id, b.code])),
|
|
106
|
+
buttons: Object.fromEntries(Object.entries(bindings).filter(([, b]) => Number.isInteger(b.button)).map(([id, b]) => [id, b.button])),
|
|
107
|
+
});
|
|
21
108
|
const esc = (text) => String(text ?? '').replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
22
109
|
|
|
23
110
|
let cssLoaded = null;
|
|
@@ -30,15 +117,15 @@ const loadCss = () =>
|
|
|
30
117
|
document.head.append(link);
|
|
31
118
|
}));
|
|
32
119
|
|
|
33
|
-
const
|
|
120
|
+
const whenIn = (t, locale) => (date) => {
|
|
34
121
|
if (!date) return '';
|
|
35
122
|
const now = new Date();
|
|
36
|
-
const time = date.toLocaleTimeString(
|
|
37
|
-
if (date.toDateString() === now.toDateString()) return
|
|
123
|
+
const time = date.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' });
|
|
124
|
+
if (date.toDateString() === now.toDateString()) return t('today', { time });
|
|
38
125
|
const yesterday = new Date(now);
|
|
39
126
|
yesterday.setDate(now.getDate() - 1);
|
|
40
|
-
if (date.toDateString() === yesterday.toDateString()) return
|
|
41
|
-
return `${date.toLocaleDateString(
|
|
127
|
+
if (date.toDateString() === yesterday.toDateString()) return t('yesterday', { time });
|
|
128
|
+
return `${date.toLocaleDateString(locale, { day: 'numeric', month: 'short' })} · ${time}`;
|
|
42
129
|
};
|
|
43
130
|
|
|
44
131
|
const LOCK = '<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M4.5 7V5a3.5 3.5 0 0 1 7 0v2h.5a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1zm1.6 0h3.8V5a1.9 1.9 0 0 0-3.8 0z"/></svg>';
|
|
@@ -47,6 +134,11 @@ const RESTART = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="none" s
|
|
|
47
134
|
export async function mount(target, host) {
|
|
48
135
|
await loadCss();
|
|
49
136
|
|
|
137
|
+
const locale = host.locale ?? resolveLocale();
|
|
138
|
+
const t = (key, params = {}) =>
|
|
139
|
+
(STRINGS[key]?.[locale] ?? STRINGS[key]?.en ?? key).replace(/\{(\w+)\}/g, (m, name) => (name in params ? String(params[name]) : m));
|
|
140
|
+
const when = whenIn(t, locale);
|
|
141
|
+
|
|
50
142
|
const root = document.createElement('div');
|
|
51
143
|
root.className = 'bem-app';
|
|
52
144
|
root.style.setProperty('--accent', host.game?.accent ?? '#9f1239');
|
|
@@ -64,13 +156,14 @@ export async function mount(target, host) {
|
|
|
64
156
|
*/
|
|
65
157
|
const state = {
|
|
66
158
|
screen: 'boot',
|
|
67
|
-
status: '
|
|
159
|
+
status: t('booting'),
|
|
68
160
|
error: null,
|
|
69
161
|
cards: [], // [{ kind: 'start' | 'auto' | 'slot', slot, info }]
|
|
70
162
|
focus: 0,
|
|
71
163
|
from: 'boot',
|
|
72
164
|
picking: false,
|
|
73
|
-
// The pause menu: Continuar, the four slots (a row), Reiniciar,
|
|
165
|
+
// The pause menu: Continuar, the four slots (a row), Reiniciar, Ajustes, Pantalla completa,
|
|
166
|
+
// Volver al lanzador.
|
|
74
167
|
// focus: { kind: 'item' | 'slot', i }; col: the slot the row comes back to.
|
|
75
168
|
pause: { items: [], slots: [], focus: { kind: 'item', i: 0 }, col: 0 },
|
|
76
169
|
sheet: null, // { slot, items, focus }
|
|
@@ -131,28 +224,28 @@ export async function mount(target, host) {
|
|
|
131
224
|
if (card.kind === 'start') {
|
|
132
225
|
return `<button class="point is-start${focused}${dim}" data-card="${i}">
|
|
133
226
|
<span class="point-frame">${RESTART}</span>
|
|
134
|
-
<span class="point-label"
|
|
227
|
+
<span class="point-label">${esc(t('fromStart'))}</span>
|
|
135
228
|
<span class="point-date"> </span>
|
|
136
229
|
</button>`;
|
|
137
230
|
}
|
|
138
231
|
const { info } = card;
|
|
139
232
|
const empty = !info.savedAt;
|
|
140
|
-
const label = card.kind === 'auto' ? '
|
|
233
|
+
const label = card.kind === 'auto' ? t('unsaved') : `${card.slot + 1}`;
|
|
141
234
|
return `<button class="point${card.kind === 'auto' ? ' is-auto' : ''}${empty ? ' is-empty' : ''}${info.locked ? ' is-locked' : ''}${focused}${target}${dim}" data-card="${i}">
|
|
142
235
|
<span class="point-frame">${card.img ? `<img src="${card.img}" alt="">` : ''}${info.locked ? `<i class="point-lock">${LOCK}</i>` : ''}</span>
|
|
143
236
|
<span class="point-label">${esc(label)}</span>
|
|
144
|
-
<span class="point-date">${empty ? '
|
|
237
|
+
<span class="point-date">${empty ? esc(t('empty')) : esc(when(info.savedAt))}</span>
|
|
145
238
|
</button>`;
|
|
146
239
|
};
|
|
147
240
|
|
|
148
241
|
const pointsHints = () => {
|
|
149
|
-
if (state.picking) return hints([['←→', '
|
|
242
|
+
if (state.picking) return hints([['←→', t('slot')], ['A', t('saveHere'), 'accept'], ['B', t('cancelHint'), 'back']]);
|
|
150
243
|
const card = cardAt(state.focus);
|
|
151
|
-
const pairs = [['←→', '
|
|
152
|
-
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', '
|
|
153
|
-
if (card?.kind === 'auto') pairs.push(['Y', '
|
|
154
|
-
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', '
|
|
155
|
-
pairs.push(['B', state.from === 'pause' ? '
|
|
244
|
+
const pairs = [['←→', t('choose')]];
|
|
245
|
+
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', t('playHint'), 'accept']);
|
|
246
|
+
if (card?.kind === 'auto') pairs.push(['Y', t('saveToSlot'), 'more']);
|
|
247
|
+
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', t('options'), 'more']);
|
|
248
|
+
pairs.push(['B', state.from === 'pause' ? t('backHint') : t('quitHint'), 'back']);
|
|
156
249
|
return hints(pairs);
|
|
157
250
|
};
|
|
158
251
|
|
|
@@ -161,7 +254,7 @@ export async function mount(target, host) {
|
|
|
161
254
|
return `<button class="slot${focused ? ' is-focused' : ''}${empty ? ' is-empty' : ''}${info.locked ? ' is-locked' : ''}" data-slot="${i}">
|
|
162
255
|
<span class="point-frame">${img ? `<img src="${img}" alt="">` : ''}${info.locked ? `<i class="point-lock">${LOCK}</i>` : ''}</span>
|
|
163
256
|
<span class="slot-label">${info.slot + 1}</span>
|
|
164
|
-
<span class="slot-date">${empty ? '
|
|
257
|
+
<span class="slot-date">${empty ? esc(t('empty')) : esc(when(info.savedAt))}</span>
|
|
165
258
|
</button>`;
|
|
166
259
|
};
|
|
167
260
|
|
|
@@ -169,15 +262,17 @@ export async function mount(target, host) {
|
|
|
169
262
|
const f = state.pause.focus;
|
|
170
263
|
if (f.kind === 'slot') {
|
|
171
264
|
const saved = !!state.pause.slots[f.i]?.info.savedAt;
|
|
172
|
-
return hints([['←→', '
|
|
265
|
+
return hints([['←→', t('slot')], ['A', saved ? t('options') : t('saveHere')], ['B', t('continueHint')]]);
|
|
173
266
|
}
|
|
174
267
|
// Gamepad-only: by touch, "Continuar" is the first item already.
|
|
175
|
-
return hints([['A', '
|
|
268
|
+
return hints([['A', t('choose')], ['B', t('continueHint')]]);
|
|
176
269
|
};
|
|
177
270
|
|
|
178
271
|
const render = () => {
|
|
179
272
|
if (destroyed) return;
|
|
180
273
|
const s = state.screen;
|
|
274
|
+
wake.setActive(s === 'game' && setting('keepScreenOn') !== false);
|
|
275
|
+
if (s === 'settings') return;
|
|
181
276
|
const base = s === 'confirm' || s === 'sheet' ? (state.confirm?.under ?? state.sheet?.under) : s;
|
|
182
277
|
root.dataset.screen = base;
|
|
183
278
|
if (s === 'game') {
|
|
@@ -194,9 +289,9 @@ export async function mount(target, host) {
|
|
|
194
289
|
if (s === 'error') {
|
|
195
290
|
overlay.innerHTML = `<section class="bem-panel">
|
|
196
291
|
<p class="kicker">${esc(host.game?.title ?? 'BlastEm')}</p>
|
|
197
|
-
<h2
|
|
292
|
+
<h2>${esc(t('bootFailed'))}</h2>
|
|
198
293
|
<p class="text">${esc(state.error)}</p>
|
|
199
|
-
<button class="item is-focused" data-exit
|
|
294
|
+
<button class="item is-focused" data-exit>${esc(t('back'))}</button>
|
|
200
295
|
</section>`;
|
|
201
296
|
return;
|
|
202
297
|
}
|
|
@@ -205,7 +300,7 @@ export async function mount(target, host) {
|
|
|
205
300
|
html += `<section class="bem-points">
|
|
206
301
|
<header>
|
|
207
302
|
<p class="kicker">${esc(host.game?.title ?? '')}</p>
|
|
208
|
-
<h2>${state.picking ? '
|
|
303
|
+
<h2>${esc(state.picking ? t('whichSlot') : t('points'))}</h2>
|
|
209
304
|
</header>
|
|
210
305
|
<div class="points">${state.cards.map(pointCard).join('')}</div>
|
|
211
306
|
${pointsHints()}
|
|
@@ -219,21 +314,20 @@ export async function mount(target, host) {
|
|
|
219
314
|
};
|
|
220
315
|
html += `<section class="bem-panel is-pause">
|
|
221
316
|
<p class="kicker">${esc(host.game?.title ?? '')}</p>
|
|
222
|
-
<h2
|
|
317
|
+
<h2>${esc(t('paused'))}</h2>
|
|
223
318
|
${item(0)}
|
|
224
|
-
<p class="slots-label"
|
|
319
|
+
<p class="slots-label">${esc(t('points'))}</p>
|
|
225
320
|
<div class="slots">${P.slots.map((slot, i) => slotCard(slot, i, on('slot', i))).join('')}</div>
|
|
226
|
-
${item(1)}
|
|
227
|
-
${item(2)}
|
|
321
|
+
${P.items.slice(1).map((_, i) => item(i + 1)).join('')}
|
|
228
322
|
${pauseHints()}
|
|
229
323
|
</section>`;
|
|
230
324
|
}
|
|
231
325
|
if (s === 'sheet') {
|
|
232
326
|
const sh = state.sheet;
|
|
233
327
|
html += `<div class="bem-layer"><section class="bem-panel is-small">
|
|
234
|
-
<h2
|
|
328
|
+
<h2>${esc(t('point', { n: sh.slot + 1 }))}</h2>
|
|
235
329
|
${sh.items.map((item, i) => `<button class="item${item.danger ? ' is-danger' : ''}${i === sh.focus ? ' is-focused' : ''}" data-sheet="${i}" ${item.disabled ? 'disabled' : ''}>${esc(item.label)}${item.hint ? `<small>${esc(item.hint)}</small>` : ''}</button>`).join('')}
|
|
236
|
-
${hints([['B', '
|
|
330
|
+
${hints([['B', t('backHint')]])}
|
|
237
331
|
</section></div>`;
|
|
238
332
|
}
|
|
239
333
|
if (s === 'confirm') {
|
|
@@ -314,9 +408,15 @@ export async function mount(target, host) {
|
|
|
314
408
|
col: state.pause.col ?? 0,
|
|
315
409
|
slots: [],
|
|
316
410
|
items: [
|
|
317
|
-
{ label: '
|
|
318
|
-
{ label: '
|
|
319
|
-
{ label: '
|
|
411
|
+
{ label: t('continue'), run: enterGame },
|
|
412
|
+
{ label: t('restart'), hint: t('restartHint'), run: restart },
|
|
413
|
+
{ label: t('settings'), run: openSettings },
|
|
414
|
+
{
|
|
415
|
+
label: t('fullscreen'),
|
|
416
|
+
hint: /mac|iphone|ipad/i.test(navigator.userAgentData?.platform || navigator.platform || '') ? t('fullscreenHintMac') : t('fullscreenHint'),
|
|
417
|
+
run: () => fullscreen.toggle(),
|
|
418
|
+
},
|
|
419
|
+
{ label: t('exit'), hint: t('exitHint'), run: leave },
|
|
320
420
|
],
|
|
321
421
|
};
|
|
322
422
|
readPauseSlots();
|
|
@@ -342,14 +442,14 @@ export async function mount(target, host) {
|
|
|
342
442
|
const { info } = state.pause.slots[i];
|
|
343
443
|
await play.states.save(info.slot, { thumbnail: frame });
|
|
344
444
|
readPauseSlots();
|
|
345
|
-
toast(
|
|
445
|
+
toast(t('savedIn', { n: info.slot + 1 }));
|
|
346
446
|
};
|
|
347
447
|
|
|
348
448
|
const loadSlot = (slot) => {
|
|
349
449
|
state.sheet = null;
|
|
350
450
|
if (!play.states.load(slot)) {
|
|
351
451
|
state.screen = 'pause';
|
|
352
|
-
return toast('
|
|
452
|
+
return toast(t('loadFailed'));
|
|
353
453
|
}
|
|
354
454
|
enterGame();
|
|
355
455
|
};
|
|
@@ -364,25 +464,25 @@ export async function mount(target, host) {
|
|
|
364
464
|
slot: info.slot,
|
|
365
465
|
focus: 0,
|
|
366
466
|
items: [
|
|
367
|
-
{ label: '
|
|
467
|
+
{ label: t('load'), hint: when(info.savedAt), run: () => loadSlot(info.slot) },
|
|
368
468
|
{
|
|
369
|
-
label: '
|
|
469
|
+
label: t('saveHereItem'),
|
|
370
470
|
disabled: locked,
|
|
371
|
-
hint: locked ? '
|
|
471
|
+
hint: locked ? t('unlockFirst') : t('replaces'),
|
|
372
472
|
run: () => {
|
|
373
473
|
closeSheet();
|
|
374
474
|
ask({
|
|
375
|
-
title:
|
|
475
|
+
title: t('overwriteAsk', { n }),
|
|
376
476
|
text: when(info.savedAt),
|
|
377
|
-
yes: '
|
|
378
|
-
no: '
|
|
477
|
+
yes: t('overwrite'),
|
|
478
|
+
no: t('cancel'),
|
|
379
479
|
onYes: () => saveIntoSlot(i),
|
|
380
480
|
});
|
|
381
481
|
},
|
|
382
482
|
},
|
|
383
483
|
{
|
|
384
|
-
label: locked ? '
|
|
385
|
-
hint: locked ? '
|
|
484
|
+
label: locked ? t('unlock') : t('lock'),
|
|
485
|
+
hint: locked ? t('unlockHint') : t('lockHint'),
|
|
386
486
|
run: async () => {
|
|
387
487
|
await play.states.lock(info.slot, !locked);
|
|
388
488
|
closeSheet();
|
|
@@ -391,17 +491,17 @@ export async function mount(target, host) {
|
|
|
391
491
|
},
|
|
392
492
|
},
|
|
393
493
|
{
|
|
394
|
-
label: '
|
|
494
|
+
label: t('delete'),
|
|
395
495
|
danger: true,
|
|
396
496
|
disabled: locked,
|
|
397
|
-
hint: locked ? '
|
|
497
|
+
hint: locked ? t('unlockFirst') : null,
|
|
398
498
|
run: () => {
|
|
399
499
|
closeSheet();
|
|
400
500
|
ask({
|
|
401
|
-
title:
|
|
402
|
-
text: '
|
|
403
|
-
yes: '
|
|
404
|
-
no: '
|
|
501
|
+
title: t('deleteAsk', { n }),
|
|
502
|
+
text: t('noUndo'),
|
|
503
|
+
yes: t('delete'),
|
|
504
|
+
no: t('cancel'),
|
|
405
505
|
onYes: async () => {
|
|
406
506
|
await play.states.remove(info.slot);
|
|
407
507
|
readPauseSlots();
|
|
@@ -410,7 +510,7 @@ export async function mount(target, host) {
|
|
|
410
510
|
});
|
|
411
511
|
},
|
|
412
512
|
},
|
|
413
|
-
{ label: '
|
|
513
|
+
{ label: t('cancel'), run: () => closeSheet() },
|
|
414
514
|
],
|
|
415
515
|
};
|
|
416
516
|
state.screen = 'sheet';
|
|
@@ -424,14 +524,15 @@ export async function mount(target, host) {
|
|
|
424
524
|
state.pause.focus = { kind: 'slot', i };
|
|
425
525
|
state.pause.col = i;
|
|
426
526
|
if (slot.info.savedAt) return openSlotSheet(i);
|
|
427
|
-
if (slot.info.locked) return toast('
|
|
527
|
+
if (slot.info.locked) return toast(t('slotLocked'));
|
|
428
528
|
await saveIntoSlot(i);
|
|
429
529
|
};
|
|
430
530
|
|
|
431
531
|
/** Up / down between the rows, left / right along the slots. */
|
|
432
|
-
const PAUSE_ROWS = 4;
|
|
433
532
|
const onPause = async (action) => {
|
|
434
533
|
const P = state.pause;
|
|
534
|
+
// Rows: the first item, the slots, then the other items.
|
|
535
|
+
const PAUSE_ROWS = P.items.length + 1;
|
|
435
536
|
const row = P.focus.kind === 'slot' ? 1 : P.focus.i === 0 ? 0 : P.focus.i + 1;
|
|
436
537
|
const at = (r) => (r === 1 ? { kind: 'slot', i: P.col } : { kind: 'item', i: r === 0 ? 0 : r - 1 });
|
|
437
538
|
if (action === 'up') P.focus = at((row + PAUSE_ROWS - 1) % PAUSE_ROWS);
|
|
@@ -456,7 +557,7 @@ export async function mount(target, host) {
|
|
|
456
557
|
return enterGame();
|
|
457
558
|
}
|
|
458
559
|
if (!card.info.savedAt) return;
|
|
459
|
-
if (!play.states.load(card.slot)) return toast('
|
|
560
|
+
if (!play.states.load(card.slot)) return toast(t('loadFailed'));
|
|
460
561
|
enterGame();
|
|
461
562
|
};
|
|
462
563
|
|
|
@@ -468,14 +569,14 @@ export async function mount(target, host) {
|
|
|
468
569
|
readPoints();
|
|
469
570
|
state.picking = false;
|
|
470
571
|
state.focus = state.cards.findIndex((c) => c.kind === 'slot' && c.slot === card.slot);
|
|
471
|
-
toast(
|
|
572
|
+
toast(t('savedIn', { n: card.slot + 1 }));
|
|
472
573
|
};
|
|
473
574
|
|
|
474
575
|
const saveAuto = async () => {
|
|
475
576
|
const free = freeSlot();
|
|
476
577
|
if (free >= 0) return saveAutoInto(free);
|
|
477
578
|
const target = state.cards.findIndex((c) => c.kind === 'slot' && !c.info.locked);
|
|
478
|
-
if (target < 0) return toast('
|
|
579
|
+
if (target < 0) return toast(t('allLocked'));
|
|
479
580
|
state.picking = true;
|
|
480
581
|
state.focus = target;
|
|
481
582
|
render();
|
|
@@ -489,8 +590,8 @@ export async function mount(target, host) {
|
|
|
489
590
|
focus: 0,
|
|
490
591
|
items: [
|
|
491
592
|
{
|
|
492
|
-
label: locked ? '
|
|
493
|
-
hint: locked ? '
|
|
593
|
+
label: locked ? t('unlock') : t('lock'),
|
|
594
|
+
hint: locked ? t('unlockHint') : t('lockHint'),
|
|
494
595
|
run: async () => {
|
|
495
596
|
await play.states.lock(card.slot, !locked);
|
|
496
597
|
closeSheet();
|
|
@@ -499,17 +600,17 @@ export async function mount(target, host) {
|
|
|
499
600
|
},
|
|
500
601
|
},
|
|
501
602
|
{
|
|
502
|
-
label: '
|
|
603
|
+
label: t('delete'),
|
|
503
604
|
danger: true,
|
|
504
605
|
disabled: locked,
|
|
505
|
-
hint: locked ? '
|
|
606
|
+
hint: locked ? t('unlockFirst') : null,
|
|
506
607
|
run: () => {
|
|
507
608
|
closeSheet();
|
|
508
609
|
ask({
|
|
509
|
-
title:
|
|
510
|
-
text: '
|
|
511
|
-
yes: '
|
|
512
|
-
no: '
|
|
610
|
+
title: t('deleteAsk', { n: card.slot + 1 }),
|
|
611
|
+
text: t('noUndo'),
|
|
612
|
+
yes: t('delete'),
|
|
613
|
+
no: t('cancel'),
|
|
513
614
|
onYes: async () => {
|
|
514
615
|
await play.states.remove(card.slot);
|
|
515
616
|
readPoints();
|
|
@@ -518,7 +619,7 @@ export async function mount(target, host) {
|
|
|
518
619
|
});
|
|
519
620
|
},
|
|
520
621
|
},
|
|
521
|
-
{ label: '
|
|
622
|
+
{ label: t('cancel'), run: () => closeSheet() },
|
|
522
623
|
],
|
|
523
624
|
};
|
|
524
625
|
state.screen = 'sheet';
|
|
@@ -558,13 +659,92 @@ export async function mount(target, host) {
|
|
|
558
659
|
/** Leaving from a running game keeps it as the unsaved suspend point. */
|
|
559
660
|
const leave = async () => {
|
|
560
661
|
if (leaving) return;
|
|
561
|
-
state.status = '
|
|
662
|
+
state.status = t('saving');
|
|
562
663
|
state.screen = 'boot';
|
|
563
664
|
render();
|
|
564
665
|
await suspend();
|
|
565
666
|
await exit();
|
|
566
667
|
};
|
|
567
668
|
|
|
669
|
+
// ---- settings, fullscreen, performance (engine-specs 0.6) -----------------------
|
|
670
|
+
|
|
671
|
+
// The player's choices, per engine (OPFS settings/mgba.json): BlastEm's options, the shared
|
|
672
|
+
// ones (keep the screen on, show performance) and the controls.
|
|
673
|
+
let saved = { version: 1, values: {}, controls: {} };
|
|
674
|
+
const setting = (key) => (key in saved.values ? saved.values[key] : SHARED_SETTINGS[key]?.default);
|
|
675
|
+
const store = () => saveSettings(ENGINE_ID, saved).catch((error) => console.warn('[blastem app] settings not saved', error));
|
|
676
|
+
const engineValues = () =>
|
|
677
|
+
Object.fromEntries(Object.entries(saved.values).filter(([key]) => !(key in SHARED_SETTINGS)));
|
|
678
|
+
|
|
679
|
+
const fullscreen = createFullscreenToggle(root);
|
|
680
|
+
const wake = createWakeLock();
|
|
681
|
+
const perf = createPerfCounter(root, { locale });
|
|
682
|
+
let offFrames = () => {};
|
|
683
|
+
const applyShared = () => {
|
|
684
|
+
if (setting('showPerformance')) perf.show();
|
|
685
|
+
else perf.hide();
|
|
686
|
+
wake.setActive(state.screen === 'game' && setting('keepScreenOn') !== false);
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
let screen = null;
|
|
690
|
+
// BlastEm's settings are in its config (smoothing, region), not its options.
|
|
691
|
+
let configKeys = new Set();
|
|
692
|
+
const described = async () => {
|
|
693
|
+
const config = await play.config();
|
|
694
|
+
configKeys = new Set(Object.keys(config));
|
|
695
|
+
return { ...config, ...(await play.options()), ...SHARED_SETTINGS };
|
|
696
|
+
};
|
|
697
|
+
const write = (values) => {
|
|
698
|
+
const config = Object.fromEntries(Object.entries(values).filter(([key]) => configKeys.has(key)));
|
|
699
|
+
const options = Object.fromEntries(Object.entries(values).filter(([key]) => !configKeys.has(key)));
|
|
700
|
+
if (Object.keys(config).length) play.config(config);
|
|
701
|
+
if (Object.keys(options).length) play.options(options);
|
|
702
|
+
};
|
|
703
|
+
const controlRows = () => controlsModel(BUTTONS, DEFAULT_CONTROLS, saved.controls, locale);
|
|
704
|
+
|
|
705
|
+
const openSettings = async () => {
|
|
706
|
+
const all = await described();
|
|
707
|
+
const model = () => settingsModel(all, saved.values, locale);
|
|
708
|
+
state.screen = 'settings';
|
|
709
|
+
render();
|
|
710
|
+
overlay.innerHTML = '';
|
|
711
|
+
const layer = document.createElement('div');
|
|
712
|
+
layer.className = 'bem-layer bem-settings';
|
|
713
|
+
overlay.append(layer);
|
|
714
|
+
screen = createSettingsScreen(layer, {
|
|
715
|
+
sections: model(),
|
|
716
|
+
controls: controlRows(),
|
|
717
|
+
input: host.input,
|
|
718
|
+
locale,
|
|
719
|
+
onChange(key, value) {
|
|
720
|
+
saved.values = { ...saved.values, [key]: value };
|
|
721
|
+
// BlastEm's own options go to the engine: a live one applies now, the rest on Reiniciar.
|
|
722
|
+
if (key in SHARED_SETTINGS) applyShared();
|
|
723
|
+
else write({ [key]: value });
|
|
724
|
+
void store();
|
|
725
|
+
},
|
|
726
|
+
onControl(_id, _binding, bindings) {
|
|
727
|
+
saved.controls = bindings;
|
|
728
|
+
play.setControls(toBlastemControls(bindings));
|
|
729
|
+
void store();
|
|
730
|
+
},
|
|
731
|
+
onReset() {
|
|
732
|
+
const defaults = settingsDefaults(all);
|
|
733
|
+
saved = { version: 1, values: {}, controls: {} };
|
|
734
|
+
write(Object.fromEntries(Object.entries(defaults).filter(([key]) => !(key in SHARED_SETTINGS))));
|
|
735
|
+
play.setControls({});
|
|
736
|
+
applyShared();
|
|
737
|
+
void store();
|
|
738
|
+
screen.update(settingsModel(all, defaults, locale), controlRows());
|
|
739
|
+
},
|
|
740
|
+
onClose: () => {
|
|
741
|
+
screen?.destroy();
|
|
742
|
+
screen = null;
|
|
743
|
+
void openPause();
|
|
744
|
+
},
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
|
|
568
748
|
// ---- input ----------------------------------------------------------------------
|
|
569
749
|
|
|
570
750
|
const onPoints = (action) => {
|
|
@@ -582,10 +762,10 @@ export async function mount(target, host) {
|
|
|
582
762
|
if (!state.picking) return playCard(card);
|
|
583
763
|
if (!card.info.savedAt) return saveAutoInto(state.focus);
|
|
584
764
|
return ask({
|
|
585
|
-
title:
|
|
765
|
+
title: t('overwriteAsk', { n: card.slot + 1 }),
|
|
586
766
|
text: when(card.info.savedAt),
|
|
587
|
-
yes: '
|
|
588
|
-
no: '
|
|
767
|
+
yes: t('overwrite'),
|
|
768
|
+
no: t('cancel'),
|
|
589
769
|
onYes: () => saveAutoInto(state.focus),
|
|
590
770
|
});
|
|
591
771
|
} else if (action === 'more' && !state.picking) {
|
|
@@ -598,7 +778,7 @@ export async function mount(target, host) {
|
|
|
598
778
|
state.focus = state.cards.findIndex((c) => c.kind === 'auto');
|
|
599
779
|
} else if (state.from === 'pause') return openPause();
|
|
600
780
|
else
|
|
601
|
-
return ask({ title: '
|
|
781
|
+
return ask({ title: t('leaveAsk'), yes: t('leave'), no: t('stay'), onYes: exit });
|
|
602
782
|
} else return;
|
|
603
783
|
render();
|
|
604
784
|
};
|
|
@@ -632,6 +812,7 @@ export async function mount(target, host) {
|
|
|
632
812
|
busy = true;
|
|
633
813
|
try {
|
|
634
814
|
const s = state.screen;
|
|
815
|
+
if (s === 'settings') return;
|
|
635
816
|
if (s === 'game') {
|
|
636
817
|
if (action === 'menu') await openPause({ capture: true });
|
|
637
818
|
} else if (s === 'points') await onPoints(action);
|
|
@@ -767,6 +948,11 @@ export async function mount(target, host) {
|
|
|
767
948
|
}
|
|
768
949
|
play = null;
|
|
769
950
|
dropUrls();
|
|
951
|
+
screen?.destroy();
|
|
952
|
+
offFrames();
|
|
953
|
+
fullscreen.destroy();
|
|
954
|
+
wake.destroy();
|
|
955
|
+
perf.destroy();
|
|
770
956
|
root.remove();
|
|
771
957
|
},
|
|
772
958
|
};
|
|
@@ -776,10 +962,13 @@ export async function mount(target, host) {
|
|
|
776
962
|
render();
|
|
777
963
|
host.input.resume();
|
|
778
964
|
try {
|
|
965
|
+
saved = await loadSettings(ENGINE_ID);
|
|
779
966
|
play = await new BlastemSDK()
|
|
780
967
|
.mount(stage)
|
|
781
968
|
.assets(host.assets)
|
|
782
969
|
.storage(host.storage)
|
|
970
|
+
// The saved smoothing and region: BlastEm's config.
|
|
971
|
+
.config(engineValues())
|
|
783
972
|
.on('error', ({ detail }) => console.error('[blastem app]', detail))
|
|
784
973
|
.on('exit', () => exit())
|
|
785
974
|
.start();
|
|
@@ -788,6 +977,9 @@ export async function mount(target, host) {
|
|
|
788
977
|
play = null;
|
|
789
978
|
return handle;
|
|
790
979
|
}
|
|
980
|
+
play.setControls(toBlastemControls({ ...DEFAULT_CONTROLS, ...saved.controls }));
|
|
981
|
+
// BlastEm's loop runs inside the WASM and reports no frames: the counter counts the display's.
|
|
982
|
+
applyShared();
|
|
791
983
|
readPoints();
|
|
792
984
|
if (hasPoints()) showPoints('boot');
|
|
793
985
|
else enterGame();
|
package/src/blastem.options.ts
CHANGED
|
@@ -78,12 +78,18 @@ export const BLASTEM_SPEC: EngineSpec<BlastemPayloads> = {
|
|
|
78
78
|
enum: ['auto', 'us', 'eu', 'jp'],
|
|
79
79
|
live: false,
|
|
80
80
|
description: 'Console region; auto reads it from the ROM header.',
|
|
81
|
+
label: { en: 'Region', es: 'Región' },
|
|
82
|
+
group: 'emulation',
|
|
83
|
+
valueLabels: [{ en: 'Auto', es: 'Automática' }, { en: 'USA', es: 'EE. UU.' }, { en: 'Europe', es: 'Europa' }, { en: 'Japan', es: 'Japón' }],
|
|
81
84
|
},
|
|
82
85
|
renderFilter: {
|
|
83
86
|
default: 'pixelated',
|
|
84
87
|
enum: ['pixelated', 'smooth'],
|
|
85
88
|
live: true,
|
|
86
89
|
description: 'Scaling: crisp pixels or linear filtering.',
|
|
90
|
+
label: { en: 'Smoothing', es: 'Suavizado' },
|
|
91
|
+
group: 'video',
|
|
92
|
+
valueLabels: [{ en: 'Sharp pixels', es: 'Píxeles nítidos' }, { en: 'Smooth', es: 'Suavizado' }],
|
|
87
93
|
},
|
|
88
94
|
jsUrl: { live: false, description: 'Emscripten glue URL. Defaults to ./blastem.js.' },
|
|
89
95
|
wasmUrl: { live: false, description: 'WASM URL. Defaults to ./blastem.wasm.' },
|