@vibechain/os 0.5.1 → 0.6.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/AGENTS.md +52 -11
- package/README.md +115 -20
- package/SECURITY.md +6 -4
- package/dist/app-client.js +20 -4
- package/dist/app-host.d.ts +74 -5
- package/dist/app-host.js +94 -6
- package/dist/app-protocol.d.ts +21 -0
- package/dist/app-protocol.js +9 -0
- package/dist/app-wire.d.ts +186 -6
- package/dist/app-wire.js +213 -7
- package/dist/audio.d.ts +65 -0
- package/dist/audio.js +162 -0
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +2 -1
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.js +5 -3
- package/dist/check.js +11 -4
- package/dist/cli.js +3 -1
- package/dist/commands.d.ts +6 -0
- package/dist/commands.js +17 -0
- package/dist/fake-services.d.ts +88 -0
- package/dist/fake-services.js +132 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/links.d.ts +13 -0
- package/dist/links.js +17 -1
- package/dist/listing.d.ts +12 -0
- package/dist/listing.js +49 -1
- package/dist/manifest.d.ts +76 -1
- package/dist/manifest.js +170 -5
- package/dist/os.d.ts +83 -5
- package/dist/os.js +179 -15
- package/dist/preview-parent.d.ts +21 -2
- package/dist/preview-parent.js +101 -8
- package/dist/preview-surfaces.d.ts +36 -0
- package/dist/preview-surfaces.js +84 -0
- package/dist/preview-ui.js +1 -1
- package/dist/preview.js +4 -2
- package/dist/templates/plain/game.js +3 -1
- package/dist/testing.d.ts +50 -7
- package/dist/testing.js +137 -13
- package/dist/transport.d.ts +4 -1
- package/dist/transport.js +2 -2
- package/dist/vibemarket-os.js +1 -1
- package/examples/paw-beat/README.md +38 -10
- package/examples/paw-beat/cat.ts +13 -0
- package/examples/paw-beat/game.ts +290 -123
- package/examples/paw-beat/index.html +20 -4
- package/examples/paw-beat/main.ts +156 -48
- package/examples/paw-beat/music.ts +72 -337
- package/examples/paw-beat/stage.ts +23 -9
- package/examples/paw-beat/store/screenshot-1.webp +0 -0
- package/examples/paw-beat/store/screenshot-2.webp +0 -0
- package/examples/paw-beat/synth.ts +477 -0
- package/examples/paw-beat/tracks.ts +286 -0
- package/examples/paw-beat/vibemarket.json +15 -8
- package/examples/vibexp-app/plain/game.ts +6 -2
- package/package.json +7 -1
- package/skill.md +471 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
|
-
import {
|
|
2
|
+
import { connect, OsError, type Os } from "@vibechain/os";
|
|
3
|
+
import { createAudio, type AppAudio } from "@vibechain/os/audio";
|
|
3
4
|
import { createLoop } from "@vibechain/os/loop";
|
|
4
5
|
import { fitCanvas } from "@vibechain/os/canvas";
|
|
5
6
|
import { createCat } from "./cat";
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
type DanceGame, type Judgement, type Lane, type
|
|
8
|
+
beatSeconds, COMBO_MILESTONES, comboMultiplier, countInBeats, createGame, gradeRound, pickTrack, readProgress, recordRound, roundAchievements, sectionAt,
|
|
9
|
+
sectionsOf, songSeconds, type DanceGame, type Judgement, type Lane, type Progress, type SectionRole,
|
|
9
10
|
} from "./game";
|
|
10
|
-
import { createMusic } from "./music";
|
|
11
|
+
import { createMusic, soundLabel } from "./music";
|
|
11
12
|
import { createStage, HIT_Z, type StageFrame } from "./stage";
|
|
13
|
+
import type { PlayableTrack } from "./synth";
|
|
14
|
+
import { TRACKS } from "./tracks";
|
|
12
15
|
|
|
13
16
|
function element<T extends HTMLElement>(id: string): T {
|
|
14
17
|
const node = document.getElementById(id);
|
|
@@ -20,29 +23,45 @@ const callout = element("callout"), call = element("call"), combo = element("com
|
|
|
20
23
|
const intro = element("intro"), done = element("done"), bestLine = element("best"), lost = element("lost"), lostText = element("lost-text");
|
|
21
24
|
const startButton = element<HTMLButtonElement>("start"), againButton = element<HTMLButtonElement>("again"), resumeButton = element<HTMLButtonElement>("resume");
|
|
22
25
|
const soundButton = element<HTMLButtonElement>("sound"), scoreText = element("score"), multiplierText = element("multiplier");
|
|
23
|
-
const progress = element("progress"), played = element("played");
|
|
26
|
+
const progress = element("progress"), played = element("played"), nowPlaying = element("now-playing");
|
|
27
|
+
const trackName = element("track-name"), trackMood = element("track-mood"), nextTrackButton = element<HTMLButtonElement>("next-track"), upNext = element("up-next");
|
|
28
|
+
const shareButton = element<HTMLButtonElement>("share"), boardButton = element<HTMLButtonElement>("board"), coatButton = element<HTMLButtonElement>("coat"), shopNote = element("shop");
|
|
24
29
|
|
|
25
30
|
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: "low-power" });
|
|
26
31
|
renderer.setPixelRatio(1); // fitCanvas already sizes the backing store in device pixels.
|
|
27
32
|
const stage = createStage(), cat = createCat();
|
|
28
33
|
stage.scene.add(cat.root);
|
|
29
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Sound is the desktop's: the helper's master follows the vmOS taskbar speaker and volume, the window and the browser's
|
|
36
|
+
* gesture rule, and recovers a context the browser stopped. The game's own button is only an extra mute on top.
|
|
37
|
+
*/
|
|
38
|
+
let audio: AppAudio | null = null;
|
|
39
|
+
const music = createMusic(() => {
|
|
40
|
+
if (!app) return null;
|
|
41
|
+
try { audio = createAudio(app); } catch { return null; } // no Web Audio: the game keeps its own clock, silent
|
|
42
|
+
audio.muted = saved.muted;
|
|
43
|
+
audio.onChange(drawSound);
|
|
44
|
+
return audio;
|
|
45
|
+
});
|
|
30
46
|
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
31
47
|
|
|
32
48
|
/** How hard the cat grooves and the stage pulses in each part of the song. */
|
|
33
|
-
const ENERGY: Readonly<Record<
|
|
49
|
+
const ENERGY: Readonly<Record<SectionRole, number>> = { "count-in": 0.4, intro: 0.55, build: 0.75, drop: 1, break: 0.45, finale: 1, outro: 0.8 };
|
|
34
50
|
|
|
35
51
|
// ---- Round state ----
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const TRACK_IDS = TRACKS.map(item => item.id);
|
|
53
|
+
let app: Os | undefined;
|
|
54
|
+
/** The track that plays when the player next presses Start or Dance again. */
|
|
55
|
+
let chosen = 0;
|
|
56
|
+
let track: PlayableTrack = TRACKS[0]!;
|
|
57
|
+
let game: DanceGame = createGame(track);
|
|
58
|
+
let saved: Progress = readProgress(null, TRACK_IDS);
|
|
59
|
+
/**
|
|
60
|
+
* Tracks are picked by the game's seeded rule (pickTrack), from a seed that starts somewhere new
|
|
61
|
+
* in each window, so a fresh window starts on a random track and the same track never plays twice
|
|
62
|
+
* in a row. The steps themselves use the round number as their seed.
|
|
63
|
+
*/
|
|
64
|
+
const shuffle = Math.floor(Math.random() * 0x7fffffff);
|
|
46
65
|
type Phase = "title" | "playing" | "results";
|
|
47
66
|
let phase: Phase = "title", paused = false, contextLost = false;
|
|
48
67
|
let songTime = 0, idleClock = 0, lastMilestone = 0, reported = false, reportTimer: number | undefined;
|
|
@@ -53,8 +72,9 @@ const frame: StageFrame = { beat: 0, section: "intro", energy: 0.35, reducedMoti
|
|
|
53
72
|
let pendingScore = 0, viewWidth = 0, viewHeight = 0;
|
|
54
73
|
|
|
55
74
|
function save() {
|
|
56
|
-
//
|
|
57
|
-
|
|
75
|
+
// Kept for the player across opens and devices (a guest's only while the window is open). Saves are coalesced by the SDK,
|
|
76
|
+
// and a failed write only loses the personal bests and settings; the game goes on.
|
|
77
|
+
void app?.save({ best: saved.best, bests: { ...saved.bests }, rounds: saved.rounds, muted: saved.muted, last: saved.last, coat: saved.coat }).catch(() => {});
|
|
58
78
|
}
|
|
59
79
|
|
|
60
80
|
// ---- Feedback ----
|
|
@@ -125,23 +145,55 @@ function release(lane: Lane) {
|
|
|
125
145
|
pads.querySelector(`[data-lane="${lane}"]`)?.classList.remove("down");
|
|
126
146
|
}
|
|
127
147
|
|
|
148
|
+
/** The desktop's sound: from the helper once it exists, else from the host (audible on a host that does not say). */
|
|
149
|
+
function desktopSound() { return audio?.desktop ?? app?.sound ?? { muted: false, volume: 1 }; }
|
|
150
|
+
/** The button says what the player will hear: off by the game's own toggle, off because vmOS is muted, or on. */
|
|
151
|
+
function drawSound() {
|
|
152
|
+
const label = soundLabel(!saved.muted, desktopSound());
|
|
153
|
+
soundButton.setAttribute("aria-pressed", String(label.pressed));
|
|
154
|
+
soundButton.textContent = label.text;
|
|
155
|
+
soundButton.title = label.title;
|
|
156
|
+
}
|
|
157
|
+
/** The game's own toggle: an extra mute that can silence the game but never turns on what vmOS has muted. */
|
|
128
158
|
function setSound(on: boolean) {
|
|
129
|
-
saved
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
soundButton.textContent = on ? "♪ Sound on" : "♪ Sound off";
|
|
159
|
+
saved = { ...saved, muted: !on };
|
|
160
|
+
if (audio) audio.muted = !on;
|
|
161
|
+
drawSound();
|
|
133
162
|
}
|
|
134
163
|
|
|
135
164
|
// ---- Flow: title, count-in and song, results ----
|
|
165
|
+
const plural = (count: number, word: string) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
166
|
+
/** Choose the next track and show it on the title card and in the stage's colours. */
|
|
167
|
+
function choose(index: number) {
|
|
168
|
+
chosen = index;
|
|
169
|
+
const next = TRACKS[index]!, best = saved.bests[next.id] ?? 0;
|
|
170
|
+
trackName.textContent = next.name;
|
|
171
|
+
trackMood.textContent = `${next.mood} ${next.bpm} beats a minute${best > 0 ? `, your best ${best.toLocaleString("en-US")}` : ""}.`;
|
|
172
|
+
upNext.textContent = `Next up: ${next.name}`;
|
|
173
|
+
stage.setColours(next.colours);
|
|
174
|
+
}
|
|
175
|
+
/** The section marks on the progress bar, for this track's sections. */
|
|
176
|
+
function drawSections() {
|
|
177
|
+
for (const mark of Array.from(progress.querySelectorAll("i"))) mark.remove();
|
|
178
|
+
for (const section of sectionsOf(track)) {
|
|
179
|
+
const mark = document.createElement("i");
|
|
180
|
+
mark.style.flex = String(section.beats);
|
|
181
|
+
progress.insertBefore(mark, played);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
136
185
|
function begin() {
|
|
137
186
|
report(); // a previous round's score goes to the host before the next starts
|
|
138
187
|
const seed = saved.rounds + 1;
|
|
139
|
-
|
|
188
|
+
track = TRACKS[chosen]!;
|
|
189
|
+
game = createGame(track, seed);
|
|
140
190
|
songTime = 0;
|
|
141
191
|
lastMilestone = 0;
|
|
142
192
|
shownCount = -1;
|
|
143
|
-
|
|
144
|
-
|
|
193
|
+
nowPlaying.textContent = track.name;
|
|
194
|
+
drawSections();
|
|
195
|
+
stage.setColours(track.colours);
|
|
196
|
+
music.start(track, seed);
|
|
145
197
|
phase = "playing";
|
|
146
198
|
intro.hidden = done.hidden = true;
|
|
147
199
|
hud.hidden = pads.hidden = false;
|
|
@@ -149,7 +201,7 @@ function begin() {
|
|
|
149
201
|
cat.setMood("neutral");
|
|
150
202
|
stage.frame("play", motion.matches);
|
|
151
203
|
drawScore();
|
|
152
|
-
say.textContent =
|
|
204
|
+
say.textContent = `${track.name}. Get ready.`;
|
|
153
205
|
canvas.focus();
|
|
154
206
|
}
|
|
155
207
|
|
|
@@ -158,9 +210,13 @@ function end() {
|
|
|
158
210
|
music.stop();
|
|
159
211
|
stage.hideNotes();
|
|
160
212
|
const { score, bestCombo, counts } = game.state, result = gradeRound(counts);
|
|
161
|
-
const newBest = score >
|
|
162
|
-
saved =
|
|
213
|
+
const trackBest = saved.bests[track.id] ?? 0, newBest = score > trackBest && score > 0;
|
|
214
|
+
saved = recordRound(saved, track.id, score);
|
|
163
215
|
save();
|
|
216
|
+
element("done-track").textContent = track.name;
|
|
217
|
+
element("done-track-best").textContent = `Best on this track: ${saved.bests[track.id]!.toLocaleString("en-US")}${saved.best > saved.bests[track.id]! ? ` · overall ${saved.best.toLocaleString("en-US")}` : ""}`;
|
|
218
|
+
// Dance again plays another track, never this one twice in a row.
|
|
219
|
+
choose(pickTrack(TRACKS.length, shuffle + saved.rounds, TRACK_IDS.indexOf(track.id)));
|
|
164
220
|
hud.hidden = pads.hidden = combo.hidden = true;
|
|
165
221
|
call.textContent = "";
|
|
166
222
|
element("grade").textContent = result.grade;
|
|
@@ -171,11 +227,13 @@ function end() {
|
|
|
171
227
|
element("full-combo").hidden = !result.fullCombo;
|
|
172
228
|
for (const kind of ["perfect", "great", "good", "miss"] as const) element(`done-${kind}`).textContent = String(counts[kind]);
|
|
173
229
|
element("sent").textContent = "Your score goes to VibeMarket OS in a moment.";
|
|
230
|
+
// Achievements cost nothing to ask for: vmOS records each once and shows its own toast the first time.
|
|
231
|
+
for (const id of roundAchievements({ bestCombo, fullCombo: result.fullCombo })) void app?.unlock(id).catch(() => {});
|
|
174
232
|
done.hidden = false;
|
|
175
233
|
stage.frame("title", motion.matches);
|
|
176
234
|
cat.setMood(result.grade === "S" || result.grade === "A" || result.grade === "B" ? "happy" : result.grade === "D" ? "sad" : "neutral");
|
|
177
235
|
if (result.grade === "S" || result.grade === "A") { cat.celebrate(); stage.confetti(); }
|
|
178
|
-
say.textContent =
|
|
236
|
+
say.textContent = `${track.name} over. Grade ${result.grade}, ${score} points, ${result.accuracy.toFixed(1)} percent accuracy.${newBest ? " New best!" : ""}`;
|
|
179
237
|
againButton.focus();
|
|
180
238
|
// The host owns the final results screen and may replace this frame once it has the score, so
|
|
181
239
|
// the card above gets a few seconds first. If the host declines (it accepts one score per open
|
|
@@ -188,7 +246,8 @@ function report() {
|
|
|
188
246
|
window.clearTimeout(reportTimer);
|
|
189
247
|
if (reported || phase !== "results") return;
|
|
190
248
|
reported = true;
|
|
191
|
-
|
|
249
|
+
// One board for all six tracks (a manifest may declare five), so the score goes to the default board, "score".
|
|
250
|
+
app?.finish({ score: pendingScore }).then(
|
|
192
251
|
() => { element("sent").textContent = "Score sent to VibeMarket OS."; },
|
|
193
252
|
() => { element("sent").textContent = "VibeMarket OS keeps one score per open window, so this one stays here."; },
|
|
194
253
|
);
|
|
@@ -218,6 +277,51 @@ for (const pad of Array.from(pads.querySelectorAll<HTMLButtonElement>("button[da
|
|
|
218
277
|
}
|
|
219
278
|
soundButton.addEventListener("click", () => { setSound(saved.muted); save(); });
|
|
220
279
|
|
|
280
|
+
// ---- vmOS services (SDK 0.6). Every one is optional: on a host that predates it the call answers `unsupported` and the
|
|
281
|
+
// button goes away; nothing else in the game depends on them. ----
|
|
282
|
+
/** Hide `button` for good when the host cannot do what it does; true when the error was handled that way. */
|
|
283
|
+
function retire(button: HTMLButtonElement, error: unknown): boolean {
|
|
284
|
+
if (error instanceof OsError && error.code === "unsupported") { button.hidden = true; return true; }
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
/** Results card: vmOS composes a card with the score and the player's rank, and the player chooses where to post it. */
|
|
288
|
+
shareButton.addEventListener("click", () => {
|
|
289
|
+
app?.share({ score: pendingScore, text: `I scored ${pendingScore.toLocaleString("en-US")} on ${track.name} in Paw Beat!` }).catch(error => {
|
|
290
|
+
if (!retire(shareButton, error) && error instanceof OsError && error.code === "guest") element("sent").textContent = "Sign in to VibeMarket OS to share your score.";
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
/** Results card: vmOS draws its own leaderboard panel over the game (everyone and friends, this week and all time). */
|
|
294
|
+
boardButton.addEventListener("click", () => { app?.showLeaderboard().catch(error => { retire(boardButton, error); }); });
|
|
295
|
+
|
|
296
|
+
/** The one product: a cosmetic coat for Biscuit, bought once with Printer Cash in vmOS's own dialog. */
|
|
297
|
+
const COAT_PRODUCT = "midnight-coat";
|
|
298
|
+
let coatOwned = false;
|
|
299
|
+
function wear(coat: Progress["coat"]) {
|
|
300
|
+
saved = { ...saved, coat };
|
|
301
|
+
cat.setCoat(coat);
|
|
302
|
+
drawCoat();
|
|
303
|
+
}
|
|
304
|
+
function drawCoat() {
|
|
305
|
+
coatButton.textContent = !coatOwned ? "Midnight coat · 25 Printer Cash" : saved.coat === "midnight" ? "Wear the ginger coat" : "Wear the midnight coat";
|
|
306
|
+
}
|
|
307
|
+
coatButton.addEventListener("click", () => {
|
|
308
|
+
if (coatOwned) { wear(saved.coat === "midnight" ? "classic" : "midnight"); save(); return; }
|
|
309
|
+
shopNote.textContent = "";
|
|
310
|
+
// buy needs this click: vmOS opens its spend dialog, and the promise settles when the player decides
|
|
311
|
+
app?.buy(COAT_PRODUCT).then(() => { coatOwned = true; wear("midnight"); save(); shopNote.textContent = "The midnight coat is yours."; }, error => {
|
|
312
|
+
if (retire(coatButton, error) || !(error instanceof OsError) || error.code === "cancelled") return;
|
|
313
|
+
shopNote.textContent = error.code === "insufficient" ? "Not enough Printer Cash yet." : error.code === "guest" ? "Sign in to VibeMarket OS to buy." : "The coat could not be bought right now.";
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
/** Whether the player owns the coat (on every device): from the host's product list. Without it the button stays hidden. */
|
|
317
|
+
async function readShop(host: Os) {
|
|
318
|
+
try {
|
|
319
|
+
coatOwned = (await host.products()).some(product => product.id === COAT_PRODUCT && product.owned);
|
|
320
|
+
coatButton.hidden = false;
|
|
321
|
+
} catch { coatButton.hidden = true; }
|
|
322
|
+
wear(coatOwned ? saved.coat : "classic");
|
|
323
|
+
}
|
|
324
|
+
|
|
221
325
|
// ---- HUD: touch the DOM only when a value actually changed ----
|
|
222
326
|
/** Score, multiplier and combo change only on a hit or a miss, so this runs on those events, not every frame. */
|
|
223
327
|
function drawScore() {
|
|
@@ -232,17 +336,18 @@ function drawScore() {
|
|
|
232
336
|
showCombo(state.combo);
|
|
233
337
|
}
|
|
234
338
|
function drawHud(now: number) {
|
|
235
|
-
const percent = Math.max(0, Math.min(100, Math.floor((now /
|
|
339
|
+
const percent = Math.max(0, Math.min(100, Math.floor((now / songSeconds(track)) * 100)));
|
|
236
340
|
if (percent !== shownProgress) {
|
|
237
341
|
shownProgress = percent;
|
|
238
342
|
played.style.width = `${percent}%`;
|
|
239
343
|
progress.setAttribute("aria-valuenow", String(percent));
|
|
240
344
|
}
|
|
241
|
-
// Count-in: 3, 2, 1, Go!
|
|
242
|
-
const
|
|
243
|
-
|
|
345
|
+
// Count-in: the clicks count down to Go! (3, 2, 1, Go! in four; 2, 1, Go! in a waltz's three).
|
|
346
|
+
const clicks = countInBeats(track), beat = beatSeconds(track);
|
|
347
|
+
const count = now < clicks * beat ? Math.max(0, Math.floor(now / beat)) : clicks;
|
|
348
|
+
if (count !== shownCount && count < clicks) {
|
|
244
349
|
call.dataset.kind = "count";
|
|
245
|
-
call.textContent =
|
|
350
|
+
call.textContent = count === clicks - 1 ? "Go!" : String(clicks - 1 - count);
|
|
246
351
|
pop(call, true);
|
|
247
352
|
}
|
|
248
353
|
shownCount = count;
|
|
@@ -266,7 +371,7 @@ function placeCallout() {
|
|
|
266
371
|
// ---- Boot: connect, restore, then let the host know the first frame is up. ----
|
|
267
372
|
async function boot() {
|
|
268
373
|
try {
|
|
269
|
-
app = await
|
|
374
|
+
app = await connect();
|
|
270
375
|
} catch {
|
|
271
376
|
startButton.textContent = "Open in VibeMarket OS";
|
|
272
377
|
return;
|
|
@@ -285,7 +390,7 @@ async function boot() {
|
|
|
285
390
|
onContextLost() {
|
|
286
391
|
// GPU resources are gone. Pause the song with the game so nothing is judged blind.
|
|
287
392
|
contextLost = paused = true;
|
|
288
|
-
|
|
393
|
+
if (audio) audio.paused = true;
|
|
289
394
|
lostText.textContent = "The graphics stopped. Waiting for them to come back…";
|
|
290
395
|
resumeButton.hidden = true;
|
|
291
396
|
lost.hidden = false;
|
|
@@ -301,7 +406,7 @@ async function boot() {
|
|
|
301
406
|
resumeButton.addEventListener("click", () => {
|
|
302
407
|
lost.hidden = true;
|
|
303
408
|
paused = false;
|
|
304
|
-
if (
|
|
409
|
+
if (audio) audio.paused = false;
|
|
305
410
|
canvas.focus();
|
|
306
411
|
});
|
|
307
412
|
createLoop(host, {
|
|
@@ -309,18 +414,18 @@ async function boot() {
|
|
|
309
414
|
const seconds = stepMs / 1000;
|
|
310
415
|
if (paused) return;
|
|
311
416
|
idleClock += seconds;
|
|
312
|
-
let beat = idleClock * 0.9, section:
|
|
417
|
+
let beat = idleClock * 0.9, section: SectionRole = "intro", energy = 0.35;
|
|
313
418
|
if (phase === "playing") {
|
|
314
419
|
tickClock(seconds);
|
|
315
420
|
const now = songTime;
|
|
316
|
-
music.pump();
|
|
421
|
+
music.pump(now);
|
|
317
422
|
catchUp();
|
|
318
423
|
drawHud(now);
|
|
319
|
-
beat = now /
|
|
320
|
-
section = sectionAt(Math.max(0, beat)).
|
|
424
|
+
beat = now / beatSeconds(track);
|
|
425
|
+
section = sectionAt(track, Math.max(0, beat)).role;
|
|
321
426
|
energy = ENERGY[section];
|
|
322
427
|
stage.notes(now, game.each);
|
|
323
|
-
if (now >=
|
|
428
|
+
if (now >= songSeconds(track)) end();
|
|
324
429
|
} else if (phase === "results") {
|
|
325
430
|
energy = 0.5;
|
|
326
431
|
section = "outro";
|
|
@@ -340,11 +445,14 @@ async function boot() {
|
|
|
340
445
|
if (!contextLost) renderer.render(stage.scene, stage.camera);
|
|
341
446
|
},
|
|
342
447
|
});
|
|
343
|
-
host.
|
|
448
|
+
host.onSound(drawSound);
|
|
344
449
|
|
|
345
|
-
saved =
|
|
450
|
+
saved = readProgress(await host.load().catch(() => null), TRACK_IDS);
|
|
451
|
+
await readShop(host);
|
|
346
452
|
setSound(!saved.muted);
|
|
347
|
-
bestLine.textContent = saved.rounds > 0 ? `Best: ${saved.best.toLocaleString("en-US")} over ${saved.rounds
|
|
453
|
+
bestLine.textContent = saved.rounds > 0 ? `Best: ${saved.best.toLocaleString("en-US")} over ${plural(saved.rounds, "song")}.` : `${TRACKS.length} tracks, about a minute each.`;
|
|
454
|
+
choose(pickTrack(TRACKS.length, shuffle, saved.last === null ? null : TRACK_IDS.indexOf(saved.last)));
|
|
455
|
+
nextTrackButton.addEventListener("click", () => choose((chosen + 1) % TRACKS.length));
|
|
348
456
|
stage.frame("title", true);
|
|
349
457
|
startButton.textContent = "Start dancing";
|
|
350
458
|
startButton.disabled = false;
|
|
@@ -352,7 +460,7 @@ async function boot() {
|
|
|
352
460
|
againButton.addEventListener("click", begin);
|
|
353
461
|
await host.ready();
|
|
354
462
|
startButton.focus();
|
|
355
|
-
window.addEventListener("pagehide", () => { report(); music.dispose(); cat.dispose(); stage.dispose(); renderer.dispose(); host.
|
|
463
|
+
window.addEventListener("pagehide", () => { report(); music.dispose(); audio?.close(); cat.dispose(); stage.dispose(); renderer.dispose(); host.close(); }, { once: true });
|
|
356
464
|
}
|
|
357
465
|
canvas.tabIndex = 0;
|
|
358
466
|
void boot();
|