@wasm-gaming/sonic3air-wasm 0.0.0 → 0.1.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/sonic3air/LICENSE +674 -0
- package/dist/sonic3air/THIRD_PARTY_NOTICES.md +79 -0
- package/dist/sonic3air/app/app.css +104 -0
- package/dist/sonic3air/app/app.js +347 -0
- package/dist/sonic3air/engine-specs.js +2600 -0
- package/dist/sonic3air/sonic3air.data +0 -0
- package/dist/sonic3air/sonic3air.data.json +64 -0
- package/dist/sonic3air/sonic3air.js +42 -0
- package/dist/sonic3air/sonic3air.options.d.ts +68 -0
- package/dist/sonic3air/sonic3air.options.d.ts.map +1 -0
- package/dist/sonic3air/sonic3air.options.js +35 -0
- package/dist/sonic3air/sonic3air.options.js.map +1 -0
- package/dist/sonic3air/sonic3air.sdk.d.ts +100 -0
- package/dist/sonic3air/sonic3air.sdk.d.ts.map +1 -0
- package/dist/sonic3air/sonic3air.sdk.js +604 -0
- package/dist/sonic3air/sonic3air.sdk.js.map +1 -0
- package/dist/sonic3air/sonic3air.wasm +0 -0
- package/package.json +2 -2
- package/src/app/app.js +55 -13
- package/src/sonic3air.sdk.ts +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`sonic3air.wasm`, `sonic3air.data` and the code inside `sonic3air.js` are **Sonic 3 A.I.R.**
|
|
4
|
+
("Sonic 3 - Angel Island Revisited") by Eukaryot and contributors, taken unchanged from its official
|
|
5
|
+
release. Sonic 3 A.I.R. is free software under the **GNU General Public License v3** (see
|
|
6
|
+
[LICENSE](LICENSE)). This package ships none of SEGA's game: the player provides the
|
|
7
|
+
Sonic & Knuckles + Sonic 3 ROM.
|
|
8
|
+
|
|
9
|
+
| Component | Version | Licence | Where it comes from |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
| Sonic 3 A.I.R. (Oxygen Engine, lemonscript, rmx) | `v26.03.28.0-stable` | GPL-3.0 | https://github.com/Eukaryot/sonic3air — release asset `sonic3air_web_data.zip`, SHA-256 `227ceb546388fe37051bb770fcfebcf2128cedc55646b27831f29f8b664b4b3c`, checked by `scripts/fetch-upstream.mjs` |
|
|
12
|
+
| SDL2 | 2.32.8 | zlib | Emscripten's `sdl2` port, linked into the binary by upstream |
|
|
13
|
+
| Dear ImGui | 1.92.4 | MIT | vendored by upstream (`framework/external/imgui`) |
|
|
14
|
+
| ProggyClean font | — | MIT (as distributed with Dear ImGui) | Dear ImGui's default font, Tristan Grimmer |
|
|
15
|
+
|
|
16
|
+
The components above are the ones identifiable in the binary. Upstream vendors its other
|
|
17
|
+
dependencies in its source tree (`framework/external/` at the tag above); that tree, with their
|
|
18
|
+
licences, is the corresponding source of this binary.
|
|
19
|
+
|
|
20
|
+
## Sonic 3 A.I.R.
|
|
21
|
+
|
|
22
|
+
Copyright Eukaryot and contributors. Sonic 3 A.I.R. is a non-profit fan game project, not affiliated
|
|
23
|
+
with SEGA or Sonic Team. It is distributed under the terms of the GNU General Public License version
|
|
24
|
+
3; see [LICENSE](LICENSE). **Corresponding source:** https://github.com/Eukaryot/sonic3air/tree/v26.03.28.0-stable
|
|
25
|
+
(build recipe: `Oxygen/sonic3air/build/_emscripten/`).
|
|
26
|
+
|
|
27
|
+
## SDL2 (zlib licence)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
|
31
|
+
|
|
32
|
+
This software is provided 'as-is', without any express or implied
|
|
33
|
+
warranty. In no event will the authors be held liable for any damages
|
|
34
|
+
arising from the use of this software.
|
|
35
|
+
|
|
36
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
37
|
+
including commercial applications, and to alter it and redistribute it
|
|
38
|
+
freely, subject to the following restrictions:
|
|
39
|
+
|
|
40
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
41
|
+
claim that you wrote the original software. If you use this software
|
|
42
|
+
in a product, an acknowledgment in the product documentation would be
|
|
43
|
+
appreciated but is not required.
|
|
44
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
45
|
+
misrepresented as being the original software.
|
|
46
|
+
3. This notice may not be removed or altered from any source distribution.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Dear ImGui (MIT)
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
The MIT License (MIT)
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2014-2025 Omar Cornut
|
|
56
|
+
|
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
58
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
59
|
+
in the Software without restriction, including without limitation the rights
|
|
60
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
61
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
62
|
+
furnished to do so, subject to the following conditions:
|
|
63
|
+
|
|
64
|
+
The above copyright notice and this permission notice shall be included in all
|
|
65
|
+
copies or substantial portions of the Software.
|
|
66
|
+
|
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
68
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
69
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
70
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
71
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
72
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
73
|
+
SOFTWARE.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## ProggyClean font
|
|
77
|
+
|
|
78
|
+
Copyright (c) 2004, 2005 Tristan Grimmer. Distributed with Dear ImGui under the MIT licence above
|
|
79
|
+
(https://github.com/bluescan/proggyfonts).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* sonic3air app — boot screen and pause menu (the look of the rsdk apps).
|
|
2
|
+
Tokens come from engine-specs (UI_TOKENS, `--wg-*`) when the host sets them; the
|
|
3
|
+
fallbacks are the same values, so the app looks right on a bare page too. */
|
|
4
|
+
|
|
5
|
+
.s3air-app {
|
|
6
|
+
--ring: var(--wg-focus-ring, 0 0 0 3px #fff);
|
|
7
|
+
--surface: var(--wg-surface, rgb(18 20 28 / 0.78));
|
|
8
|
+
--line: var(--wg-line, rgb(255 255 255 / 0.12));
|
|
9
|
+
--text: var(--wg-text, #f4f6fb);
|
|
10
|
+
--muted: var(--wg-muted, #8e97a9);
|
|
11
|
+
--danger: var(--wg-danger, #f87171);
|
|
12
|
+
--ui: var(--wg-font-ui, 'Inter Variable', 'Inter', system-ui, sans-serif);
|
|
13
|
+
--display: var(--wg-font-display, 'Unbounded Variable', 'Unbounded', system-ui, sans-serif);
|
|
14
|
+
--ease: var(--wg-ease, cubic-bezier(0.2, 0.8, 0.2, 1));
|
|
15
|
+
position: absolute;
|
|
16
|
+
inset: 0;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
background: #000;
|
|
19
|
+
color: var(--text);
|
|
20
|
+
font-family: var(--ui);
|
|
21
|
+
user-select: none;
|
|
22
|
+
-webkit-tap-highlight-color: transparent;
|
|
23
|
+
}
|
|
24
|
+
.s3air-app * { box-sizing: border-box; }
|
|
25
|
+
.s3air-stage { position: absolute; inset: 0; display: grid; place-items: center; }
|
|
26
|
+
.s3air-stage canvas { outline: none; }
|
|
27
|
+
.s3air-overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
|
|
28
|
+
.s3air-overlay > * { pointer-events: auto; }
|
|
29
|
+
.s3air-app[data-screen='game'] .s3air-overlay { display: none; }
|
|
30
|
+
|
|
31
|
+
/* Everything but the game sits on a backdrop that keeps the game visible underneath. */
|
|
32
|
+
.s3air-app:not([data-screen='game']) .s3air-overlay {
|
|
33
|
+
background:
|
|
34
|
+
radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--accent) 38%, transparent), transparent 70%),
|
|
35
|
+
rgb(4 6 12 / 0.72);
|
|
36
|
+
backdrop-filter: blur(14px) saturate(1.2);
|
|
37
|
+
-webkit-backdrop-filter: blur(14px) saturate(1.2);
|
|
38
|
+
}
|
|
39
|
+
.s3air-app[data-screen='boot'] .s3air-overlay { background-color: rgb(4 6 12 / 0.9); }
|
|
40
|
+
|
|
41
|
+
.kicker { margin: 0; font: 600 0.72rem var(--ui); letter-spacing: 0.22em; text-transform: uppercase; color: var(--muted); }
|
|
42
|
+
.s3air-app h2 { margin: 0; font: 700 clamp(1.4rem, 3vw, 2.1rem) var(--display); letter-spacing: -0.02em; }
|
|
43
|
+
|
|
44
|
+
/* ---- boot ---- */
|
|
45
|
+
.s3air-boot { display: grid; justify-items: center; gap: 22px; }
|
|
46
|
+
.s3air-boot img { width: min(260px, 50vw); border-radius: 22px; box-shadow: 0 30px 80px -30px #000; animation: s3air-breathe 2.4s var(--ease) infinite alternate; }
|
|
47
|
+
.s3air-boot p { margin: 0; color: var(--muted); font-weight: 500; }
|
|
48
|
+
@keyframes s3air-breathe { from { opacity: 0.55; transform: scale(0.98); } to { opacity: 1; transform: none; } }
|
|
49
|
+
|
|
50
|
+
/* ---- pause & confirm ---- */
|
|
51
|
+
.s3air-panel {
|
|
52
|
+
width: min(440px, 92vw); display: grid; gap: 10px; padding: 26px; border-radius: 28px;
|
|
53
|
+
background: rgb(20 22 31 / 0.9); border: 1px solid var(--line); box-shadow: 0 40px 100px -30px #000;
|
|
54
|
+
}
|
|
55
|
+
.s3air-panel h2 { margin-bottom: 8px; }
|
|
56
|
+
.s3air-panel .text { margin: 0 0 8px; color: var(--muted); line-height: 1.5; }
|
|
57
|
+
.item {
|
|
58
|
+
all: unset; box-sizing: border-box; display: grid; gap: 2px; padding: 13px 16px; border-radius: 14px;
|
|
59
|
+
background: rgb(255 255 255 / 0.05); font-weight: 600; cursor: pointer; transition: background 0.15s, box-shadow 0.15s;
|
|
60
|
+
}
|
|
61
|
+
.item small { font-weight: 500; font-size: 0.78rem; color: var(--muted); }
|
|
62
|
+
.item.is-focused { background: #fff; color: #0b0d12; box-shadow: var(--ring); }
|
|
63
|
+
.item.is-focused small { color: #4b5563; }
|
|
64
|
+
.item.is-danger.is-focused { background: var(--danger); color: #1a0505; box-shadow: 0 0 0 3px var(--danger); }
|
|
65
|
+
.s3air-panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
|
66
|
+
.s3air-panel .row .item { text-align: center; }
|
|
67
|
+
/* A dialog sits on its own layer, above anything the screen under it positions (the
|
|
68
|
+
character art on the slot cards is z-index 1), on a backdrop that hides that screen. */
|
|
69
|
+
.s3air-confirm {
|
|
70
|
+
position: absolute; inset: 0; z-index: 10; display: grid; place-items: center;
|
|
71
|
+
background: rgb(4 6 12 / 0.78);
|
|
72
|
+
backdrop-filter: blur(10px) saturate(0.8);
|
|
73
|
+
-webkit-backdrop-filter: blur(10px) saturate(0.8);
|
|
74
|
+
}
|
|
75
|
+
.s3air-confirm h2 { font-size: clamp(1.15rem, 2.2vw, 1.55rem); line-height: 1.2; }
|
|
76
|
+
.s3air-confirm .s3air-panel {
|
|
77
|
+
width: min(500px, 92vw);
|
|
78
|
+
background:
|
|
79
|
+
radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
|
|
80
|
+
#151821;
|
|
81
|
+
border-color: rgb(255 255 255 / 0.14);
|
|
82
|
+
box-shadow: 0 40px 120px -20px #000, 0 0 0 1px rgb(0 0 0 / 0.4);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ---- hints ---- */
|
|
86
|
+
.s3air-hints { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; color: var(--muted); font-size: 0.78rem; font-weight: 500; }
|
|
87
|
+
.s3air-hints span { display: inline-flex; align-items: center; gap: 7px; }
|
|
88
|
+
.s3air-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); }
|
|
89
|
+
.s3air-panel .s3air-hints { justify-content: flex-start; margin-top: 6px; }
|
|
90
|
+
|
|
91
|
+
@media (prefers-reduced-motion: reduce) {
|
|
92
|
+
.s3air-boot img { transition: none; animation: none; }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* ---- touch: the pause button (UX.md: it replaces Select + Start on a touch screen) ---- */
|
|
96
|
+
.s3air-pause {
|
|
97
|
+
all: unset; position: absolute; z-index: 5; display: none; place-items: center;
|
|
98
|
+
top: max(10px, env(safe-area-inset-top)); left: 50%; translate: -50% 0;
|
|
99
|
+
width: 48px; height: 48px; border-radius: 24px; cursor: pointer;
|
|
100
|
+
background: rgb(0 0 0 / 0.35); border: 1px solid rgb(255 255 255 / 0.25); color: #fff; opacity: 0.7;
|
|
101
|
+
}
|
|
102
|
+
.s3air-pause::before { content: ''; width: 14px; height: 16px; border-inline: 5px solid currentColor; box-sizing: border-box; }
|
|
103
|
+
.s3air-app[data-screen='game'][data-touch] .s3air-pause { display: grid; }
|
|
104
|
+
.s3air-panel .text.is-error { color: var(--danger); }
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// sonic3air's own app: what a host gets when it mounts this engine instead of driving
|
|
2
|
+
// the SDK itself — a boot screen, then the game with its OWN title, save select,
|
|
3
|
+
// options and mods, and a pause menu on the wasm-gaming usability scheme
|
|
4
|
+
// (engine-specs UX.md).
|
|
5
|
+
//
|
|
6
|
+
// import * as app from '<engines>/sonic3air/app/app.js'
|
|
7
|
+
// const handle = await app.mount(target, host) // EngineApp.mount
|
|
8
|
+
// await handle.unmount()
|
|
9
|
+
//
|
|
10
|
+
// `host` is engine-specs' EngineAppHost: { game, storage, assets, input, exit }.
|
|
11
|
+
// `assets.rom` is required (Sonic_Knuckles_wSonic3.bin), `assets.audioremaster` is
|
|
12
|
+
// optional. The input is the host's createInput(): resumed it delivers menu actions;
|
|
13
|
+
// suspended (in game) only Select+Start and Escape come through, as `menu`.
|
|
14
|
+
//
|
|
15
|
+
// No load-game screen and no save states: the game's own save select is the load
|
|
16
|
+
// screen, and the engine has no state to snapshot (see RECORD/).
|
|
17
|
+
//
|
|
18
|
+
// Plain JS and DOM on purpose: the app ships inside the engine's package next to the
|
|
19
|
+
// SDK and loads from a static server, so it imports nothing but the SDK and the contract
|
|
20
|
+
// runtime shipped beside it (`../engine-specs.js`).
|
|
21
|
+
|
|
22
|
+
import Sonic3AirSDK from '../sonic3air.sdk.js';
|
|
23
|
+
import { createFullscreenToggle, createWakeLock, resolveLocale } from '../engine-specs.js';
|
|
24
|
+
|
|
25
|
+
const ENGINE = 'sonic3air';
|
|
26
|
+
const OWNER = 'app';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The app's words, in English and Spanish (engine-specs UX.md, "Languages"). The game's own
|
|
30
|
+
* menus stay as the game ships them.
|
|
31
|
+
*/
|
|
32
|
+
const STRINGS = {
|
|
33
|
+
booting: { en: 'Starting the engine…', es: 'Arrancando el motor…' },
|
|
34
|
+
bootFailed: { en: 'Could not start', es: 'No se pudo arrancar' },
|
|
35
|
+
back: { en: 'Back', es: 'Volver' },
|
|
36
|
+
paused: { en: 'Paused', es: 'Pausa' },
|
|
37
|
+
choose: { en: 'choose', es: 'elegir' },
|
|
38
|
+
continueHint: { en: 'continue', es: 'continuar' },
|
|
39
|
+
continue: { en: 'Continue', es: 'Continuar' },
|
|
40
|
+
fullscreen: { en: 'Fullscreen', es: 'Pantalla completa' },
|
|
41
|
+
fullscreenHint: { en: 'Alt+Enter · Select + Y', es: 'Alt+Enter · Select + Y' },
|
|
42
|
+
fullscreenHintMac: { en: 'Cmd+Enter · Select + Y', es: 'Cmd+Enter · Select + Y' },
|
|
43
|
+
exit: { en: 'Back to the launcher', es: 'Volver al lanzador' },
|
|
44
|
+
leaveAsk: { en: 'Back to the launcher?', es: '¿Volver al lanzador?' },
|
|
45
|
+
leaveText: { en: 'The game saves where the game itself saves.', es: 'La partida se guarda donde la guarde el juego.' },
|
|
46
|
+
leave: { en: 'Leave', es: 'Salir' },
|
|
47
|
+
stay: { en: 'Stay', es: 'Seguir' },
|
|
48
|
+
unknownError: { en: 'Unknown error', es: 'Error desconocido' },
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const esc = (text) => String(text ?? '').replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
52
|
+
|
|
53
|
+
/** The error a player reads: the SDK's message without its `sonic3air: ` prefix, capitalised. */
|
|
54
|
+
export const describeError = (error, unknown = STRINGS.unknownError.es) => {
|
|
55
|
+
const text = String(error?.message ?? error ?? '').replace(/^sonic3air:\s*/, '');
|
|
56
|
+
return text ? text[0].toUpperCase() + text.slice(1) : unknown;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
let cssLoaded = null;
|
|
60
|
+
const loadCss = () =>
|
|
61
|
+
(cssLoaded ??= new Promise((resolve) => {
|
|
62
|
+
const link = document.createElement('link');
|
|
63
|
+
link.rel = 'stylesheet';
|
|
64
|
+
link.href = new URL('./app.css', import.meta.url).href;
|
|
65
|
+
link.onload = link.onerror = () => resolve();
|
|
66
|
+
document.head.append(link);
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
export async function mount(target, host) {
|
|
70
|
+
await loadCss();
|
|
71
|
+
|
|
72
|
+
const locale = host.locale ?? resolveLocale();
|
|
73
|
+
const t = (key) => STRINGS[key]?.[locale] ?? STRINGS[key]?.en ?? key;
|
|
74
|
+
|
|
75
|
+
const root = document.createElement('div');
|
|
76
|
+
root.className = 's3air-app';
|
|
77
|
+
root.style.setProperty('--accent', host.game?.accent ?? '#2563eb');
|
|
78
|
+
const stage = document.createElement('div');
|
|
79
|
+
stage.className = 's3air-stage';
|
|
80
|
+
const overlay = document.createElement('div');
|
|
81
|
+
overlay.className = 's3air-overlay';
|
|
82
|
+
const pauseButton = document.createElement('button');
|
|
83
|
+
pauseButton.className = 's3air-pause';
|
|
84
|
+
pauseButton.setAttribute('aria-label', t('paused'));
|
|
85
|
+
root.append(stage, overlay, pauseButton);
|
|
86
|
+
target.append(root);
|
|
87
|
+
|
|
88
|
+
/** screen: 'boot' | 'game' | 'pause' | 'confirm' | 'error' */
|
|
89
|
+
const state = {
|
|
90
|
+
screen: 'boot',
|
|
91
|
+
status: t('booting'),
|
|
92
|
+
error: null,
|
|
93
|
+
pause: { items: [], focus: 0 },
|
|
94
|
+
confirm: null, // { title, text, yes, no, onYes, onNo, focus, under }
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
let play = null;
|
|
98
|
+
let leaving = false;
|
|
99
|
+
let destroyed = false;
|
|
100
|
+
|
|
101
|
+
const canvasFocus = () => stage.querySelector('canvas')?.focus({ preventScroll: true });
|
|
102
|
+
const title = () => host.game?.title ?? 'Sonic 3 A.I.R.';
|
|
103
|
+
|
|
104
|
+
// ---- screens ------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
const hints = (pairs) =>
|
|
107
|
+
`<footer class="s3air-hints">${pairs.map(([k, t]) => `<span><kbd>${k}</kbd>${t}</span>`).join('')}</footer>`;
|
|
108
|
+
|
|
109
|
+
// Fullscreen (Cmd+Enter / Alt+Enter, Select + Y, and the pause-menu entry), and the screen
|
|
110
|
+
// kept on while playing. There is no Ajustes screen here: the game's own Options hold the
|
|
111
|
+
// display settings, so the Wake Lock is always on.
|
|
112
|
+
const fullscreen = createFullscreenToggle(root);
|
|
113
|
+
const wake = createWakeLock();
|
|
114
|
+
|
|
115
|
+
const render = () => {
|
|
116
|
+
if (destroyed) return;
|
|
117
|
+
wake.setActive(state.screen === 'game');
|
|
118
|
+
root.dataset.screen = state.screen;
|
|
119
|
+
const s = state.screen;
|
|
120
|
+
if (s === 'game') {
|
|
121
|
+
overlay.innerHTML = '';
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (s === 'boot') {
|
|
125
|
+
overlay.innerHTML = `<section class="s3air-boot">
|
|
126
|
+
${host.game?.art ? `<img src="${esc(host.game.art)}" alt="">` : ''}
|
|
127
|
+
<p>${esc(state.status)}</p>
|
|
128
|
+
</section>`;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (s === 'error') {
|
|
132
|
+
overlay.innerHTML = `<section class="s3air-panel">
|
|
133
|
+
<p class="kicker">${esc(title())}</p>
|
|
134
|
+
<h2>${esc(t('bootFailed'))}</h2>
|
|
135
|
+
<p class="text is-error">${esc(state.error)}</p>
|
|
136
|
+
<button class="item is-focused" data-exit>${esc(t('back'))}</button>
|
|
137
|
+
</section>`;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let html = '';
|
|
141
|
+
const base = s === 'confirm' ? state.confirm.under : s;
|
|
142
|
+
if (base === 'pause') {
|
|
143
|
+
html += `<section class="s3air-panel">
|
|
144
|
+
<p class="kicker">${esc(title())}</p>
|
|
145
|
+
<h2>${esc(t('paused'))}</h2>
|
|
146
|
+
${state.pause.items.map((item, i) => `<button class="item${i === state.pause.focus && s !== 'confirm' ? ' is-focused' : ''}" data-item="${i}">${esc(item.label)}${item.hint ? `<small>${esc(item.hint)}</small>` : ''}</button>`).join('')}
|
|
147
|
+
${hints([['A', t('choose')], ['B', t('continueHint')]])}
|
|
148
|
+
</section>`;
|
|
149
|
+
}
|
|
150
|
+
if (s === 'confirm') {
|
|
151
|
+
const c = state.confirm;
|
|
152
|
+
html += `<div class="s3air-confirm"><section class="s3air-panel">
|
|
153
|
+
<h2>${esc(c.title)}</h2>
|
|
154
|
+
${c.text ? `<p class="text">${esc(c.text)}</p>` : ''}
|
|
155
|
+
<div class="row">
|
|
156
|
+
<button class="item${c.focus === 0 ? ' is-focused' : ''}" data-confirm="0">${esc(c.no)}</button>
|
|
157
|
+
<button class="item is-danger${c.focus === 1 ? ' is-focused' : ''}" data-confirm="1">${esc(c.yes)}</button>
|
|
158
|
+
</div>
|
|
159
|
+
</section></div>`;
|
|
160
|
+
}
|
|
161
|
+
overlay.innerHTML = html;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ---- transitions --------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
const enterGame = () => {
|
|
167
|
+
state.screen = 'game';
|
|
168
|
+
render();
|
|
169
|
+
host.input.suspend();
|
|
170
|
+
canvasFocus();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const openPause = () => {
|
|
174
|
+
play?.pause(OWNER);
|
|
175
|
+
state.pause = {
|
|
176
|
+
focus: 0,
|
|
177
|
+
items: [
|
|
178
|
+
{ label: t('continue'), run: closePause },
|
|
179
|
+
{
|
|
180
|
+
label: t('fullscreen'),
|
|
181
|
+
hint: /mac|iphone|ipad/i.test(navigator.userAgentData?.platform || navigator.platform || '') ? t('fullscreenHintMac') : t('fullscreenHint'),
|
|
182
|
+
run: () => fullscreen.toggle(),
|
|
183
|
+
},
|
|
184
|
+
{ label: t('exit'), run: askExit },
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
state.screen = 'pause';
|
|
188
|
+
host.input.resume();
|
|
189
|
+
render();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const closePause = () => {
|
|
193
|
+
enterGame();
|
|
194
|
+
play?.resume(OWNER);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// A confirm sits on top of the screen it was asked from and goes back to it.
|
|
198
|
+
const ask = (options) => {
|
|
199
|
+
state.confirm = { focus: 0, under: state.screen, ...options };
|
|
200
|
+
state.screen = 'confirm';
|
|
201
|
+
render();
|
|
202
|
+
};
|
|
203
|
+
const answer = (yes) => {
|
|
204
|
+
const c = state.confirm;
|
|
205
|
+
state.screen = c.under;
|
|
206
|
+
state.confirm = null;
|
|
207
|
+
render();
|
|
208
|
+
(yes ? c.onYes : c.onNo)?.();
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const exit = async () => {
|
|
212
|
+
if (leaving) return;
|
|
213
|
+
leaving = true;
|
|
214
|
+
try {
|
|
215
|
+
await play?.destroy();
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.warn(`[${ENGINE} app] destroy failed`, error);
|
|
218
|
+
}
|
|
219
|
+
play = null;
|
|
220
|
+
host.exit();
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const askExit = () =>
|
|
224
|
+
ask({ title: t('leaveAsk'), text: t('leaveText'), yes: t('leave'), no: t('stay'), onYes: exit });
|
|
225
|
+
|
|
226
|
+
// ---- input ----------------------------------------------------------------------
|
|
227
|
+
|
|
228
|
+
const onPause = (action) => {
|
|
229
|
+
const p = state.pause;
|
|
230
|
+
if (action === 'up') p.focus = (p.focus + p.items.length - 1) % p.items.length;
|
|
231
|
+
else if (action === 'down') p.focus = (p.focus + 1) % p.items.length;
|
|
232
|
+
else if (action === 'accept') return p.items[p.focus].run();
|
|
233
|
+
else if (action === 'back' || action === 'menu') return closePause();
|
|
234
|
+
else return;
|
|
235
|
+
render();
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const onConfirm = (action) => {
|
|
239
|
+
const c = state.confirm;
|
|
240
|
+
if (action === 'left' || action === 'up') c.focus = 0;
|
|
241
|
+
else if (action === 'right' || action === 'down') c.focus = 1;
|
|
242
|
+
else if (action === 'accept') return answer(c.focus === 1);
|
|
243
|
+
else if (action === 'back') return answer(false);
|
|
244
|
+
else return;
|
|
245
|
+
render();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const off = host.input.on((action) => {
|
|
249
|
+
if (leaving) return;
|
|
250
|
+
const s = state.screen;
|
|
251
|
+
if (s === 'game') {
|
|
252
|
+
if (action === 'menu') openPause();
|
|
253
|
+
} else if (s === 'pause') onPause(action);
|
|
254
|
+
else if (s === 'confirm') onConfirm(action);
|
|
255
|
+
else if (s === 'error' && (action === 'accept' || action === 'back')) exit();
|
|
256
|
+
else if (s === 'boot' && action === 'back') exit();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Pointer: hover focuses, click activates — the same paths as the pad. Hover is read
|
|
260
|
+
// from real movement only: every render replaces the buttons, and the browser fires
|
|
261
|
+
// a fresh pointerover for whatever lands under a resting cursor.
|
|
262
|
+
let lastPointer = '';
|
|
263
|
+
const onPointer = (event) => {
|
|
264
|
+
if (event.type === 'pointermove') {
|
|
265
|
+
const at = `${event.clientX},${event.clientY}`;
|
|
266
|
+
if (at === lastPointer) return;
|
|
267
|
+
lastPointer = at;
|
|
268
|
+
}
|
|
269
|
+
const el = event.target.closest('[data-item],[data-confirm],[data-exit]');
|
|
270
|
+
if (!el || leaving) return;
|
|
271
|
+
if (event.type === 'pointermove') {
|
|
272
|
+
if (el.dataset.item != null && state.screen === 'pause' && state.pause.focus !== +el.dataset.item) {
|
|
273
|
+
state.pause.focus = +el.dataset.item;
|
|
274
|
+
render();
|
|
275
|
+
}
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (el.dataset.item != null) state.pause.items[+el.dataset.item].run();
|
|
279
|
+
else if (el.dataset.confirm != null) answer(el.dataset.confirm === '1');
|
|
280
|
+
else if (el.dataset.exit != null) exit();
|
|
281
|
+
};
|
|
282
|
+
overlay.addEventListener('click', onPointer);
|
|
283
|
+
overlay.addEventListener('pointermove', onPointer);
|
|
284
|
+
|
|
285
|
+
// Touch: the game draws its own on-screen pad; the app adds the pause button, shown
|
|
286
|
+
// once a finger has touched the screen (UX.md), hidden again by a key press.
|
|
287
|
+
const onTouch = (event) => {
|
|
288
|
+
if (event.pointerType === 'touch') root.dataset.touch = '';
|
|
289
|
+
};
|
|
290
|
+
const onKey = () => delete root.dataset.touch;
|
|
291
|
+
root.addEventListener('pointerdown', onTouch, { capture: true });
|
|
292
|
+
window.addEventListener('keydown', onKey, { capture: true });
|
|
293
|
+
pauseButton.addEventListener('click', (event) => {
|
|
294
|
+
event.stopPropagation();
|
|
295
|
+
if (state.screen === 'game' && !leaving) openPause();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const handle = {
|
|
299
|
+
async unmount() {
|
|
300
|
+
destroyed = true;
|
|
301
|
+
leaving = true;
|
|
302
|
+
off();
|
|
303
|
+
overlay.removeEventListener('click', onPointer);
|
|
304
|
+
overlay.removeEventListener('pointermove', onPointer);
|
|
305
|
+
root.removeEventListener('pointerdown', onTouch, { capture: true });
|
|
306
|
+
window.removeEventListener('keydown', onKey, { capture: true });
|
|
307
|
+
try {
|
|
308
|
+
await play?.destroy();
|
|
309
|
+
} catch {
|
|
310
|
+
/* already gone */
|
|
311
|
+
}
|
|
312
|
+
play = null;
|
|
313
|
+
fullscreen.destroy();
|
|
314
|
+
wake.destroy();
|
|
315
|
+
root.remove();
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// ---- boot -----------------------------------------------------------------------
|
|
320
|
+
|
|
321
|
+
render();
|
|
322
|
+
host.input.resume();
|
|
323
|
+
try {
|
|
324
|
+
play = await new Sonic3AirSDK()
|
|
325
|
+
.mount(stage)
|
|
326
|
+
.assets(host.assets)
|
|
327
|
+
.storage(host.storage)
|
|
328
|
+
.on('error', ({ detail }) => console.error(`[${ENGINE} app]`, detail))
|
|
329
|
+
// The game's own quit ends the session (the SDK destroys itself): leave too.
|
|
330
|
+
.on('exit', () => exit())
|
|
331
|
+
.start();
|
|
332
|
+
if (destroyed) {
|
|
333
|
+
// Unmounted while booting: nothing to show any more.
|
|
334
|
+
await play.destroy().catch(() => {});
|
|
335
|
+
play = null;
|
|
336
|
+
return handle;
|
|
337
|
+
}
|
|
338
|
+
enterGame();
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error(`[${ENGINE} app]`, error);
|
|
341
|
+
state.error = describeError(error, t('unknownError'));
|
|
342
|
+
state.screen = 'error';
|
|
343
|
+
render();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return handle;
|
|
347
|
+
}
|