@wasm-gaming/blastem-wasm 0.1.2 → 0.1.3
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 +37 -0
- package/dist/blastem/app/app.js +248 -24
- package/dist/blastem/blastem.sdk.d.ts +1 -1
- package/dist/blastem/blastem.sdk.js +1 -1
- package/dist/blastem/blastem.wasm +0 -0
- package/package.json +1 -1
- package/src/app/app.css +37 -0
- package/src/app/app.js +248 -24
- package/src/blastem.sdk.ts +1 -1
package/dist/blastem/app/app.css
CHANGED
|
@@ -89,6 +89,32 @@
|
|
|
89
89
|
.item.is-danger.is-focused small { color: #450a0a; }
|
|
90
90
|
.bem-panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
|
91
91
|
.bem-panel .row .item { text-align: center; }
|
|
92
|
+
/* the slots in the pause menu: a compact row of the same frames */
|
|
93
|
+
.bem-panel.is-pause { width: min(520px, 94vw); max-height: calc(100% - 24px); overflow-y: auto; scrollbar-width: none; }
|
|
94
|
+
.slots-label { margin: 6px 0 0; font: 600 0.72rem var(--ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
|
|
95
|
+
.slots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 4px 0 6px; }
|
|
96
|
+
.slot { all: unset; box-sizing: border-box; display: grid; gap: 4px; min-width: 0; cursor: pointer; transition: transform 0.18s var(--ease); }
|
|
97
|
+
.slot .point-frame { border-radius: 8px; }
|
|
98
|
+
.slot.is-empty .point-frame { border-style: dashed; background: transparent; }
|
|
99
|
+
.slot.is-focused { transform: translateY(-3px); }
|
|
100
|
+
.slot.is-focused .point-frame { box-shadow: var(--ring), 0 18px 40px -20px #000; border-color: transparent; }
|
|
101
|
+
.slot-label { font: 700 0.8rem var(--ui); text-align: center; }
|
|
102
|
+
.slot-date { font: 500 0.68rem var(--ui); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
103
|
+
@media (max-width: 420px) { .slots { gap: 7px; } .slot-date { font-size: 0.6rem; } }
|
|
104
|
+
@media (max-height: 480px) {
|
|
105
|
+
.bem-panel.is-pause { padding: 16px 20px; gap: 7px; }
|
|
106
|
+
.bem-panel.is-pause .item { padding: 9px 14px; }
|
|
107
|
+
.bem-panel.is-pause h2 { margin-bottom: 2px; }
|
|
108
|
+
}
|
|
109
|
+
/* A phone on its side: two columns — the entries left, the slots right — so nothing scrolls. */
|
|
110
|
+
@media (max-height: 480px) and (min-width: 560px) {
|
|
111
|
+
.bem-panel.is-pause { width: min(780px, 96vw); grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); column-gap: 22px; align-content: start; }
|
|
112
|
+
.bem-panel.is-pause > * { grid-column: 1; }
|
|
113
|
+
.bem-panel.is-pause > .slots-label { grid-column: 2; grid-row: 1; }
|
|
114
|
+
.bem-panel.is-pause > .slots { grid-column: 2; grid-row: 2 / span 4; align-self: center; }
|
|
115
|
+
.bem-panel.is-pause > .bem-hints { grid-column: 1 / -1; }
|
|
116
|
+
}
|
|
117
|
+
|
|
92
118
|
/* A dialog sits on its own layer, above anything the screen under it positions (the
|
|
93
119
|
character art on the slot cards is z-index 1), on a backdrop that hides that screen. */
|
|
94
120
|
.bem-layer {
|
|
@@ -111,6 +137,17 @@
|
|
|
111
137
|
.bem-hints span { display: inline-flex; align-items: center; gap: 7px; }
|
|
112
138
|
.bem-hints kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: rgb(255 255 255 / 0.12); color: var(--text); font: 700 0.68rem var(--ui); }
|
|
113
139
|
.bem-panel .bem-hints { justify-content: flex-start; margin-top: 6px; }
|
|
140
|
+
.bem-hints .hint { display: inline-flex; align-items: center; gap: 7px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
|
|
141
|
+
.bem-hints .hint:hover { color: var(--text); }
|
|
142
|
+
.bem-overlay button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
|
|
143
|
+
/* Touch screens: the hints are the on-screen buttons — a finger-sized target, no gamepad glyph —
|
|
144
|
+
and the gamepad-only ones (←→, "A elegir") go. */
|
|
145
|
+
@media (pointer: coarse) {
|
|
146
|
+
.bem-hints { gap: 10px; }
|
|
147
|
+
.bem-hints .is-pad { display: none; }
|
|
148
|
+
.bem-hints kbd { display: none; }
|
|
149
|
+
.bem-hints .hint { min-height: 44px; padding: 0 16px; border-radius: 22px; background: rgb(255 255 255 / 0.08); border: 1px solid var(--line); color: var(--text); font-weight: 600; }
|
|
150
|
+
}
|
|
114
151
|
|
|
115
152
|
.bem-toast {
|
|
116
153
|
position: absolute; left: 50%; bottom: calc(28px + var(--wg-safe-bottom, 0px)); transform: translateX(-50%); margin: 0;
|
package/dist/blastem/app/app.js
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
// - Coming back with any suspend point shows them: the unsaved one, four slots, and
|
|
9
9
|
// "from the beginning". Y saves the unsaved point into a slot; Y on a saved one
|
|
10
10
|
// locks / unlocks or deletes it.
|
|
11
|
-
// - In game, Select+Start or Escape opens the pause menu
|
|
11
|
+
// - In game, Select+Start or Escape opens the pause menu, with the four slots in it: an
|
|
12
|
+
// empty one saves the moment at once; a saved one opens Cargar (focused) · Guardar aquí ·
|
|
13
|
+
// Bloquear · Borrar.
|
|
14
|
+
// - By touch: the hints are buttons (A, B, Y), and a long press on a card is Y.
|
|
12
15
|
//
|
|
13
16
|
// Plain JS and DOM: it ships next to the SDK and imports nothing else.
|
|
14
17
|
|
|
@@ -67,7 +70,9 @@ export async function mount(target, host) {
|
|
|
67
70
|
focus: 0,
|
|
68
71
|
from: 'boot',
|
|
69
72
|
picking: false,
|
|
70
|
-
pause:
|
|
73
|
+
// The pause menu: Continuar, the four slots (a row), Reiniciar, Volver al lanzador.
|
|
74
|
+
// focus: { kind: 'item' | 'slot', i }; col: the slot the row comes back to.
|
|
75
|
+
pause: { items: [], slots: [], focus: { kind: 'item', i: 0 }, col: 0 },
|
|
71
76
|
sheet: null, // { slot, items, focus }
|
|
72
77
|
confirm: null, // { title, text, yes, no, onYes, under, focus }
|
|
73
78
|
toast: null,
|
|
@@ -108,8 +113,16 @@ export async function mount(target, host) {
|
|
|
108
113
|
|
|
109
114
|
// ---- render ---------------------------------------------------------------------
|
|
110
115
|
|
|
116
|
+
// A hint with an action is also a button: tapping it does what the gamepad button
|
|
117
|
+
// would (on a phone the menus are tapped). One without is the gamepad's only.
|
|
111
118
|
const hints = (pairs) =>
|
|
112
|
-
`<footer class="bem-hints">${pairs
|
|
119
|
+
`<footer class="bem-hints">${pairs
|
|
120
|
+
.map(([k, t, act]) =>
|
|
121
|
+
act
|
|
122
|
+
? `<button class="hint" data-act="${act}"><kbd>${k}</kbd>${t}</button>`
|
|
123
|
+
: `<span class="is-pad"><kbd>${k}</kbd>${t}</span>`,
|
|
124
|
+
)
|
|
125
|
+
.join('')}</footer>`;
|
|
113
126
|
|
|
114
127
|
const pointCard = (card, i) => {
|
|
115
128
|
const focused = state.focus === i ? ' is-focused' : '';
|
|
@@ -133,16 +146,35 @@ export async function mount(target, host) {
|
|
|
133
146
|
};
|
|
134
147
|
|
|
135
148
|
const pointsHints = () => {
|
|
136
|
-
if (state.picking) return hints([['←→', 'hueco'], ['A', 'guardar aquí'], ['B', 'cancelar']]);
|
|
149
|
+
if (state.picking) return hints([['←→', 'hueco'], ['A', 'guardar aquí', 'accept'], ['B', 'cancelar', 'back']]);
|
|
137
150
|
const card = cardAt(state.focus);
|
|
138
151
|
const pairs = [['←→', 'elegir']];
|
|
139
|
-
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', 'jugar']);
|
|
140
|
-
if (card?.kind === 'auto') pairs.push(['Y', 'guardar en un hueco']);
|
|
141
|
-
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', 'opciones']);
|
|
142
|
-
pairs.push(['B', state.from === 'pause' ? 'volver' : 'salir']);
|
|
152
|
+
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', 'jugar', 'accept']);
|
|
153
|
+
if (card?.kind === 'auto') pairs.push(['Y', 'guardar en un hueco', 'more']);
|
|
154
|
+
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', 'opciones', 'more']);
|
|
155
|
+
pairs.push(['B', state.from === 'pause' ? 'volver' : 'salir', 'back']);
|
|
143
156
|
return hints(pairs);
|
|
144
157
|
};
|
|
145
158
|
|
|
159
|
+
const slotCard = ({ info, img }, i, focused) => {
|
|
160
|
+
const empty = !info.savedAt;
|
|
161
|
+
return `<button class="slot${focused ? ' is-focused' : ''}${empty ? ' is-empty' : ''}${info.locked ? ' is-locked' : ''}" data-slot="${i}">
|
|
162
|
+
<span class="point-frame">${img ? `<img src="${img}" alt="">` : ''}${info.locked ? `<i class="point-lock">${LOCK}</i>` : ''}</span>
|
|
163
|
+
<span class="slot-label">${info.slot + 1}</span>
|
|
164
|
+
<span class="slot-date">${empty ? 'Vacío' : esc(when(info.savedAt))}</span>
|
|
165
|
+
</button>`;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const pauseHints = () => {
|
|
169
|
+
const f = state.pause.focus;
|
|
170
|
+
if (f.kind === 'slot') {
|
|
171
|
+
const saved = !!state.pause.slots[f.i]?.info.savedAt;
|
|
172
|
+
return hints([['←→', 'hueco'], ['A', saved ? 'opciones' : 'guardar aquí'], ['B', 'continuar']]);
|
|
173
|
+
}
|
|
174
|
+
// Gamepad-only: by touch, "Continuar" is the first item already.
|
|
175
|
+
return hints([['A', 'elegir'], ['B', 'continuar']]);
|
|
176
|
+
};
|
|
177
|
+
|
|
146
178
|
const render = () => {
|
|
147
179
|
if (destroyed) return;
|
|
148
180
|
const s = state.screen;
|
|
@@ -179,11 +211,21 @@ export async function mount(target, host) {
|
|
|
179
211
|
${pointsHints()}
|
|
180
212
|
</section>`;
|
|
181
213
|
} else if (base === 'pause') {
|
|
182
|
-
|
|
214
|
+
const P = state.pause;
|
|
215
|
+
const on = (kind, i) => s === 'pause' && P.focus.kind === kind && P.focus.i === i;
|
|
216
|
+
const item = (i) => {
|
|
217
|
+
const it = P.items[i];
|
|
218
|
+
return `<button class="item${on('item', i) ? ' is-focused' : ''}" data-item="${i}">${esc(it.label)}${it.hint ? `<small>${esc(it.hint)}</small>` : ''}</button>`;
|
|
219
|
+
};
|
|
220
|
+
html += `<section class="bem-panel is-pause">
|
|
183
221
|
<p class="kicker">${esc(host.game?.title ?? '')}</p>
|
|
184
222
|
<h2>Pausa</h2>
|
|
185
|
-
${
|
|
186
|
-
|
|
223
|
+
${item(0)}
|
|
224
|
+
<p class="slots-label">Puntos de suspensión</p>
|
|
225
|
+
<div class="slots">${P.slots.map((slot, i) => slotCard(slot, i, on('slot', i))).join('')}</div>
|
|
226
|
+
${item(1)}
|
|
227
|
+
${item(2)}
|
|
228
|
+
${pauseHints()}
|
|
187
229
|
</section>`;
|
|
188
230
|
}
|
|
189
231
|
if (s === 'sheet') {
|
|
@@ -191,6 +233,7 @@ export async function mount(target, host) {
|
|
|
191
233
|
html += `<div class="bem-layer"><section class="bem-panel is-small">
|
|
192
234
|
<h2>Punto ${sh.slot + 1}</h2>
|
|
193
235
|
${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', 'volver']])}
|
|
194
237
|
</section></div>`;
|
|
195
238
|
}
|
|
196
239
|
if (s === 'confirm') {
|
|
@@ -267,21 +310,16 @@ export async function mount(target, host) {
|
|
|
267
310
|
if (capture) frame = await play.snapshot().catch(() => null);
|
|
268
311
|
play.pause(OWNER);
|
|
269
312
|
state.pause = {
|
|
270
|
-
focus: 0,
|
|
313
|
+
focus: { kind: 'item', i: 0 },
|
|
314
|
+
col: state.pause.col ?? 0,
|
|
315
|
+
slots: [],
|
|
271
316
|
items: [
|
|
272
317
|
{ label: 'Continuar', run: enterGame },
|
|
273
|
-
{
|
|
274
|
-
label: 'Puntos de suspensión',
|
|
275
|
-
hint: 'guarda este momento y elige dónde dejarlo',
|
|
276
|
-
run: async () => {
|
|
277
|
-
await suspend();
|
|
278
|
-
showPoints('pause');
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
318
|
{ label: 'Reiniciar', hint: 'reset de la consola', run: restart },
|
|
282
319
|
{ label: 'Volver al lanzador', hint: 'se queda un punto de suspensión', run: leave },
|
|
283
320
|
],
|
|
284
321
|
};
|
|
322
|
+
readPauseSlots();
|
|
285
323
|
state.screen = 'pause';
|
|
286
324
|
host.input.resume();
|
|
287
325
|
render();
|
|
@@ -292,6 +330,126 @@ export async function mount(target, host) {
|
|
|
292
330
|
await play.restart();
|
|
293
331
|
};
|
|
294
332
|
|
|
333
|
+
// ---- save states in the pause menu ---------------------------------------------
|
|
334
|
+
|
|
335
|
+
const readPauseSlots = () => {
|
|
336
|
+
dropUrls();
|
|
337
|
+
state.pause.slots = play.states.list().map((info) => ({ info, img: blobUrl(info.thumbnail) }));
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/** The moment the menu opened (its frame was taken then) into slot row position `i`. */
|
|
341
|
+
const saveIntoSlot = async (i) => {
|
|
342
|
+
const { info } = state.pause.slots[i];
|
|
343
|
+
await play.states.save(info.slot, { thumbnail: frame });
|
|
344
|
+
readPauseSlots();
|
|
345
|
+
toast(`Guardado en el hueco ${info.slot + 1}`);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const loadSlot = (slot) => {
|
|
349
|
+
state.sheet = null;
|
|
350
|
+
if (!play.states.load(slot)) {
|
|
351
|
+
state.screen = 'pause';
|
|
352
|
+
return toast('No se pudo cargar ese punto');
|
|
353
|
+
}
|
|
354
|
+
enterGame();
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/** A saved slot's sheet, from the pause menu: Cargar first and focused. */
|
|
358
|
+
const openSlotSheet = (i) => {
|
|
359
|
+
const { info } = state.pause.slots[i];
|
|
360
|
+
const n = info.slot + 1;
|
|
361
|
+
const locked = info.locked;
|
|
362
|
+
state.sheet = {
|
|
363
|
+
under: 'pause',
|
|
364
|
+
slot: info.slot,
|
|
365
|
+
focus: 0,
|
|
366
|
+
items: [
|
|
367
|
+
{ label: 'Cargar', hint: when(info.savedAt), run: () => loadSlot(info.slot) },
|
|
368
|
+
{
|
|
369
|
+
label: 'Guardar aquí',
|
|
370
|
+
disabled: locked,
|
|
371
|
+
hint: locked ? 'desbloquéalo antes' : 'sustituye lo que hay',
|
|
372
|
+
run: () => {
|
|
373
|
+
closeSheet();
|
|
374
|
+
ask({
|
|
375
|
+
title: `¿Sobrescribir el punto ${n}?`,
|
|
376
|
+
text: when(info.savedAt),
|
|
377
|
+
yes: 'Sobrescribir',
|
|
378
|
+
no: 'Cancelar',
|
|
379
|
+
onYes: () => saveIntoSlot(i),
|
|
380
|
+
});
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
label: locked ? 'Desbloquear' : 'Bloquear',
|
|
385
|
+
hint: locked ? 'se podrá sobrescribir y borrar' : 'que no se sobrescriba ni se borre',
|
|
386
|
+
run: async () => {
|
|
387
|
+
await play.states.lock(info.slot, !locked);
|
|
388
|
+
closeSheet();
|
|
389
|
+
readPauseSlots();
|
|
390
|
+
render();
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
label: 'Borrar',
|
|
395
|
+
danger: true,
|
|
396
|
+
disabled: locked,
|
|
397
|
+
hint: locked ? 'desbloquéalo antes' : null,
|
|
398
|
+
run: () => {
|
|
399
|
+
closeSheet();
|
|
400
|
+
ask({
|
|
401
|
+
title: `¿Borrar el punto ${n}?`,
|
|
402
|
+
text: 'No se puede deshacer.',
|
|
403
|
+
yes: 'Borrar',
|
|
404
|
+
no: 'Cancelar',
|
|
405
|
+
onYes: async () => {
|
|
406
|
+
await play.states.remove(info.slot);
|
|
407
|
+
readPauseSlots();
|
|
408
|
+
render();
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
{ label: 'Cancelar', run: () => closeSheet() },
|
|
414
|
+
],
|
|
415
|
+
};
|
|
416
|
+
state.screen = 'sheet';
|
|
417
|
+
render();
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/** A slot chosen in the pause menu: an empty one saves at once, a saved one opens its sheet. */
|
|
421
|
+
const onSlot = async (i) => {
|
|
422
|
+
const slot = state.pause.slots[i];
|
|
423
|
+
if (!slot) return;
|
|
424
|
+
state.pause.focus = { kind: 'slot', i };
|
|
425
|
+
state.pause.col = i;
|
|
426
|
+
if (slot.info.savedAt) return openSlotSheet(i);
|
|
427
|
+
if (slot.info.locked) return toast('Ese hueco está bloqueado');
|
|
428
|
+
await saveIntoSlot(i);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/** Up / down between the rows, left / right along the slots. */
|
|
432
|
+
const PAUSE_ROWS = 4;
|
|
433
|
+
const onPause = async (action) => {
|
|
434
|
+
const P = state.pause;
|
|
435
|
+
const row = P.focus.kind === 'slot' ? 1 : P.focus.i === 0 ? 0 : P.focus.i + 1;
|
|
436
|
+
const at = (r) => (r === 1 ? { kind: 'slot', i: P.col } : { kind: 'item', i: r === 0 ? 0 : r - 1 });
|
|
437
|
+
if (action === 'up') P.focus = at((row + PAUSE_ROWS - 1) % PAUSE_ROWS);
|
|
438
|
+
else if (action === 'down') P.focus = at((row + 1) % PAUSE_ROWS);
|
|
439
|
+
else if ((action === 'left' || action === 'right') && P.focus.kind === 'slot') {
|
|
440
|
+
P.col = Math.max(0, Math.min(P.slots.length - 1, P.focus.i + (action === 'left' ? -1 : 1)));
|
|
441
|
+
P.focus = { kind: 'slot', i: P.col };
|
|
442
|
+
} else if (action === 'accept') {
|
|
443
|
+
if (P.focus.kind === 'slot') return onSlot(P.focus.i);
|
|
444
|
+
return P.items[P.focus.i].run();
|
|
445
|
+
} else if (action === 'more' && P.focus.kind === 'slot') {
|
|
446
|
+
if (P.slots[P.focus.i]?.info.savedAt) return openSlotSheet(P.focus.i);
|
|
447
|
+
return;
|
|
448
|
+
} else if (action === 'back' || action === 'menu') return enterGame();
|
|
449
|
+
else return;
|
|
450
|
+
render();
|
|
451
|
+
};
|
|
452
|
+
|
|
295
453
|
const playCard = async (card) => {
|
|
296
454
|
if (card.kind === 'start') {
|
|
297
455
|
if (state.started) return restart();
|
|
@@ -469,7 +627,7 @@ export async function mount(target, host) {
|
|
|
469
627
|
};
|
|
470
628
|
|
|
471
629
|
let busy = false;
|
|
472
|
-
const
|
|
630
|
+
const onAction = async (action) => {
|
|
473
631
|
if (leaving || busy) return;
|
|
474
632
|
busy = true;
|
|
475
633
|
try {
|
|
@@ -477,7 +635,7 @@ export async function mount(target, host) {
|
|
|
477
635
|
if (s === 'game') {
|
|
478
636
|
if (action === 'menu') await openPause({ capture: true });
|
|
479
637
|
} else if (s === 'points') await onPoints(action);
|
|
480
|
-
else if (s === 'pause') await
|
|
638
|
+
else if (s === 'pause') await onPause(action);
|
|
481
639
|
else if (s === 'sheet') await onList(state.sheet, action, closeSheet);
|
|
482
640
|
else if (s === 'confirm') await onConfirm(action);
|
|
483
641
|
else if (s === 'error' && (action === 'accept' || action === 'back')) await exit();
|
|
@@ -487,18 +645,38 @@ export async function mount(target, host) {
|
|
|
487
645
|
} finally {
|
|
488
646
|
busy = false;
|
|
489
647
|
}
|
|
490
|
-
}
|
|
648
|
+
};
|
|
649
|
+
const off = host.input.on(onAction);
|
|
491
650
|
|
|
492
651
|
// Pointer: hover (real movement only — a render replaces what is under a resting
|
|
493
652
|
// cursor) focuses, click activates; the same paths as the pad.
|
|
494
653
|
let lastPointer = '';
|
|
495
654
|
const onPointer = async (event) => {
|
|
496
|
-
|
|
655
|
+
if (event.type === 'click' && longPressed) {
|
|
656
|
+
// The lift after a long press: the press already did its job.
|
|
657
|
+
longPressed = false;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const el = event.target.closest('[data-card],[data-item],[data-slot],[data-sheet],[data-confirm],[data-exit],[data-act]');
|
|
497
661
|
if (!el || leaving || busy) return;
|
|
662
|
+
if (el.dataset.act != null) {
|
|
663
|
+
if (event.type === 'click') await onAction(el.dataset.act);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
498
666
|
if (event.type === 'pointermove') {
|
|
499
667
|
const at = `${event.clientX},${event.clientY}`;
|
|
500
668
|
if (at === lastPointer) return;
|
|
501
669
|
lastPointer = at;
|
|
670
|
+
if (state.screen === 'pause' && (el.dataset.item != null || el.dataset.slot != null)) {
|
|
671
|
+
const focus = el.dataset.slot != null ? { kind: 'slot', i: +el.dataset.slot } : { kind: 'item', i: +el.dataset.item };
|
|
672
|
+
const P = state.pause;
|
|
673
|
+
if (P.focus.kind !== focus.kind || P.focus.i !== focus.i) {
|
|
674
|
+
P.focus = focus;
|
|
675
|
+
if (focus.kind === 'slot') P.col = focus.i;
|
|
676
|
+
render();
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
502
680
|
const key = el.dataset.card ?? el.dataset.item ?? el.dataset.sheet;
|
|
503
681
|
if (key == null) return;
|
|
504
682
|
const list = el.dataset.card != null ? state : el.dataset.item != null ? state.pause : state.sheet;
|
|
@@ -516,6 +694,7 @@ export async function mount(target, host) {
|
|
|
516
694
|
return onPoints('accept');
|
|
517
695
|
}
|
|
518
696
|
if (el.dataset.item != null) await state.pause.items[+el.dataset.item].run();
|
|
697
|
+
else if (el.dataset.slot != null) await onSlot(+el.dataset.slot);
|
|
519
698
|
else if (el.dataset.sheet != null) {
|
|
520
699
|
const item = state.sheet.items[+el.dataset.sheet];
|
|
521
700
|
if (!item.disabled) await item.run();
|
|
@@ -528,6 +707,45 @@ export async function mount(target, host) {
|
|
|
528
707
|
overlay.addEventListener('click', onPointer);
|
|
529
708
|
overlay.addEventListener('pointermove', onPointer);
|
|
530
709
|
|
|
710
|
+
// Touch: a long press on a card focuses it and does what Y does (save the unsaved point
|
|
711
|
+
// into a slot; a saved point's options) — a tap would play it.
|
|
712
|
+
const LONG_PRESS_MS = 500;
|
|
713
|
+
let longPressed = false;
|
|
714
|
+
let press = null;
|
|
715
|
+
const cancelPress = () => {
|
|
716
|
+
if (press) clearTimeout(press.timer);
|
|
717
|
+
press = null;
|
|
718
|
+
};
|
|
719
|
+
const onPressDown = (event) => {
|
|
720
|
+
cancelPress();
|
|
721
|
+
longPressed = false;
|
|
722
|
+
if (event.pointerType === 'mouse') return;
|
|
723
|
+
const el = event.target.closest('[data-card]');
|
|
724
|
+
if (!el || state.screen !== 'points') return;
|
|
725
|
+
const index = +el.dataset.card;
|
|
726
|
+
press = {
|
|
727
|
+
x: event.clientX,
|
|
728
|
+
y: event.clientY,
|
|
729
|
+
timer: setTimeout(async () => {
|
|
730
|
+
press = null;
|
|
731
|
+
longPressed = true;
|
|
732
|
+
if (leaving || busy || state.screen !== 'points') return;
|
|
733
|
+
state.focus = index;
|
|
734
|
+
render();
|
|
735
|
+
await onAction('more');
|
|
736
|
+
}, LONG_PRESS_MS),
|
|
737
|
+
};
|
|
738
|
+
};
|
|
739
|
+
const onPressMove = (event) => {
|
|
740
|
+
if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > 12) cancelPress();
|
|
741
|
+
};
|
|
742
|
+
const noMenu = (event) => event.preventDefault();
|
|
743
|
+
overlay.addEventListener('pointerdown', onPressDown);
|
|
744
|
+
overlay.addEventListener('pointermove', onPressMove);
|
|
745
|
+
overlay.addEventListener('pointerup', cancelPress);
|
|
746
|
+
overlay.addEventListener('pointercancel', cancelPress);
|
|
747
|
+
overlay.addEventListener('contextmenu', noMenu);
|
|
748
|
+
|
|
531
749
|
const handle = {
|
|
532
750
|
async unmount() {
|
|
533
751
|
destroyed = true;
|
|
@@ -536,6 +754,12 @@ export async function mount(target, host) {
|
|
|
536
754
|
clearTimeout(toastTimer);
|
|
537
755
|
overlay.removeEventListener('click', onPointer);
|
|
538
756
|
overlay.removeEventListener('pointermove', onPointer);
|
|
757
|
+
cancelPress();
|
|
758
|
+
overlay.removeEventListener('pointerdown', onPressDown);
|
|
759
|
+
overlay.removeEventListener('pointermove', onPressMove);
|
|
760
|
+
overlay.removeEventListener('pointerup', cancelPress);
|
|
761
|
+
overlay.removeEventListener('pointercancel', cancelPress);
|
|
762
|
+
overlay.removeEventListener('contextmenu', noMenu);
|
|
539
763
|
try {
|
|
540
764
|
await play?.destroy();
|
|
541
765
|
} catch {
|
|
@@ -123,7 +123,7 @@ export declare class BlastemPlay extends EnginePlayBase<BlastemPayloads> {
|
|
|
123
123
|
export declare class BlastemSDK extends EngineSDKBase<BlastemPayloads> {
|
|
124
124
|
static readonly id = "blastem";
|
|
125
125
|
/** Kept in step with package.json by `node scripts/sync-version.mjs`. */
|
|
126
|
-
static readonly version = "0.1.
|
|
126
|
+
static readonly version = "0.1.3";
|
|
127
127
|
static readonly name = "BlastEm";
|
|
128
128
|
static readonly description = "BlastEm, the Sega Mega Drive / Genesis emulator by Michael Pavone, compiled to WebAssembly. Ships no games: the player provides the ROM, and it never leaves their browser.";
|
|
129
129
|
protected createPlay(init: EngineInit<BlastemPayloads>, events: EventEmitter<EventsOf<BlastemPayloads>>): BlastemPlay;
|
|
@@ -588,7 +588,7 @@ export class BlastemPlay extends EnginePlayBase {
|
|
|
588
588
|
export class BlastemSDK extends EngineSDKBase {
|
|
589
589
|
static id = ENGINE_ID;
|
|
590
590
|
/** Kept in step with package.json by `node scripts/sync-version.mjs`. */
|
|
591
|
-
static version = '0.1.
|
|
591
|
+
static version = '0.1.3';
|
|
592
592
|
static name = 'BlastEm';
|
|
593
593
|
static description = 'BlastEm, the Sega Mega Drive / Genesis emulator by Michael Pavone, compiled to WebAssembly. Ships no games: the player provides the ROM, and it never leaves their browser.';
|
|
594
594
|
createPlay(init, events) {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wasm-gaming/blastem-wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
package/src/app/app.css
CHANGED
|
@@ -89,6 +89,32 @@
|
|
|
89
89
|
.item.is-danger.is-focused small { color: #450a0a; }
|
|
90
90
|
.bem-panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
|
91
91
|
.bem-panel .row .item { text-align: center; }
|
|
92
|
+
/* the slots in the pause menu: a compact row of the same frames */
|
|
93
|
+
.bem-panel.is-pause { width: min(520px, 94vw); max-height: calc(100% - 24px); overflow-y: auto; scrollbar-width: none; }
|
|
94
|
+
.slots-label { margin: 6px 0 0; font: 600 0.72rem var(--ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
|
|
95
|
+
.slots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 4px 0 6px; }
|
|
96
|
+
.slot { all: unset; box-sizing: border-box; display: grid; gap: 4px; min-width: 0; cursor: pointer; transition: transform 0.18s var(--ease); }
|
|
97
|
+
.slot .point-frame { border-radius: 8px; }
|
|
98
|
+
.slot.is-empty .point-frame { border-style: dashed; background: transparent; }
|
|
99
|
+
.slot.is-focused { transform: translateY(-3px); }
|
|
100
|
+
.slot.is-focused .point-frame { box-shadow: var(--ring), 0 18px 40px -20px #000; border-color: transparent; }
|
|
101
|
+
.slot-label { font: 700 0.8rem var(--ui); text-align: center; }
|
|
102
|
+
.slot-date { font: 500 0.68rem var(--ui); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
103
|
+
@media (max-width: 420px) { .slots { gap: 7px; } .slot-date { font-size: 0.6rem; } }
|
|
104
|
+
@media (max-height: 480px) {
|
|
105
|
+
.bem-panel.is-pause { padding: 16px 20px; gap: 7px; }
|
|
106
|
+
.bem-panel.is-pause .item { padding: 9px 14px; }
|
|
107
|
+
.bem-panel.is-pause h2 { margin-bottom: 2px; }
|
|
108
|
+
}
|
|
109
|
+
/* A phone on its side: two columns — the entries left, the slots right — so nothing scrolls. */
|
|
110
|
+
@media (max-height: 480px) and (min-width: 560px) {
|
|
111
|
+
.bem-panel.is-pause { width: min(780px, 96vw); grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); column-gap: 22px; align-content: start; }
|
|
112
|
+
.bem-panel.is-pause > * { grid-column: 1; }
|
|
113
|
+
.bem-panel.is-pause > .slots-label { grid-column: 2; grid-row: 1; }
|
|
114
|
+
.bem-panel.is-pause > .slots { grid-column: 2; grid-row: 2 / span 4; align-self: center; }
|
|
115
|
+
.bem-panel.is-pause > .bem-hints { grid-column: 1 / -1; }
|
|
116
|
+
}
|
|
117
|
+
|
|
92
118
|
/* A dialog sits on its own layer, above anything the screen under it positions (the
|
|
93
119
|
character art on the slot cards is z-index 1), on a backdrop that hides that screen. */
|
|
94
120
|
.bem-layer {
|
|
@@ -111,6 +137,17 @@
|
|
|
111
137
|
.bem-hints span { display: inline-flex; align-items: center; gap: 7px; }
|
|
112
138
|
.bem-hints kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: rgb(255 255 255 / 0.12); color: var(--text); font: 700 0.68rem var(--ui); }
|
|
113
139
|
.bem-panel .bem-hints { justify-content: flex-start; margin-top: 6px; }
|
|
140
|
+
.bem-hints .hint { display: inline-flex; align-items: center; gap: 7px; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
|
|
141
|
+
.bem-hints .hint:hover { color: var(--text); }
|
|
142
|
+
.bem-overlay button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
|
|
143
|
+
/* Touch screens: the hints are the on-screen buttons — a finger-sized target, no gamepad glyph —
|
|
144
|
+
and the gamepad-only ones (←→, "A elegir") go. */
|
|
145
|
+
@media (pointer: coarse) {
|
|
146
|
+
.bem-hints { gap: 10px; }
|
|
147
|
+
.bem-hints .is-pad { display: none; }
|
|
148
|
+
.bem-hints kbd { display: none; }
|
|
149
|
+
.bem-hints .hint { min-height: 44px; padding: 0 16px; border-radius: 22px; background: rgb(255 255 255 / 0.08); border: 1px solid var(--line); color: var(--text); font-weight: 600; }
|
|
150
|
+
}
|
|
114
151
|
|
|
115
152
|
.bem-toast {
|
|
116
153
|
position: absolute; left: 50%; bottom: calc(28px + var(--wg-safe-bottom, 0px)); transform: translateX(-50%); margin: 0;
|
package/src/app/app.js
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
// - Coming back with any suspend point shows them: the unsaved one, four slots, and
|
|
9
9
|
// "from the beginning". Y saves the unsaved point into a slot; Y on a saved one
|
|
10
10
|
// locks / unlocks or deletes it.
|
|
11
|
-
// - In game, Select+Start or Escape opens the pause menu
|
|
11
|
+
// - In game, Select+Start or Escape opens the pause menu, with the four slots in it: an
|
|
12
|
+
// empty one saves the moment at once; a saved one opens Cargar (focused) · Guardar aquí ·
|
|
13
|
+
// Bloquear · Borrar.
|
|
14
|
+
// - By touch: the hints are buttons (A, B, Y), and a long press on a card is Y.
|
|
12
15
|
//
|
|
13
16
|
// Plain JS and DOM: it ships next to the SDK and imports nothing else.
|
|
14
17
|
|
|
@@ -67,7 +70,9 @@ export async function mount(target, host) {
|
|
|
67
70
|
focus: 0,
|
|
68
71
|
from: 'boot',
|
|
69
72
|
picking: false,
|
|
70
|
-
pause:
|
|
73
|
+
// The pause menu: Continuar, the four slots (a row), Reiniciar, Volver al lanzador.
|
|
74
|
+
// focus: { kind: 'item' | 'slot', i }; col: the slot the row comes back to.
|
|
75
|
+
pause: { items: [], slots: [], focus: { kind: 'item', i: 0 }, col: 0 },
|
|
71
76
|
sheet: null, // { slot, items, focus }
|
|
72
77
|
confirm: null, // { title, text, yes, no, onYes, under, focus }
|
|
73
78
|
toast: null,
|
|
@@ -108,8 +113,16 @@ export async function mount(target, host) {
|
|
|
108
113
|
|
|
109
114
|
// ---- render ---------------------------------------------------------------------
|
|
110
115
|
|
|
116
|
+
// A hint with an action is also a button: tapping it does what the gamepad button
|
|
117
|
+
// would (on a phone the menus are tapped). One without is the gamepad's only.
|
|
111
118
|
const hints = (pairs) =>
|
|
112
|
-
`<footer class="bem-hints">${pairs
|
|
119
|
+
`<footer class="bem-hints">${pairs
|
|
120
|
+
.map(([k, t, act]) =>
|
|
121
|
+
act
|
|
122
|
+
? `<button class="hint" data-act="${act}"><kbd>${k}</kbd>${t}</button>`
|
|
123
|
+
: `<span class="is-pad"><kbd>${k}</kbd>${t}</span>`,
|
|
124
|
+
)
|
|
125
|
+
.join('')}</footer>`;
|
|
113
126
|
|
|
114
127
|
const pointCard = (card, i) => {
|
|
115
128
|
const focused = state.focus === i ? ' is-focused' : '';
|
|
@@ -133,16 +146,35 @@ export async function mount(target, host) {
|
|
|
133
146
|
};
|
|
134
147
|
|
|
135
148
|
const pointsHints = () => {
|
|
136
|
-
if (state.picking) return hints([['←→', 'hueco'], ['A', 'guardar aquí'], ['B', 'cancelar']]);
|
|
149
|
+
if (state.picking) return hints([['←→', 'hueco'], ['A', 'guardar aquí', 'accept'], ['B', 'cancelar', 'back']]);
|
|
137
150
|
const card = cardAt(state.focus);
|
|
138
151
|
const pairs = [['←→', 'elegir']];
|
|
139
|
-
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', 'jugar']);
|
|
140
|
-
if (card?.kind === 'auto') pairs.push(['Y', 'guardar en un hueco']);
|
|
141
|
-
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', 'opciones']);
|
|
142
|
-
pairs.push(['B', state.from === 'pause' ? 'volver' : 'salir']);
|
|
152
|
+
if (card?.kind === 'start' || card?.info?.savedAt) pairs.push(['A', 'jugar', 'accept']);
|
|
153
|
+
if (card?.kind === 'auto') pairs.push(['Y', 'guardar en un hueco', 'more']);
|
|
154
|
+
if (card?.kind === 'slot' && card.info.savedAt) pairs.push(['Y', 'opciones', 'more']);
|
|
155
|
+
pairs.push(['B', state.from === 'pause' ? 'volver' : 'salir', 'back']);
|
|
143
156
|
return hints(pairs);
|
|
144
157
|
};
|
|
145
158
|
|
|
159
|
+
const slotCard = ({ info, img }, i, focused) => {
|
|
160
|
+
const empty = !info.savedAt;
|
|
161
|
+
return `<button class="slot${focused ? ' is-focused' : ''}${empty ? ' is-empty' : ''}${info.locked ? ' is-locked' : ''}" data-slot="${i}">
|
|
162
|
+
<span class="point-frame">${img ? `<img src="${img}" alt="">` : ''}${info.locked ? `<i class="point-lock">${LOCK}</i>` : ''}</span>
|
|
163
|
+
<span class="slot-label">${info.slot + 1}</span>
|
|
164
|
+
<span class="slot-date">${empty ? 'Vacío' : esc(when(info.savedAt))}</span>
|
|
165
|
+
</button>`;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const pauseHints = () => {
|
|
169
|
+
const f = state.pause.focus;
|
|
170
|
+
if (f.kind === 'slot') {
|
|
171
|
+
const saved = !!state.pause.slots[f.i]?.info.savedAt;
|
|
172
|
+
return hints([['←→', 'hueco'], ['A', saved ? 'opciones' : 'guardar aquí'], ['B', 'continuar']]);
|
|
173
|
+
}
|
|
174
|
+
// Gamepad-only: by touch, "Continuar" is the first item already.
|
|
175
|
+
return hints([['A', 'elegir'], ['B', 'continuar']]);
|
|
176
|
+
};
|
|
177
|
+
|
|
146
178
|
const render = () => {
|
|
147
179
|
if (destroyed) return;
|
|
148
180
|
const s = state.screen;
|
|
@@ -179,11 +211,21 @@ export async function mount(target, host) {
|
|
|
179
211
|
${pointsHints()}
|
|
180
212
|
</section>`;
|
|
181
213
|
} else if (base === 'pause') {
|
|
182
|
-
|
|
214
|
+
const P = state.pause;
|
|
215
|
+
const on = (kind, i) => s === 'pause' && P.focus.kind === kind && P.focus.i === i;
|
|
216
|
+
const item = (i) => {
|
|
217
|
+
const it = P.items[i];
|
|
218
|
+
return `<button class="item${on('item', i) ? ' is-focused' : ''}" data-item="${i}">${esc(it.label)}${it.hint ? `<small>${esc(it.hint)}</small>` : ''}</button>`;
|
|
219
|
+
};
|
|
220
|
+
html += `<section class="bem-panel is-pause">
|
|
183
221
|
<p class="kicker">${esc(host.game?.title ?? '')}</p>
|
|
184
222
|
<h2>Pausa</h2>
|
|
185
|
-
${
|
|
186
|
-
|
|
223
|
+
${item(0)}
|
|
224
|
+
<p class="slots-label">Puntos de suspensión</p>
|
|
225
|
+
<div class="slots">${P.slots.map((slot, i) => slotCard(slot, i, on('slot', i))).join('')}</div>
|
|
226
|
+
${item(1)}
|
|
227
|
+
${item(2)}
|
|
228
|
+
${pauseHints()}
|
|
187
229
|
</section>`;
|
|
188
230
|
}
|
|
189
231
|
if (s === 'sheet') {
|
|
@@ -191,6 +233,7 @@ export async function mount(target, host) {
|
|
|
191
233
|
html += `<div class="bem-layer"><section class="bem-panel is-small">
|
|
192
234
|
<h2>Punto ${sh.slot + 1}</h2>
|
|
193
235
|
${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', 'volver']])}
|
|
194
237
|
</section></div>`;
|
|
195
238
|
}
|
|
196
239
|
if (s === 'confirm') {
|
|
@@ -267,21 +310,16 @@ export async function mount(target, host) {
|
|
|
267
310
|
if (capture) frame = await play.snapshot().catch(() => null);
|
|
268
311
|
play.pause(OWNER);
|
|
269
312
|
state.pause = {
|
|
270
|
-
focus: 0,
|
|
313
|
+
focus: { kind: 'item', i: 0 },
|
|
314
|
+
col: state.pause.col ?? 0,
|
|
315
|
+
slots: [],
|
|
271
316
|
items: [
|
|
272
317
|
{ label: 'Continuar', run: enterGame },
|
|
273
|
-
{
|
|
274
|
-
label: 'Puntos de suspensión',
|
|
275
|
-
hint: 'guarda este momento y elige dónde dejarlo',
|
|
276
|
-
run: async () => {
|
|
277
|
-
await suspend();
|
|
278
|
-
showPoints('pause');
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
318
|
{ label: 'Reiniciar', hint: 'reset de la consola', run: restart },
|
|
282
319
|
{ label: 'Volver al lanzador', hint: 'se queda un punto de suspensión', run: leave },
|
|
283
320
|
],
|
|
284
321
|
};
|
|
322
|
+
readPauseSlots();
|
|
285
323
|
state.screen = 'pause';
|
|
286
324
|
host.input.resume();
|
|
287
325
|
render();
|
|
@@ -292,6 +330,126 @@ export async function mount(target, host) {
|
|
|
292
330
|
await play.restart();
|
|
293
331
|
};
|
|
294
332
|
|
|
333
|
+
// ---- save states in the pause menu ---------------------------------------------
|
|
334
|
+
|
|
335
|
+
const readPauseSlots = () => {
|
|
336
|
+
dropUrls();
|
|
337
|
+
state.pause.slots = play.states.list().map((info) => ({ info, img: blobUrl(info.thumbnail) }));
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/** The moment the menu opened (its frame was taken then) into slot row position `i`. */
|
|
341
|
+
const saveIntoSlot = async (i) => {
|
|
342
|
+
const { info } = state.pause.slots[i];
|
|
343
|
+
await play.states.save(info.slot, { thumbnail: frame });
|
|
344
|
+
readPauseSlots();
|
|
345
|
+
toast(`Guardado en el hueco ${info.slot + 1}`);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const loadSlot = (slot) => {
|
|
349
|
+
state.sheet = null;
|
|
350
|
+
if (!play.states.load(slot)) {
|
|
351
|
+
state.screen = 'pause';
|
|
352
|
+
return toast('No se pudo cargar ese punto');
|
|
353
|
+
}
|
|
354
|
+
enterGame();
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/** A saved slot's sheet, from the pause menu: Cargar first and focused. */
|
|
358
|
+
const openSlotSheet = (i) => {
|
|
359
|
+
const { info } = state.pause.slots[i];
|
|
360
|
+
const n = info.slot + 1;
|
|
361
|
+
const locked = info.locked;
|
|
362
|
+
state.sheet = {
|
|
363
|
+
under: 'pause',
|
|
364
|
+
slot: info.slot,
|
|
365
|
+
focus: 0,
|
|
366
|
+
items: [
|
|
367
|
+
{ label: 'Cargar', hint: when(info.savedAt), run: () => loadSlot(info.slot) },
|
|
368
|
+
{
|
|
369
|
+
label: 'Guardar aquí',
|
|
370
|
+
disabled: locked,
|
|
371
|
+
hint: locked ? 'desbloquéalo antes' : 'sustituye lo que hay',
|
|
372
|
+
run: () => {
|
|
373
|
+
closeSheet();
|
|
374
|
+
ask({
|
|
375
|
+
title: `¿Sobrescribir el punto ${n}?`,
|
|
376
|
+
text: when(info.savedAt),
|
|
377
|
+
yes: 'Sobrescribir',
|
|
378
|
+
no: 'Cancelar',
|
|
379
|
+
onYes: () => saveIntoSlot(i),
|
|
380
|
+
});
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
label: locked ? 'Desbloquear' : 'Bloquear',
|
|
385
|
+
hint: locked ? 'se podrá sobrescribir y borrar' : 'que no se sobrescriba ni se borre',
|
|
386
|
+
run: async () => {
|
|
387
|
+
await play.states.lock(info.slot, !locked);
|
|
388
|
+
closeSheet();
|
|
389
|
+
readPauseSlots();
|
|
390
|
+
render();
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
label: 'Borrar',
|
|
395
|
+
danger: true,
|
|
396
|
+
disabled: locked,
|
|
397
|
+
hint: locked ? 'desbloquéalo antes' : null,
|
|
398
|
+
run: () => {
|
|
399
|
+
closeSheet();
|
|
400
|
+
ask({
|
|
401
|
+
title: `¿Borrar el punto ${n}?`,
|
|
402
|
+
text: 'No se puede deshacer.',
|
|
403
|
+
yes: 'Borrar',
|
|
404
|
+
no: 'Cancelar',
|
|
405
|
+
onYes: async () => {
|
|
406
|
+
await play.states.remove(info.slot);
|
|
407
|
+
readPauseSlots();
|
|
408
|
+
render();
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
{ label: 'Cancelar', run: () => closeSheet() },
|
|
414
|
+
],
|
|
415
|
+
};
|
|
416
|
+
state.screen = 'sheet';
|
|
417
|
+
render();
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/** A slot chosen in the pause menu: an empty one saves at once, a saved one opens its sheet. */
|
|
421
|
+
const onSlot = async (i) => {
|
|
422
|
+
const slot = state.pause.slots[i];
|
|
423
|
+
if (!slot) return;
|
|
424
|
+
state.pause.focus = { kind: 'slot', i };
|
|
425
|
+
state.pause.col = i;
|
|
426
|
+
if (slot.info.savedAt) return openSlotSheet(i);
|
|
427
|
+
if (slot.info.locked) return toast('Ese hueco está bloqueado');
|
|
428
|
+
await saveIntoSlot(i);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/** Up / down between the rows, left / right along the slots. */
|
|
432
|
+
const PAUSE_ROWS = 4;
|
|
433
|
+
const onPause = async (action) => {
|
|
434
|
+
const P = state.pause;
|
|
435
|
+
const row = P.focus.kind === 'slot' ? 1 : P.focus.i === 0 ? 0 : P.focus.i + 1;
|
|
436
|
+
const at = (r) => (r === 1 ? { kind: 'slot', i: P.col } : { kind: 'item', i: r === 0 ? 0 : r - 1 });
|
|
437
|
+
if (action === 'up') P.focus = at((row + PAUSE_ROWS - 1) % PAUSE_ROWS);
|
|
438
|
+
else if (action === 'down') P.focus = at((row + 1) % PAUSE_ROWS);
|
|
439
|
+
else if ((action === 'left' || action === 'right') && P.focus.kind === 'slot') {
|
|
440
|
+
P.col = Math.max(0, Math.min(P.slots.length - 1, P.focus.i + (action === 'left' ? -1 : 1)));
|
|
441
|
+
P.focus = { kind: 'slot', i: P.col };
|
|
442
|
+
} else if (action === 'accept') {
|
|
443
|
+
if (P.focus.kind === 'slot') return onSlot(P.focus.i);
|
|
444
|
+
return P.items[P.focus.i].run();
|
|
445
|
+
} else if (action === 'more' && P.focus.kind === 'slot') {
|
|
446
|
+
if (P.slots[P.focus.i]?.info.savedAt) return openSlotSheet(P.focus.i);
|
|
447
|
+
return;
|
|
448
|
+
} else if (action === 'back' || action === 'menu') return enterGame();
|
|
449
|
+
else return;
|
|
450
|
+
render();
|
|
451
|
+
};
|
|
452
|
+
|
|
295
453
|
const playCard = async (card) => {
|
|
296
454
|
if (card.kind === 'start') {
|
|
297
455
|
if (state.started) return restart();
|
|
@@ -469,7 +627,7 @@ export async function mount(target, host) {
|
|
|
469
627
|
};
|
|
470
628
|
|
|
471
629
|
let busy = false;
|
|
472
|
-
const
|
|
630
|
+
const onAction = async (action) => {
|
|
473
631
|
if (leaving || busy) return;
|
|
474
632
|
busy = true;
|
|
475
633
|
try {
|
|
@@ -477,7 +635,7 @@ export async function mount(target, host) {
|
|
|
477
635
|
if (s === 'game') {
|
|
478
636
|
if (action === 'menu') await openPause({ capture: true });
|
|
479
637
|
} else if (s === 'points') await onPoints(action);
|
|
480
|
-
else if (s === 'pause') await
|
|
638
|
+
else if (s === 'pause') await onPause(action);
|
|
481
639
|
else if (s === 'sheet') await onList(state.sheet, action, closeSheet);
|
|
482
640
|
else if (s === 'confirm') await onConfirm(action);
|
|
483
641
|
else if (s === 'error' && (action === 'accept' || action === 'back')) await exit();
|
|
@@ -487,18 +645,38 @@ export async function mount(target, host) {
|
|
|
487
645
|
} finally {
|
|
488
646
|
busy = false;
|
|
489
647
|
}
|
|
490
|
-
}
|
|
648
|
+
};
|
|
649
|
+
const off = host.input.on(onAction);
|
|
491
650
|
|
|
492
651
|
// Pointer: hover (real movement only — a render replaces what is under a resting
|
|
493
652
|
// cursor) focuses, click activates; the same paths as the pad.
|
|
494
653
|
let lastPointer = '';
|
|
495
654
|
const onPointer = async (event) => {
|
|
496
|
-
|
|
655
|
+
if (event.type === 'click' && longPressed) {
|
|
656
|
+
// The lift after a long press: the press already did its job.
|
|
657
|
+
longPressed = false;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const el = event.target.closest('[data-card],[data-item],[data-slot],[data-sheet],[data-confirm],[data-exit],[data-act]');
|
|
497
661
|
if (!el || leaving || busy) return;
|
|
662
|
+
if (el.dataset.act != null) {
|
|
663
|
+
if (event.type === 'click') await onAction(el.dataset.act);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
498
666
|
if (event.type === 'pointermove') {
|
|
499
667
|
const at = `${event.clientX},${event.clientY}`;
|
|
500
668
|
if (at === lastPointer) return;
|
|
501
669
|
lastPointer = at;
|
|
670
|
+
if (state.screen === 'pause' && (el.dataset.item != null || el.dataset.slot != null)) {
|
|
671
|
+
const focus = el.dataset.slot != null ? { kind: 'slot', i: +el.dataset.slot } : { kind: 'item', i: +el.dataset.item };
|
|
672
|
+
const P = state.pause;
|
|
673
|
+
if (P.focus.kind !== focus.kind || P.focus.i !== focus.i) {
|
|
674
|
+
P.focus = focus;
|
|
675
|
+
if (focus.kind === 'slot') P.col = focus.i;
|
|
676
|
+
render();
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
502
680
|
const key = el.dataset.card ?? el.dataset.item ?? el.dataset.sheet;
|
|
503
681
|
if (key == null) return;
|
|
504
682
|
const list = el.dataset.card != null ? state : el.dataset.item != null ? state.pause : state.sheet;
|
|
@@ -516,6 +694,7 @@ export async function mount(target, host) {
|
|
|
516
694
|
return onPoints('accept');
|
|
517
695
|
}
|
|
518
696
|
if (el.dataset.item != null) await state.pause.items[+el.dataset.item].run();
|
|
697
|
+
else if (el.dataset.slot != null) await onSlot(+el.dataset.slot);
|
|
519
698
|
else if (el.dataset.sheet != null) {
|
|
520
699
|
const item = state.sheet.items[+el.dataset.sheet];
|
|
521
700
|
if (!item.disabled) await item.run();
|
|
@@ -528,6 +707,45 @@ export async function mount(target, host) {
|
|
|
528
707
|
overlay.addEventListener('click', onPointer);
|
|
529
708
|
overlay.addEventListener('pointermove', onPointer);
|
|
530
709
|
|
|
710
|
+
// Touch: a long press on a card focuses it and does what Y does (save the unsaved point
|
|
711
|
+
// into a slot; a saved point's options) — a tap would play it.
|
|
712
|
+
const LONG_PRESS_MS = 500;
|
|
713
|
+
let longPressed = false;
|
|
714
|
+
let press = null;
|
|
715
|
+
const cancelPress = () => {
|
|
716
|
+
if (press) clearTimeout(press.timer);
|
|
717
|
+
press = null;
|
|
718
|
+
};
|
|
719
|
+
const onPressDown = (event) => {
|
|
720
|
+
cancelPress();
|
|
721
|
+
longPressed = false;
|
|
722
|
+
if (event.pointerType === 'mouse') return;
|
|
723
|
+
const el = event.target.closest('[data-card]');
|
|
724
|
+
if (!el || state.screen !== 'points') return;
|
|
725
|
+
const index = +el.dataset.card;
|
|
726
|
+
press = {
|
|
727
|
+
x: event.clientX,
|
|
728
|
+
y: event.clientY,
|
|
729
|
+
timer: setTimeout(async () => {
|
|
730
|
+
press = null;
|
|
731
|
+
longPressed = true;
|
|
732
|
+
if (leaving || busy || state.screen !== 'points') return;
|
|
733
|
+
state.focus = index;
|
|
734
|
+
render();
|
|
735
|
+
await onAction('more');
|
|
736
|
+
}, LONG_PRESS_MS),
|
|
737
|
+
};
|
|
738
|
+
};
|
|
739
|
+
const onPressMove = (event) => {
|
|
740
|
+
if (press && Math.hypot(event.clientX - press.x, event.clientY - press.y) > 12) cancelPress();
|
|
741
|
+
};
|
|
742
|
+
const noMenu = (event) => event.preventDefault();
|
|
743
|
+
overlay.addEventListener('pointerdown', onPressDown);
|
|
744
|
+
overlay.addEventListener('pointermove', onPressMove);
|
|
745
|
+
overlay.addEventListener('pointerup', cancelPress);
|
|
746
|
+
overlay.addEventListener('pointercancel', cancelPress);
|
|
747
|
+
overlay.addEventListener('contextmenu', noMenu);
|
|
748
|
+
|
|
531
749
|
const handle = {
|
|
532
750
|
async unmount() {
|
|
533
751
|
destroyed = true;
|
|
@@ -536,6 +754,12 @@ export async function mount(target, host) {
|
|
|
536
754
|
clearTimeout(toastTimer);
|
|
537
755
|
overlay.removeEventListener('click', onPointer);
|
|
538
756
|
overlay.removeEventListener('pointermove', onPointer);
|
|
757
|
+
cancelPress();
|
|
758
|
+
overlay.removeEventListener('pointerdown', onPressDown);
|
|
759
|
+
overlay.removeEventListener('pointermove', onPressMove);
|
|
760
|
+
overlay.removeEventListener('pointerup', cancelPress);
|
|
761
|
+
overlay.removeEventListener('pointercancel', cancelPress);
|
|
762
|
+
overlay.removeEventListener('contextmenu', noMenu);
|
|
539
763
|
try {
|
|
540
764
|
await play?.destroy();
|
|
541
765
|
} catch {
|
package/src/blastem.sdk.ts
CHANGED
|
@@ -666,7 +666,7 @@ export class BlastemPlay extends EnginePlayBase<BlastemPayloads> {
|
|
|
666
666
|
export class BlastemSDK extends EngineSDKBase<BlastemPayloads> {
|
|
667
667
|
static readonly id = ENGINE_ID;
|
|
668
668
|
/** Kept in step with package.json by `node scripts/sync-version.mjs`. */
|
|
669
|
-
static readonly version = '0.1.
|
|
669
|
+
static readonly version = '0.1.3';
|
|
670
670
|
static readonly name = 'BlastEm';
|
|
671
671
|
static readonly description =
|
|
672
672
|
'BlastEm, the Sega Mega Drive / Genesis emulator by Michael Pavone, compiled to WebAssembly. Ships no games: the player provides the ROM, and it never leaves their browser.';
|