@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.
Files changed (59) hide show
  1. package/AGENTS.md +52 -11
  2. package/README.md +115 -20
  3. package/SECURITY.md +6 -4
  4. package/dist/app-client.js +20 -4
  5. package/dist/app-host.d.ts +74 -5
  6. package/dist/app-host.js +94 -6
  7. package/dist/app-protocol.d.ts +21 -0
  8. package/dist/app-protocol.js +9 -0
  9. package/dist/app-wire.d.ts +186 -6
  10. package/dist/app-wire.js +213 -7
  11. package/dist/audio.d.ts +65 -0
  12. package/dist/audio.js +162 -0
  13. package/dist/browser.d.ts +2 -1
  14. package/dist/browser.js +2 -1
  15. package/dist/bundle.d.ts +2 -0
  16. package/dist/bundle.js +5 -3
  17. package/dist/check.js +11 -4
  18. package/dist/cli.js +3 -1
  19. package/dist/commands.d.ts +6 -0
  20. package/dist/commands.js +17 -0
  21. package/dist/fake-services.d.ts +88 -0
  22. package/dist/fake-services.js +132 -0
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +1 -1
  25. package/dist/links.d.ts +13 -0
  26. package/dist/links.js +17 -1
  27. package/dist/listing.d.ts +12 -0
  28. package/dist/listing.js +49 -1
  29. package/dist/manifest.d.ts +76 -1
  30. package/dist/manifest.js +170 -5
  31. package/dist/os.d.ts +83 -5
  32. package/dist/os.js +179 -15
  33. package/dist/preview-parent.d.ts +21 -2
  34. package/dist/preview-parent.js +101 -8
  35. package/dist/preview-surfaces.d.ts +36 -0
  36. package/dist/preview-surfaces.js +84 -0
  37. package/dist/preview-ui.js +1 -1
  38. package/dist/preview.js +4 -2
  39. package/dist/templates/plain/game.js +3 -1
  40. package/dist/testing.d.ts +50 -7
  41. package/dist/testing.js +137 -13
  42. package/dist/transport.d.ts +4 -1
  43. package/dist/transport.js +2 -2
  44. package/dist/vibemarket-os.js +1 -1
  45. package/examples/paw-beat/README.md +38 -10
  46. package/examples/paw-beat/cat.ts +13 -0
  47. package/examples/paw-beat/game.ts +290 -123
  48. package/examples/paw-beat/index.html +20 -4
  49. package/examples/paw-beat/main.ts +156 -48
  50. package/examples/paw-beat/music.ts +72 -337
  51. package/examples/paw-beat/stage.ts +23 -9
  52. package/examples/paw-beat/store/screenshot-1.webp +0 -0
  53. package/examples/paw-beat/store/screenshot-2.webp +0 -0
  54. package/examples/paw-beat/synth.ts +477 -0
  55. package/examples/paw-beat/tracks.ts +286 -0
  56. package/examples/paw-beat/vibemarket.json +15 -8
  57. package/examples/vibexp-app/plain/game.ts +6 -2
  58. package/package.json +7 -1
  59. package/skill.md +471 -0
@@ -1,24 +1,52 @@
1
1
  # Paw Beat
2
2
 
3
- A 3D rhythm game for VibeMarket OS, written in TypeScript with Three.js. Arrows slide down four lanes toward their outlines. Press the matching key as each one lands (arrow keys, WASD or the on-screen pads) and Biscuit the cat dances that step: a side step and point for left and right, a leap with paws up for up, a squat and floor pat for down. Timing is judged perfect, great or good; every ten steps in a row adds 10% to each step, up to double, and combos of 10, 25, 50, 75 and 100 earn a spin and confetti. A miss makes Biscuit stumble. One song lasts about a minute and ends with a results card: grade, score, accuracy, best combo and every judgement, with your personal best marked.
3
+ A 3D rhythm game for VibeMarket OS, written in TypeScript with Three.js. Arrows slide down four lanes toward their outlines. Press the matching key as each one lands (arrow keys, WASD or the on-screen pads) and Biscuit the cat dances that step: a side step and point for left and right, a leap with paws up for up, a squat and floor pat for down. Timing is judged perfect, great or good; every ten steps in a row adds 10% to each step, up to double, and combos of 10, 25, 50, 75 and 100 earn a spin and confetti. A miss makes Biscuit stumble. There are six tracks of about a minute each; a random one plays when you start, never the same one twice in a row, and **Next track** on the title card picks another. Each round ends with a results card: grade, score, accuracy, best combo and every judgement, with your personal best on that track marked, and buttons to share the score and open the leaderboard.
4
+
5
+ ## The tracks
6
+
7
+ | Track | Tempo | Key | Character |
8
+ |---|---|---|---|
9
+ | Biscuit's Groove | 120 | A minor | The original song: a four-on-the-floor dance beat with a saw-and-square lead that builds, drops and comes home |
10
+ | Sunny Windowsill | 100, swung | F major | A lazy shuffle: electric piano, a slap of bass, a whistled verse and a chorus walked down the chords |
11
+ | Midnight Zoomies | 140 | E minor | A broken beat with a growling, detuned bass and a bright supersaw hook; a lift through B major into the finale |
12
+ | Yarn Ball Waltz | 150, in 3/4 | D major | A music-box waltz on a strummed nylon guitar, with a borrowed G minor chord for a wistful turn |
13
+ | Rooftop Bossa | 112 | G minor (dorian) | A bossa nova: nylon strings, a soft flute, a clave on the rim and a bridge through B-flat |
14
+ | Laser Pointer | 132 | C major, then D | Chiptune: square waves, racing arpeggios, noise drums and a key change for the last level |
15
+
16
+ All six are original, written for this example, and played by the same instruments in `synth.ts`.
4
17
 
5
18
  It is a complete example of the app API and of a small game built entirely in code:
6
19
 
7
20
  | File | What it shows |
8
21
  |---|---|
9
- | `game.ts` | The rules as pure TypeScript with no DOM, renderer or audio, so they can be unit-tested: the song's sections and melody as data, a chart generator that writes steps from them, timing judgement, combo bonus and the grade |
22
+ | `game.ts` | The rules as pure TypeScript with no DOM, renderer or audio, so they can be unit-tested: reading a track (note and chord names, sections, swing), a chart generator that writes fair steps from the track's own tune, timing judgement, combo bonus, the grade, picking the next track, the personal bests and which achievements a round earns |
23
+ | `tracks.ts` | The six tracks as plain data: tempo, meter, sections, chords, the tune as note names, and the drum, bass, pad and arpeggio patterns |
24
+ | `synth.ts` | The instruments, all oscillators and noise (four drum kits, five basses, six leads, five pads, arpeggios, risers and cymbal swells), a tempo-synced echo and a small generated room, ducking under the kick and a soft limiter; and the player that turns a track's data into sound |
10
25
  | `cat.ts` | Biscuit, built at runtime: smooth body parts meshed from signed distance functions ("surface nets"), a toon shader with rim light and outline, a face painted by the shader so expressions are a few numbers, two-bone inverse kinematics for arms and legs, a tube tail rewritten every frame, and spring-blended dance moves |
11
- | `stage.ts` | The dance floor, backdrop and spotlights as single shader meshes that pulse with the beat and take each section's colours; the lanes and targets; every note in one instanced mesh; pooled sparks and confetti; camera framings that fit any window size |
12
- | `music.ts` | The whole song synthesized with Web Audio (drums, bass, pads, lead, bell, risers) through a soft limiter, scheduled ahead on the audio clock, which also times the steps |
13
- | `main.ts` | `connectVibeMarketApp()`, `fitCanvas` (with WebGL context loss handled) and `createLoop` from the SDK helpers; the title, play and results flow; a checkpoint for the personal best and the sound setting; and `game.finish({ score })` |
26
+ | `stage.ts` | The dance floor, backdrop and spotlights as single shader meshes that pulse with the beat and take the track's colours, tinted by each section; the lanes and targets; every note in one instanced mesh; pooled sparks and confetti; camera framings that fit any window size |
27
+ | `music.ts` | The live song: the chosen track scheduled a beat at a time ahead of the audio clock, which also times the steps, through the SDK's audio helper |
28
+ | `main.ts` | `connect()`, `fitCanvas` (with WebGL context loss handled), `createLoop` and `createAudio` (the desktop's sound) from the SDK helpers; the title, play and results flow; the track choice; `os.load` and `os.save` for the personal bests, the sound setting and the coat; `os.finish({ score })`; and the vmOS services: achievements, sharing, the leaderboard panel and buying the midnight coat |
14
29
  | `index.html` | The page: the canvas, the score and progress display, the judgement and combo callout, the touch pads, the title and results cards, all styled inline |
15
30
 
16
- Nothing is downloaded or generated outside the game: there are no models, textures, fonts, samples or images in the bundle. It is `index.html`, one script, the manifest and the three store images in `store/`, which are captures of the game itself. The song's arrangement is fixed; the steps, and the way the drop's tune is answered, come from a seed, so each round is a little different and any round can be replayed in a test.
31
+ Nothing is downloaded or generated outside the game: there are no models, textures, fonts, samples or images in the bundle. It is `index.html`, one script, the manifest and the three store images in `store/`, which are captures of the game itself. Each track's arrangement is fixed; the steps, and some of its phrases, come from a seed, so each round is a little different and any round can be replayed in a test.
32
+
33
+ ## Adding a track
34
+
35
+ A track is data in `tracks.ts`; nothing else needs to change. Give it an `id`, a `name` and a `mood`; a `bpm`, a `meter` (4, or 3 for a waltz) and a `swing`; and its sections in order, from a one-bar count-in to an outro whose last note is the home note. Each section has a role (which sets how the steps are written and how the stage behaves), a number of bars, its chords ("Am F C G", or "F,G" for two in a bar), which phrases of the tune play, and which drum, bass, pad and arpeggio patterns sound. Write the tune as note names with lengths in eighths ("E5:2 A5:1 r:1"); a list of phrases gives the seed alternatives. Patterns are strings of sixteenth notes, explained at the top of `synth.ts`. Then run the tests: they check that the tune fits its sections, that every pattern exists and is whole bars long, that the chart is fair and about as hard as the others, and that nothing is scheduled in the past or after the end.
36
+
37
+ ## Leaderboard, achievements, sharing and the midnight coat
38
+
39
+ These use the vmOS services of `@vibechain/os` 0.6, declared in `vibemarket.json`. Each is optional: on a host older than 0.6 its call answers `unsupported`, the button disappears and the game plays exactly as before.
40
+
41
+ - **Leaderboard.** One board, `score`, named "Top dancers", for all six tracks: a manifest may declare five boards, so a board per track does not fit. `os.finish({ score })` posts each round's score to it (vmOS keeps each player's best). **Leaderboard** on the results card calls `os.showLeaderboard()`, and vmOS draws its own panel over the game.
42
+ - **Achievements.** *First dance* (finish a round), *Fifty in a row* (a 50 combo) and the secret *Clean paws* (a round without a miss). `roundAchievements` in `game.ts` decides which a round earns; `main.ts` calls `os.unlock(id)` for each, every time, because vmOS records each once and shows its own toast only the first time.
43
+ - **Share score.** `os.share({ score, text })` on the results card: vmOS composes the card (the game's name, the player's name, the score and their rank) and the player chooses where to post it, or closes the sheet.
44
+ - **The midnight coat.** One `permanent` product, 25 Printer Cash. The title card's coat button calls `os.buy("midnight-coat")` from its click; vmOS draws the spend dialog and the game learns only the answer. `os.products()` says whether the player owns it on every start and device, and once owned the button switches coats (`cat.setCoat`). It is cosmetic: it changes nothing in the score. Guests see a "sign in" note; a cancelled dialog changes nothing.
17
45
 
18
46
  ## Controls
19
47
 
20
48
  - Arrow keys or `A` `S` `W` `D`, or tap the pads at the bottom.
21
- - `M` or the sound button turns the music off and on. Sound starts with your first press of **Start dancing**, as browsers require.
49
+ - Sound follows the vmOS taskbar speaker and volume, live. `M` or the sound button is an extra mute for the game alone: it can turn the music off, never on while vmOS is muted, and then the button says "Sound off in vmOS". Sound starts with your first press of **Start dancing**, as browsers require; if the browser held it back, the next key or tap starts it and the music joins at the current beat.
22
50
  - The game follows `prefers-reduced-motion`: the camera cuts instead of gliding, the spotlights hold still and the floor stops flashing on each bar.
23
51
 
24
52
  ## Build and run
@@ -40,7 +68,7 @@ The loop does no allocation per frame and touches the DOM only when a number cha
40
68
 
41
69
  ## Listing in VibeStore
42
70
 
43
- `vibemarket.json` uses manifest schema version 2, so it carries a complete VibeStore listing: a `window` of 960 x 600 that can be resized, and a `store` object with the icon, two screenshots, a plain-text description, the `game` category, a content rating (violence `none`, language `none`, not mature) and a support link.
71
+ `vibemarket.json` uses manifest schema version 3, so it carries a complete VibeStore listing: a `window` of 960 x 600 that can be resized, and a `store` object with the icon, two screenshots, a plain-text description, the `game` category, a content rating (violence `none`, language `none`, not mature) and a support link; and the 0.6 declarations: one leaderboard, three achievements and one product.
44
72
 
45
73
  The requirements are checked when you submit from the VibeStore **Submit** tab, and `os pack` and `os preview` check the same things locally:
46
74
 
@@ -55,8 +83,8 @@ The requirements are checked when you submit from the VibeStore **Submit** tab,
55
83
 
56
84
  ## What the score means
57
85
 
58
- The score is reported to the host with `game.finish` a few seconds after the results card appears, or straight away if you press **Dance again**. The host owns the final results screen and may replace the game's window once it has the score; if it keeps the window open, the card stays as the result. The score is display data: the game cannot grant Cash, XP or items, and the preview awards nothing.
86
+ The score is reported to the host with `os.finish` a few seconds after the results card appears, or straight away if you press **Dance again**. The host owns the final results screen and may replace the game's window once it has the score; if it keeps the window open, the card stays as the result. The score is display data: it never sets a reward. Finishing a round may earn the player a small amount of Printer Cash, decided and paid by VibeMarket OS; the game cannot grant or change it. The preview awards nothing.
59
87
 
60
88
  ## License
61
89
 
62
- MIT, with the rest of the `@vibechain/os` package. Biscuit, the song and all of the code here are original to this example.
90
+ MIT, with the rest of the `@vibechain/os` package. Biscuit, the six tracks and all of the code here are original to this example.
@@ -36,6 +36,8 @@ export interface Cat {
36
36
  setMood(mood: "neutral" | "happy" | "sad"): void;
37
37
  /** Colour of the rim light, from the stage. */
38
38
  setRim(color: THREE.Color): void;
39
+ /** Biscuit's coat: the classic ginger tabby, or the midnight coat a player can buy in the game. */
40
+ setCoat(coat: Coat): void;
39
41
  /**
40
42
  * Advance by `seconds`. `beat` is the song position in beats, so the idle groove lands on the
41
43
  * music; `energy` (0 to 1) is how hard to groove.
@@ -49,6 +51,9 @@ const SCALE = 1.15;
49
51
 
50
52
  // ---- Palette ----
51
53
  const FUR = "#f2923e", STRIPE = "#c4581f", CREAM = "#fff1da", PINK = "#ff8fab", INK = "#2a1a2e";
54
+ export type Coat = "classic" | "midnight";
55
+ /** Fur and stripe colours of each coat; the markings, face and paws stay the same. */
56
+ const COATS: Readonly<Record<Coat, { fur: string; stripe: string }>> = { classic: { fur: FUR, stripe: STRIPE }, midnight: { fur: "#2f3f8f", stripe: "#c9d4ff" } };
52
57
  const IRIS = "#9be15d", IRIS_DARK = "#3f8f3a";
53
58
 
54
59
  // ---- Signed distance functions and the mesher ----
@@ -361,9 +366,12 @@ export function createCat(): Cat {
361
366
  uFace: { value: new THREE.Vector4(1, 0, 0, 0) },
362
367
  uLook: { value: new THREE.Vector2() },
363
368
  };
369
+ /** The fur-coloured materials, recoloured by setCoat. */
370
+ const furs: THREE.ShaderMaterial[] = [];
364
371
  const toon = (base: string, pattern?: "HEAD" | "BODY" | "TAIL" | "EAR" | "LIMB") => {
365
372
  const material = new THREE.ShaderMaterial({ uniforms: { ...shared, uBase: color(base) }, vertexShader: VERTEX, fragmentShader: FRAGMENT, defines: pattern ? { [pattern]: "" } : {} });
366
373
  materials.push(material);
374
+ if (base === FUR) furs.push(material);
367
375
  return material;
368
376
  };
369
377
  const outline = new THREE.ShaderMaterial({ uniforms: { uWidth: { value: 0.0042 }, uInk: shared.uInk }, vertexShader: OUTLINE_VERTEX, fragmentShader: OUTLINE_FRAGMENT, side: THREE.BackSide });
@@ -611,6 +619,11 @@ export function createCat(): Cat {
611
619
  setRim(next) {
612
620
  shared.uRim.value.copy(next);
613
621
  },
622
+ setCoat(coat) {
623
+ const { fur, stripe } = COATS[coat];
624
+ for (const material of furs) (material.uniforms.uBase!.value as THREE.Color).set(fur);
625
+ shared.uStripe.value.set(stripe);
626
+ },
614
627
  animate(seconds, beat, energy = 0.6) {
615
628
  clock += seconds;
616
629
  const e = energy, t = target, swing = Math.sin(Math.PI * beat), dip = 0.5 + 0.5 * Math.cos(2 * Math.PI * beat);