@vibechain/os 0.4.1 → 0.5.1
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 +80 -48
- package/README.md +143 -55
- package/SECURITY.md +47 -20
- package/dist/app-client.d.ts +4 -1
- package/dist/app-client.js +15 -4
- package/dist/app-host.d.ts +124 -9
- package/dist/app-host.js +395 -57
- package/dist/app-protocol.d.ts +17 -1
- package/dist/app-protocol.js +12 -0
- package/dist/app-runtime.d.ts +18 -2
- package/dist/app-runtime.js +75 -11
- package/dist/app-wire.d.ts +215 -0
- package/dist/app-wire.js +268 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +3 -0
- package/dist/bundle.js +6 -6
- package/dist/canvas.d.ts +2 -2
- package/dist/canvas.js +3 -1
- package/dist/capture.d.ts +22 -0
- package/dist/capture.js +99 -0
- package/dist/check.d.ts +12 -0
- package/dist/check.js +167 -0
- package/dist/cli-publish.d.ts +24 -0
- package/dist/cli-publish.js +288 -0
- package/dist/cli-session.d.ts +108 -0
- package/dist/cli-session.js +245 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +46 -10
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/links.d.ts +15 -0
- package/dist/links.js +41 -0
- package/dist/listing.d.ts +3 -3
- package/dist/listing.js +1 -1
- package/dist/loop.d.ts +18 -2
- package/dist/loop.js +13 -1
- package/dist/manifest.d.ts +90 -4
- package/dist/manifest.js +340 -5
- package/dist/os.d.ts +63 -0
- package/dist/os.js +383 -0
- package/dist/preview-parent.d.ts +42 -0
- package/dist/preview-parent.js +134 -11
- package/dist/preview-ui.js +1 -1
- package/dist/preview.js +25 -7
- package/dist/redact.d.ts +6 -0
- package/dist/redact.js +16 -0
- package/dist/runtime-policy.d.ts +20 -0
- package/dist/runtime-policy.js +45 -0
- package/dist/scaffold.d.ts +13 -2
- package/dist/scaffold.js +95 -31
- package/dist/submit-notice.d.ts +26 -0
- package/dist/submit-notice.js +34 -0
- package/dist/templates/plain/game.js +18 -0
- package/dist/testing.d.ts +68 -0
- package/dist/testing.js +181 -1
- package/dist/transport.d.ts +22 -0
- package/dist/transport.js +71 -19
- package/dist/vibemarket-os.js +1 -0
- package/dist/worker.d.ts +18 -0
- package/dist/worker.js +34 -0
- package/examples/paw-beat/README.md +20 -8
- package/examples/paw-beat/cat.ts +665 -89
- package/examples/paw-beat/game.ts +162 -28
- package/examples/paw-beat/index.html +114 -40
- package/examples/paw-beat/main.ts +264 -149
- package/examples/paw-beat/music.ts +314 -65
- package/examples/paw-beat/stage.ts +560 -0
- package/examples/paw-beat/store/icon.png +0 -0
- package/examples/paw-beat/store/screenshot-1.webp +0 -0
- package/examples/paw-beat/store/screenshot-2.webp +0 -0
- package/examples/paw-beat/vibemarket.json +2 -2
- package/examples/vibexp-app/README.md +7 -7
- package/examples/vibexp-app/index.html +3 -2
- package/examples/vibexp-app/plain/game.ts +20 -0
- package/examples/vibexp-app/plain/index.html +6 -0
- package/examples/vibexp-app/plain/vibemarket.json +17 -0
- package/examples/vibexp-app/src/main.ts +46 -31
- package/examples/vibexp-app/store/icon.png +0 -0
- package/examples/vibexp-app/three/README.md +21 -0
- package/examples/vibexp-app/three/index.html +4 -0
- package/examples/vibexp-app/three/src/main.ts +45 -0
- package/examples/vibexp-app/three/vibemarket.json +19 -0
- package/examples/vibexp-app/vibemarket.json +17 -11
- package/package.json +6 -2
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { LANES, type Judgement, type Lane, type Note, type SectionName } from "./game";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The stage around Biscuit: a tiled dance floor and a backdrop that pulse with the beat, two
|
|
6
|
+
* sweeping spotlights, the four lanes with their targets, the notes, and the bursts and confetti.
|
|
7
|
+
*
|
|
8
|
+
* Everything that moves every frame is cheap: the floor, backdrop and lights are single meshes
|
|
9
|
+
* whose shaders read a few uniforms (the beat, the section's colours), the notes are one
|
|
10
|
+
* instanced mesh, and the sparks are one point cloud with a fixed pool. Nothing is allocated
|
|
11
|
+
* per frame and there are no shadow maps; the cat's shadow is a soft painted disc.
|
|
12
|
+
*/
|
|
13
|
+
export const LANE_X: Readonly<Record<Lane, number>> = { left: -2.95, down: -1.65, up: 1.65, right: 2.95 };
|
|
14
|
+
export const LANE_COLOR: Readonly<Record<Lane, string>> = { left: "#ff5c8a", down: "#4cc9f0", up: "#ffd166", right: "#7bd88f" };
|
|
15
|
+
/** Where the targets sit, how fast notes travel toward them and how far ahead they appear. */
|
|
16
|
+
export const HIT_Z = 1.7, SPEED = 7, LOOKAHEAD = 2.4;
|
|
17
|
+
/** Height of a note's centre above the floor. Notes and targets lean back toward the camera. */
|
|
18
|
+
const NOTE_Y = 0.42, TILT = 0.8;
|
|
19
|
+
/** In-plane turn of the arrow (which points up when unturned) for each lane. */
|
|
20
|
+
const LANE_TURN: Readonly<Record<Lane, number>> = { up: 0, left: Math.PI / 2, down: Math.PI, right: -Math.PI / 2 };
|
|
21
|
+
|
|
22
|
+
/** Each section's two stage colours: they fade into one another as the song moves on. */
|
|
23
|
+
const SECTION_COLORS: Readonly<Record<SectionName, readonly [string, string]>> = {
|
|
24
|
+
"count-in": ["#7b5cff", "#3fa9d6"], intro: ["#7b5cff", "#3fa9d6"], build: ["#ff5c8a", "#7b5cff"],
|
|
25
|
+
drop: ["#ff9f43", "#ff5c8a"], breakdown: ["#3fc6e8", "#6fd39a"], finale: ["#ffd166", "#ff5c8a"], outro: ["#b28dff", "#ffd166"],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type Framing = "title" | "play";
|
|
29
|
+
export interface StageFrame {
|
|
30
|
+
/** Song position in beats (it keeps counting on the title screen, slowly, so the stage breathes). */
|
|
31
|
+
beat: number;
|
|
32
|
+
section: SectionName;
|
|
33
|
+
/** 0 to 1: how much the stage moves. */
|
|
34
|
+
energy: number;
|
|
35
|
+
reducedMotion: boolean;
|
|
36
|
+
/** The cat's head in world space, for its shadow and the spotlights. */
|
|
37
|
+
catHead: THREE.Vector3;
|
|
38
|
+
/** How far the cat is off the floor. */
|
|
39
|
+
catLift: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface Stage {
|
|
43
|
+
readonly scene: THREE.Scene;
|
|
44
|
+
readonly camera: THREE.PerspectiveCamera;
|
|
45
|
+
/** The view size in CSS pixels, and how much of its bottom the touch pads cover while playing. */
|
|
46
|
+
resize(width: number, height: number, bottomInset: number): void;
|
|
47
|
+
/** Move the camera to a framing, gliding unless `cut`. */
|
|
48
|
+
frame(framing: Framing, cut: boolean): void;
|
|
49
|
+
/** Draw the notes visible at song time `now`. */
|
|
50
|
+
notes(now: number, each: (from: number, to: number, visit: (note: Note, judged: Judgement | null) => void) => void): void;
|
|
51
|
+
hideNotes(): void;
|
|
52
|
+
press(lane: Lane): void;
|
|
53
|
+
hit(lane: Lane, judgement: Judgement): void;
|
|
54
|
+
miss(lane: Lane): void;
|
|
55
|
+
confetti(): void;
|
|
56
|
+
/** Screen position (CSS pixels) of a world point. */
|
|
57
|
+
project(point: THREE.Vector3, out: THREE.Vector2): THREE.Vector2;
|
|
58
|
+
update(seconds: number, frame: StageFrame): void;
|
|
59
|
+
/** The stage's current main colour, for the cat's rim light. */
|
|
60
|
+
readonly accent: THREE.Color;
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const FLOOR_VERTEX = /* glsl */ `
|
|
65
|
+
varying vec3 vWorld;
|
|
66
|
+
void main() {
|
|
67
|
+
vec4 world = modelMatrix * vec4(position, 1.0);
|
|
68
|
+
vWorld = world.xyz;
|
|
69
|
+
gl_Position = projectionMatrix * viewMatrix * world;
|
|
70
|
+
}`;
|
|
71
|
+
|
|
72
|
+
// Square tiles with dark grout. A ring of light leaves the cat on every beat and travels out;
|
|
73
|
+
// tiles are tinted by the two section colours in a checker, and fade toward the horizon.
|
|
74
|
+
const FLOOR_FRAGMENT = /* glsl */ `
|
|
75
|
+
uniform float uBeat;
|
|
76
|
+
uniform float uEnergy;
|
|
77
|
+
uniform float uCalm;
|
|
78
|
+
uniform vec3 uA;
|
|
79
|
+
uniform vec3 uB;
|
|
80
|
+
uniform vec3 uBase;
|
|
81
|
+
uniform vec3 uHorizon;
|
|
82
|
+
uniform vec3 uCat;
|
|
83
|
+
varying vec3 vWorld;
|
|
84
|
+
void main() {
|
|
85
|
+
vec2 p = vWorld.xz;
|
|
86
|
+
vec2 cell = floor(p / 0.9 + 0.5), local = p / 0.9 + 0.5 - cell - 0.5;
|
|
87
|
+
float edge = max(abs(local.x), abs(local.y));
|
|
88
|
+
float tile = 1.0 - smoothstep(0.40, 0.44, edge);
|
|
89
|
+
float distanceFromCat = length(cell * 0.9 - uCat.xz);
|
|
90
|
+
float wave = exp(-pow(distanceFromCat - fract(uBeat) * 7.0, 2.0) * 0.9) * (1.0 - fract(uBeat)) * uEnergy;
|
|
91
|
+
float bar = pow(1.0 - fract(uBeat / 4.0), 6.0) * uEnergy * (1.0 - uCalm);
|
|
92
|
+
vec3 tint = mod(cell.x + cell.y, 2.0) < 1.0 ? uA : uB;
|
|
93
|
+
// Levels are in linear light, so small numbers already read clearly once converted for the screen.
|
|
94
|
+
float lightLevel = 0.014 + 0.6 * wave * (1.0 - 0.6 * uCalm) + 0.05 * bar;
|
|
95
|
+
vec3 color = mix(uBase, tint * 0.9, lightLevel * tile);
|
|
96
|
+
// A pool of light around the cat, and its soft shadow, smaller when it is in the air.
|
|
97
|
+
float pool = exp(-dot(p - uCat.xz, p - uCat.xz) * 0.35);
|
|
98
|
+
color += uA * pool * 0.1;
|
|
99
|
+
float lift = clamp(uCat.y * 1.4, 0.0, 0.8);
|
|
100
|
+
float shadow = smoothstep(0.8 - lift * 0.3, 0.0, length((p - uCat.xz) / vec2(1.0, 0.75)));
|
|
101
|
+
color *= 1.0 - 0.55 * shadow * (1.0 - lift * 0.6);
|
|
102
|
+
float far = smoothstep(1.0, -18.0, vWorld.z);
|
|
103
|
+
gl_FragColor = vec4(mix(color, uHorizon, 1.0 - far), 1.0);
|
|
104
|
+
#include <colorspace_fragment>
|
|
105
|
+
}`;
|
|
106
|
+
|
|
107
|
+
const BACKDROP_VERTEX = /* glsl */ `
|
|
108
|
+
varying vec2 vPlane;
|
|
109
|
+
void main() {
|
|
110
|
+
vPlane = position.xy;
|
|
111
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
112
|
+
}`;
|
|
113
|
+
|
|
114
|
+
// A night-sky gradient, a glow behind the cat, rings of sound that ripple out on each beat and a
|
|
115
|
+
// few slow-twinkling stars. The rings ease in and out, so nothing flashes.
|
|
116
|
+
const BACKDROP_FRAGMENT = /* glsl */ `
|
|
117
|
+
uniform float uBeat;
|
|
118
|
+
uniform float uEnergy;
|
|
119
|
+
uniform float uTime;
|
|
120
|
+
uniform vec3 uA;
|
|
121
|
+
uniform vec3 uB;
|
|
122
|
+
uniform vec3 uTop;
|
|
123
|
+
uniform vec3 uHorizon;
|
|
124
|
+
uniform vec2 uCentre;
|
|
125
|
+
varying vec2 vPlane;
|
|
126
|
+
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
|
|
127
|
+
void main() {
|
|
128
|
+
vec2 p = vPlane;
|
|
129
|
+
vec3 color = mix(uHorizon, uTop, smoothstep(-2.0, 16.0, p.y));
|
|
130
|
+
float r = length(p - uCentre);
|
|
131
|
+
color += uA * exp(-r * 0.22) * 0.35;
|
|
132
|
+
float rings = 0.0;
|
|
133
|
+
for (int i = 0; i < 4; i++) {
|
|
134
|
+
float radius = (fract(uBeat) + float(i)) * 3.2 + 1.5;
|
|
135
|
+
rings += smoothstep(0.35, 0.0, abs(r - radius)) * (1.0 - (fract(uBeat) + float(i)) / 4.0);
|
|
136
|
+
}
|
|
137
|
+
color += mix(uB, uA, 0.4) * rings * 0.16 * uEnergy;
|
|
138
|
+
vec2 cell = floor(p * 1.2);
|
|
139
|
+
float star = step(0.985, hash(cell)) * smoothstep(0.12, 0.0, length(fract(p * 1.2) - 0.5));
|
|
140
|
+
color += vec3(1.0) * star * (0.35 + 0.25 * sin(uTime * 1.3 + hash(cell + 7.0) * 6.28)) * smoothstep(2.0, 6.0, p.y);
|
|
141
|
+
gl_FragColor = vec4(color, 1.0);
|
|
142
|
+
#include <colorspace_fragment>
|
|
143
|
+
}`;
|
|
144
|
+
|
|
145
|
+
const BEAM_VERTEX = /* glsl */ `
|
|
146
|
+
varying float vAlong;
|
|
147
|
+
varying float vEdge;
|
|
148
|
+
void main() {
|
|
149
|
+
vAlong = uv.y;
|
|
150
|
+
vec4 view = modelViewMatrix * vec4(position, 1.0);
|
|
151
|
+
vEdge = abs(dot(normalize(normalMatrix * normal), normalize(-view.xyz)));
|
|
152
|
+
gl_Position = projectionMatrix * view;
|
|
153
|
+
}`;
|
|
154
|
+
// A cone of light, brightest at its source and soft at its edges; drawn additively.
|
|
155
|
+
const BEAM_FRAGMENT = /* glsl */ `
|
|
156
|
+
uniform vec3 uColor;
|
|
157
|
+
uniform float uStrength;
|
|
158
|
+
varying float vAlong;
|
|
159
|
+
varying float vEdge;
|
|
160
|
+
void main() {
|
|
161
|
+
float alpha = pow(vAlong, 3.0) * pow(vEdge, 2.0) * uStrength;
|
|
162
|
+
gl_FragColor = vec4(uColor * alpha, 1.0);
|
|
163
|
+
#include <colorspace_fragment>
|
|
164
|
+
}`;
|
|
165
|
+
|
|
166
|
+
const LANE_FRAGMENT = /* glsl */ `
|
|
167
|
+
uniform vec3 uColor;
|
|
168
|
+
uniform float uGlow;
|
|
169
|
+
varying vec2 vUv;
|
|
170
|
+
void main() {
|
|
171
|
+
// Brightest near the target, fading into the distance; a little brighter at the edges.
|
|
172
|
+
float edge = smoothstep(0.38, 0.5, abs(vUv.x - 0.5));
|
|
173
|
+
float alpha = (0.1 + 0.16 * edge + uGlow * 0.4) * smoothstep(0.0, 0.7, vUv.y) * smoothstep(1.0, 0.94, vUv.y);
|
|
174
|
+
gl_FragColor = vec4(uColor, alpha);
|
|
175
|
+
#include <colorspace_fragment>
|
|
176
|
+
}`;
|
|
177
|
+
const LANE_VERTEX = /* glsl */ `
|
|
178
|
+
varying vec2 vUv;
|
|
179
|
+
void main() {
|
|
180
|
+
vUv = uv;
|
|
181
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
182
|
+
}`;
|
|
183
|
+
|
|
184
|
+
const SPARK_VERTEX = /* glsl */ `
|
|
185
|
+
attribute float aSize;
|
|
186
|
+
attribute float aAlpha;
|
|
187
|
+
attribute vec3 aColor;
|
|
188
|
+
uniform float uScale;
|
|
189
|
+
varying float vAlpha;
|
|
190
|
+
varying vec3 vColor;
|
|
191
|
+
void main() {
|
|
192
|
+
vAlpha = aAlpha;
|
|
193
|
+
vColor = aColor;
|
|
194
|
+
vec4 view = modelViewMatrix * vec4(position, 1.0);
|
|
195
|
+
gl_PointSize = aSize * uScale / -view.z;
|
|
196
|
+
gl_Position = projectionMatrix * view;
|
|
197
|
+
}`;
|
|
198
|
+
const SPARK_FRAGMENT = /* glsl */ `
|
|
199
|
+
varying float vAlpha;
|
|
200
|
+
varying vec3 vColor;
|
|
201
|
+
void main() {
|
|
202
|
+
float d = length(gl_PointCoord - 0.5);
|
|
203
|
+
gl_FragColor = vec4(vColor, vAlpha * smoothstep(0.5, 0.3, d));
|
|
204
|
+
#include <colorspace_fragment>
|
|
205
|
+
}`;
|
|
206
|
+
|
|
207
|
+
/** The arrow outline every note and target uses, pointing up, about one unit tall. */
|
|
208
|
+
function arrowShape(scale: number): THREE.Shape {
|
|
209
|
+
const shape = new THREE.Shape(), points = [[0, 0.56], [0.52, 0.04], [0.21, 0.04], [0.21, -0.5], [-0.21, -0.5], [-0.21, 0.04], [-0.52, 0.04]] as const;
|
|
210
|
+
points.forEach(([x, y], index) => (index === 0 ? shape.moveTo(x * scale, y * scale) : shape.lineTo(x * scale, y * scale)));
|
|
211
|
+
shape.closePath();
|
|
212
|
+
return shape;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* A note: a bevelled arrow with lit faces and darker sides, on a dark outline. Built as one
|
|
217
|
+
* geometry with vertex colours so the instanced mesh tints it per lane in a single draw call.
|
|
218
|
+
*/
|
|
219
|
+
function noteGeometry(): THREE.BufferGeometry {
|
|
220
|
+
const body = new THREE.ExtrudeGeometry(arrowShape(0.86), { depth: 0.06, bevelEnabled: true, bevelThickness: 0.05, bevelSize: 0.05, bevelSegments: 2 });
|
|
221
|
+
const rim = new THREE.ShapeGeometry(arrowShape(1.08)).toNonIndexed();
|
|
222
|
+
rim.translate(0, -0.012, -0.06);
|
|
223
|
+
const bodyPositions = body.getAttribute("position"), bodyNormals = body.getAttribute("normal"), rimPositions = rim.getAttribute("position");
|
|
224
|
+
const count = bodyPositions.count + rimPositions.count;
|
|
225
|
+
const positions = new Float32Array(count * 3), colors = new Float32Array(count * 3);
|
|
226
|
+
for (let i = 0; i < bodyPositions.count; i++) {
|
|
227
|
+
positions.set([bodyPositions.getX(i), bodyPositions.getY(i), bodyPositions.getZ(i)], i * 3);
|
|
228
|
+
// Front faces full colour, a sheen toward the tip; bevels and sides darker, so the arrow reads as solid.
|
|
229
|
+
const front = bodyNormals.getZ(i) > 0.7, shade = front ? 0.86 + 0.14 * (bodyPositions.getY(i) + 0.5) : 0.5 + 0.2 * Math.max(0, bodyNormals.getY(i));
|
|
230
|
+
colors.set([shade, shade, shade], i * 3);
|
|
231
|
+
}
|
|
232
|
+
for (let i = 0; i < rimPositions.count; i++) {
|
|
233
|
+
positions.set([rimPositions.getX(i), rimPositions.getY(i), rimPositions.getZ(i)], (bodyPositions.count + i) * 3);
|
|
234
|
+
colors.set([0.16, 0.12, 0.2], (bodyPositions.count + i) * 3);
|
|
235
|
+
}
|
|
236
|
+
body.dispose();
|
|
237
|
+
rim.dispose();
|
|
238
|
+
const geometry = new THREE.BufferGeometry();
|
|
239
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
240
|
+
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
|
241
|
+
return geometry;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const NOTE_POOL = 40, SPARKS = 320, WHITE = new THREE.Color(1, 1, 1);
|
|
245
|
+
|
|
246
|
+
export function createStage(): Stage {
|
|
247
|
+
const scene = new THREE.Scene(), camera = new THREE.PerspectiveCamera(30, 1, 0.1, 90);
|
|
248
|
+
const disposables: { dispose(): void }[] = [];
|
|
249
|
+
const keep = <T extends { dispose(): void }>(item: T) => (disposables.push(item), item);
|
|
250
|
+
const accent = new THREE.Color(SECTION_COLORS.intro[0]), second = new THREE.Color(SECTION_COLORS.intro[1]);
|
|
251
|
+
const sectionColors = Object.fromEntries(Object.entries(SECTION_COLORS).map(([name, [a, b]]) => [name, [new THREE.Color(a), new THREE.Color(b)]])) as Record<SectionName, [THREE.Color, THREE.Color]>;
|
|
252
|
+
const shared = { uA: { value: accent }, uB: { value: second }, uBeat: { value: 0 }, uEnergy: { value: 0.5 } };
|
|
253
|
+
const horizon = new THREE.Color("#1c1233"), top = new THREE.Color("#07050f");
|
|
254
|
+
|
|
255
|
+
// ---- Floor and backdrop ----
|
|
256
|
+
const floorMaterial = keep(new THREE.ShaderMaterial({
|
|
257
|
+
uniforms: { ...shared, uCalm: { value: 0 }, uBase: { value: new THREE.Color("#140e24") }, uHorizon: { value: horizon }, uCat: { value: new THREE.Vector3() } },
|
|
258
|
+
vertexShader: FLOOR_VERTEX, fragmentShader: FLOOR_FRAGMENT,
|
|
259
|
+
}));
|
|
260
|
+
const floor = new THREE.Mesh(keep(new THREE.PlaneGeometry(60, 34)), floorMaterial);
|
|
261
|
+
floor.rotation.x = -Math.PI / 2;
|
|
262
|
+
floor.position.z = -10;
|
|
263
|
+
scene.add(floor);
|
|
264
|
+
const backdropMaterial = keep(new THREE.ShaderMaterial({
|
|
265
|
+
uniforms: { ...shared, uTime: { value: 0 }, uTop: { value: top }, uHorizon: { value: horizon }, uCentre: { value: new THREE.Vector2(0, 3.5) } },
|
|
266
|
+
vertexShader: BACKDROP_VERTEX, fragmentShader: BACKDROP_FRAGMENT,
|
|
267
|
+
}));
|
|
268
|
+
const backdrop = new THREE.Mesh(keep(new THREE.PlaneGeometry(90, 40)), backdropMaterial);
|
|
269
|
+
backdrop.position.set(0, 18, -26.5);
|
|
270
|
+
scene.add(backdrop);
|
|
271
|
+
|
|
272
|
+
// ---- Spotlights: open cones from high left and right, sweeping the floor behind the cat. They fade
|
|
273
|
+
// out well before the floor, so they never wash over the cat's face. ----
|
|
274
|
+
const beamGeometry = keep(new THREE.CylinderGeometry(0.1, 1.1, 1, 24, 1, true));
|
|
275
|
+
beamGeometry.translate(0, -0.5, 0); // the source at the origin, the cone hanging below it
|
|
276
|
+
const beams = [-1, 1].map(side => {
|
|
277
|
+
const material = keep(new THREE.ShaderMaterial({
|
|
278
|
+
uniforms: { uColor: { value: new THREE.Color() }, uStrength: { value: 0.3 } }, vertexShader: BEAM_VERTEX, fragmentShader: BEAM_FRAGMENT,
|
|
279
|
+
transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide,
|
|
280
|
+
}));
|
|
281
|
+
const mesh = new THREE.Mesh(beamGeometry, material);
|
|
282
|
+
mesh.position.set(side * 5.5, 10, -4);
|
|
283
|
+
mesh.renderOrder = 2;
|
|
284
|
+
scene.add(mesh);
|
|
285
|
+
return { side, mesh, material };
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// ---- Lanes and targets: the playfield, shown only while a song plays ----
|
|
289
|
+
const playfield = new THREE.Group();
|
|
290
|
+
scene.add(playfield);
|
|
291
|
+
const laneGeometry = keep(new THREE.PlaneGeometry(1.15, 26));
|
|
292
|
+
laneGeometry.rotateX(-Math.PI / 2);
|
|
293
|
+
laneGeometry.translate(0, 0.012, HIT_Z + 0.7 - 13);
|
|
294
|
+
const targetFrame = new THREE.Shape(arrowShape(1.08).getPoints());
|
|
295
|
+
targetFrame.holes.push(new THREE.Path(arrowShape(0.82).getPoints().reverse()));
|
|
296
|
+
const frameGeometry = keep(new THREE.ShapeGeometry(targetFrame)), fillGeometry = keep(new THREE.ShapeGeometry(arrowShape(0.8)));
|
|
297
|
+
const ringGeometry = keep(new THREE.RingGeometry(0.56, 0.63, 40));
|
|
298
|
+
const tilt = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1, 0, 0), -TILT);
|
|
299
|
+
const turn = {} as Record<Lane, THREE.Quaternion>;
|
|
300
|
+
const lanes = {} as Record<Lane, {
|
|
301
|
+
strip: THREE.ShaderMaterial; frame: THREE.Mesh<THREE.ShapeGeometry, THREE.MeshBasicMaterial>; fill: THREE.MeshBasicMaterial;
|
|
302
|
+
ring: THREE.Mesh<THREE.RingGeometry, THREE.MeshBasicMaterial>; glow: number; flash: number; burst: number; burstSize: number; color: THREE.Color;
|
|
303
|
+
}>;
|
|
304
|
+
for (const lane of LANES) {
|
|
305
|
+
const color = new THREE.Color(LANE_COLOR[lane]);
|
|
306
|
+
turn[lane] = tilt.clone().multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), LANE_TURN[lane]));
|
|
307
|
+
const strip = keep(new THREE.ShaderMaterial({
|
|
308
|
+
uniforms: { uColor: { value: color }, uGlow: { value: 0 } }, vertexShader: LANE_VERTEX, fragmentShader: LANE_FRAGMENT, transparent: true, depthWrite: false,
|
|
309
|
+
}));
|
|
310
|
+
const stripMesh = new THREE.Mesh(laneGeometry, strip);
|
|
311
|
+
stripMesh.position.x = LANE_X[lane];
|
|
312
|
+
stripMesh.renderOrder = 1;
|
|
313
|
+
playfield.add(stripMesh);
|
|
314
|
+
const frame = new THREE.Mesh(frameGeometry, keep(new THREE.MeshBasicMaterial({ color })));
|
|
315
|
+
const fill = keep(new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.15, depthWrite: false }));
|
|
316
|
+
const fillMesh = new THREE.Mesh(fillGeometry, fill);
|
|
317
|
+
const ring = new THREE.Mesh(ringGeometry, keep(new THREE.MeshBasicMaterial({ color: "#ffffff", transparent: true, opacity: 0, blending: THREE.AdditiveBlending, depthWrite: false })));
|
|
318
|
+
for (const mesh of [frame, fillMesh, ring]) {
|
|
319
|
+
mesh.position.set(LANE_X[lane], NOTE_Y, HIT_Z);
|
|
320
|
+
mesh.quaternion.copy(turn[lane]);
|
|
321
|
+
playfield.add(mesh);
|
|
322
|
+
}
|
|
323
|
+
fillMesh.position.z -= 0.01;
|
|
324
|
+
ring.visible = false;
|
|
325
|
+
lanes[lane] = { strip, frame, fill, ring, glow: 0, flash: 0, burst: 1, burstSize: 1, color };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ---- Notes: one instanced mesh ----
|
|
329
|
+
const notesMesh = new THREE.InstancedMesh(keep(noteGeometry()), keep(new THREE.MeshBasicMaterial({ vertexColors: true })), NOTE_POOL);
|
|
330
|
+
notesMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
331
|
+
notesMesh.setColorAt(0, accent);
|
|
332
|
+
notesMesh.instanceColor!.setUsage(THREE.DynamicDrawUsage);
|
|
333
|
+
notesMesh.count = 0;
|
|
334
|
+
notesMesh.frustumCulled = false;
|
|
335
|
+
playfield.add(notesMesh);
|
|
336
|
+
const laneColors = Object.fromEntries(LANES.map(lane => [lane, new THREE.Color(LANE_COLOR[lane])])) as Record<Lane, THREE.Color>;
|
|
337
|
+
const missed = new THREE.Color("#5a5068"), tint = new THREE.Color(), matrix = new THREE.Matrix4(), place = new THREE.Vector3(), size = new THREE.Vector3();
|
|
338
|
+
let noteClock = 0, used = 0;
|
|
339
|
+
/** One visitor for every frame (no closure per frame): writes the next instance. */
|
|
340
|
+
const drawNote = (note: Note, judged: Judgement | null) => {
|
|
341
|
+
// A step that was hit disappears; a missed one slides on past the target, greyed out.
|
|
342
|
+
if ((judged && judged !== "miss") || used >= NOTE_POOL) return;
|
|
343
|
+
const ahead = note.time - noteClock, approach = ahead / LOOKAHEAD;
|
|
344
|
+
place.set(LANE_X[note.lane], NOTE_Y, HIT_Z - ahead * SPEED);
|
|
345
|
+
// Notes grow to full size as they arrive and brighten out of the distance.
|
|
346
|
+
size.setScalar(0.82 + 0.18 * Math.min(1, (1 - approach) * 4));
|
|
347
|
+
matrix.compose(place, turn[note.lane], size);
|
|
348
|
+
notesMesh.setMatrixAt(used, matrix);
|
|
349
|
+
tint.copy(judged === "miss" ? missed : laneColors[note.lane]).multiplyScalar(0.35 + 0.65 * Math.min(1, (1 - approach) * 2.2));
|
|
350
|
+
notesMesh.setColorAt(used, tint);
|
|
351
|
+
used++;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// ---- Sparks and confetti: a fixed pool of points ----
|
|
355
|
+
const sparkPositions = new Float32Array(SPARKS * 3), sparkColors = new Float32Array(SPARKS * 3), sparkSizes = new Float32Array(SPARKS), sparkAlpha = new Float32Array(SPARKS);
|
|
356
|
+
const sparkVelocity = new Float32Array(SPARKS * 3), sparkLife = new Float32Array(SPARKS), sparkSpan = new Float32Array(SPARKS).fill(1), sparkGravity = new Float32Array(SPARKS);
|
|
357
|
+
const sparkGeometry = keep(new THREE.BufferGeometry());
|
|
358
|
+
sparkGeometry.setAttribute("position", new THREE.BufferAttribute(sparkPositions, 3).setUsage(THREE.DynamicDrawUsage));
|
|
359
|
+
sparkGeometry.setAttribute("aColor", new THREE.BufferAttribute(sparkColors, 3).setUsage(THREE.DynamicDrawUsage));
|
|
360
|
+
sparkGeometry.setAttribute("aSize", new THREE.BufferAttribute(sparkSizes, 1).setUsage(THREE.DynamicDrawUsage));
|
|
361
|
+
sparkGeometry.setAttribute("aAlpha", new THREE.BufferAttribute(sparkAlpha, 1).setUsage(THREE.DynamicDrawUsage));
|
|
362
|
+
const sparkAttributes = Object.values(sparkGeometry.attributes);
|
|
363
|
+
const sparkMaterial = keep(new THREE.ShaderMaterial({ uniforms: { uScale: { value: 300 } }, vertexShader: SPARK_VERTEX, fragmentShader: SPARK_FRAGMENT, transparent: true, depthWrite: false }));
|
|
364
|
+
const sparks = new THREE.Points(sparkGeometry, sparkMaterial);
|
|
365
|
+
sparks.frustumCulled = false;
|
|
366
|
+
sparks.renderOrder = 3;
|
|
367
|
+
scene.add(sparks);
|
|
368
|
+
let nextSpark = 0, liveSparks = 0;
|
|
369
|
+
const spark = (x: number, y: number, z: number, vx: number, vy: number, vz: number, color: THREE.Color, sizeOf: number, life: number, gravity: number) => {
|
|
370
|
+
const i = nextSpark;
|
|
371
|
+
nextSpark = (nextSpark + 1) % SPARKS;
|
|
372
|
+
const o = i * 3;
|
|
373
|
+
sparkPositions[o] = x; sparkPositions[o + 1] = y; sparkPositions[o + 2] = z;
|
|
374
|
+
sparkVelocity[o] = vx; sparkVelocity[o + 1] = vy; sparkVelocity[o + 2] = vz;
|
|
375
|
+
sparkColors[o] = color.r; sparkColors[o + 1] = color.g; sparkColors[o + 2] = color.b;
|
|
376
|
+
sparkSizes[i] = sizeOf;
|
|
377
|
+
sparkLife[i] = sparkSpan[i] = life;
|
|
378
|
+
sparkGravity[i] = gravity;
|
|
379
|
+
liveSparks = SPARKS;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// ---- Camera framings ----
|
|
383
|
+
let width = 960, height = 600, bottomInset = 0, framing: Framing = "title", blend = 1;
|
|
384
|
+
const from = { position: new THREE.Vector3(), look: new THREE.Vector3() }, to = { position: new THREE.Vector3(), look: new THREE.Vector3() };
|
|
385
|
+
const look = new THREE.Vector3(), probe = new THREE.PerspectiveCamera(), targetRow = new THREE.Vector3();
|
|
386
|
+
/** Where the camera sits for a framing at the current aspect ratio. */
|
|
387
|
+
const pose = (which: Framing, out: { position: THREE.Vector3; look: THREE.Vector3 }) => {
|
|
388
|
+
const aspect = width / height, halfFov = THREE.MathUtils.degToRad(camera.fov / 2);
|
|
389
|
+
if (which === "play") {
|
|
390
|
+
// Keep the outer lanes (and a margin) in frame on narrow windows by pulling back.
|
|
391
|
+
const fitWidth = 4.05 / (Math.tan(halfFov) * aspect), distance = Math.max(13.2, fitWidth + 1.7);
|
|
392
|
+
out.look.set(0, 1.15, -0.4);
|
|
393
|
+
out.position.set(0, 1.15 + distance * 0.6, -0.4 + distance * 0.8);
|
|
394
|
+
// Then slide the view along the lanes until the bottom of the target row sits just above the
|
|
395
|
+
// pads: on tall or small windows that uses the space instead of leaving a gap or hiding the targets.
|
|
396
|
+
probe.copy(camera);
|
|
397
|
+
probe.updateProjectionMatrix();
|
|
398
|
+
const goal = 1 - (2 * (bottomInset + Math.max(6, height * 0.02))) / height;
|
|
399
|
+
for (let step = 0; step < 6; step++) {
|
|
400
|
+
probe.position.copy(out.position);
|
|
401
|
+
probe.lookAt(out.look);
|
|
402
|
+
probe.updateMatrixWorld();
|
|
403
|
+
const below = targetRow.set(0, 0, HIT_Z + 0.35).project(probe).y + goal;
|
|
404
|
+
const slide = THREE.MathUtils.clamp(below * distance * Math.tan(halfFov) * 1.1, -2, 2);
|
|
405
|
+
out.look.z -= slide;
|
|
406
|
+
out.position.z -= slide;
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
// Title and results: closer on the cat. On wide windows the cat stands right of centre to leave room for the card.
|
|
410
|
+
const wide = aspect > 1.15, distance = wide ? 8.8 : Math.max(8.8, 2.6 / (Math.tan(halfFov) * aspect) + 2.5);
|
|
411
|
+
const shift = wide ? -Math.min(2.2, (aspect - 1) * 1.6) : 0;
|
|
412
|
+
out.look.set(shift, wide ? 1.35 : 0.85, 0);
|
|
413
|
+
out.position.set(shift, 1.35 + distance * 0.22, distance);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const applyCamera = () => {
|
|
417
|
+
const t = blend * blend * (3 - 2 * blend);
|
|
418
|
+
camera.position.lerpVectors(from.position, to.position, t);
|
|
419
|
+
look.lerpVectors(from.look, to.look, t);
|
|
420
|
+
camera.lookAt(look);
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
let clock = 0;
|
|
424
|
+
return {
|
|
425
|
+
scene,
|
|
426
|
+
camera,
|
|
427
|
+
accent,
|
|
428
|
+
resize(nextWidth, nextHeight, nextInset) {
|
|
429
|
+
width = nextWidth;
|
|
430
|
+
height = nextHeight;
|
|
431
|
+
bottomInset = nextInset;
|
|
432
|
+
camera.aspect = width / height;
|
|
433
|
+
camera.updateProjectionMatrix();
|
|
434
|
+
sparkMaterial.uniforms.uScale!.value = height / (2 * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)));
|
|
435
|
+
// A resize lands on the new framing at once rather than gliding.
|
|
436
|
+
pose(framing, to);
|
|
437
|
+
blend = 1;
|
|
438
|
+
applyCamera();
|
|
439
|
+
},
|
|
440
|
+
frame(next, cut) {
|
|
441
|
+
from.position.copy(camera.position);
|
|
442
|
+
from.look.copy(look);
|
|
443
|
+
framing = next;
|
|
444
|
+
playfield.visible = next === "play";
|
|
445
|
+
pose(next, to);
|
|
446
|
+
blend = cut ? 1 : 0;
|
|
447
|
+
applyCamera();
|
|
448
|
+
},
|
|
449
|
+
notes(now, each) {
|
|
450
|
+
noteClock = now;
|
|
451
|
+
used = 0;
|
|
452
|
+
each(now - 0.5, now + LOOKAHEAD, drawNote);
|
|
453
|
+
notesMesh.count = used;
|
|
454
|
+
notesMesh.instanceMatrix.needsUpdate = true;
|
|
455
|
+
notesMesh.instanceColor!.needsUpdate = true;
|
|
456
|
+
},
|
|
457
|
+
hideNotes() {
|
|
458
|
+
notesMesh.count = 0;
|
|
459
|
+
},
|
|
460
|
+
press(lane) {
|
|
461
|
+
lanes[lane].glow = 1;
|
|
462
|
+
lanes[lane].flash = Math.max(lanes[lane].flash, 0.45);
|
|
463
|
+
},
|
|
464
|
+
hit(lane, judgement) {
|
|
465
|
+
const target = lanes[lane], strength = judgement === "perfect" ? 1 : judgement === "great" ? 0.7 : 0.45;
|
|
466
|
+
target.flash = 1;
|
|
467
|
+
target.burst = 0;
|
|
468
|
+
target.burstSize = 0.3 + strength * 0.5;
|
|
469
|
+
target.ring.material.color.copy(target.color).lerp(WHITE, 0.5 * strength);
|
|
470
|
+
const count = judgement === "perfect" ? 16 : judgement === "great" ? 9 : 4;
|
|
471
|
+
for (let i = 0; i < count; i++) {
|
|
472
|
+
const angle = (i / count) * Math.PI * 2 + Math.random() * 0.4, speed = 1.6 + Math.random() * 1.8 * strength;
|
|
473
|
+
spark(LANE_X[lane], NOTE_Y + 0.1, HIT_Z, Math.cos(angle) * speed, 1.2 + Math.sin(angle) * speed, -0.3, target.color, 0.1 + 0.08 * strength, 0.45, 5);
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
miss(lane) {
|
|
477
|
+
lanes[lane].flash = 0;
|
|
478
|
+
lanes[lane].glow = 0.3;
|
|
479
|
+
},
|
|
480
|
+
confetti() {
|
|
481
|
+
for (let i = 0; i < 90; i++) {
|
|
482
|
+
const lane = LANES[i % 4]!, angle = Math.random() * Math.PI * 2, speed = 1 + Math.random() * 2.5;
|
|
483
|
+
spark(Math.cos(angle) * 0.3, 3.2, 0.3 + Math.sin(angle) * 0.3, Math.cos(angle) * speed, 2.5 + Math.random() * 2.5, Math.sin(angle) * speed * 0.6, laneColors[lane], 0.12, 1.6 + Math.random() * 0.6, 4);
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
project(point, out) {
|
|
487
|
+
place.copy(point).project(camera);
|
|
488
|
+
return out.set((place.x * 0.5 + 0.5) * width, (0.5 - place.y * 0.5) * height);
|
|
489
|
+
},
|
|
490
|
+
update(seconds, frame) {
|
|
491
|
+
clock += seconds;
|
|
492
|
+
if (blend < 1) {
|
|
493
|
+
blend = Math.min(1, blend + seconds / (frame.reducedMotion ? 0.001 : 0.9));
|
|
494
|
+
applyCamera();
|
|
495
|
+
}
|
|
496
|
+
// Colours glide toward the section's pair over about half a second.
|
|
497
|
+
const [a, b] = sectionColors[frame.section];
|
|
498
|
+
accent.lerp(a, Math.min(1, seconds * 2.5));
|
|
499
|
+
second.lerp(b, Math.min(1, seconds * 2.5));
|
|
500
|
+
shared.uBeat.value = frame.beat;
|
|
501
|
+
shared.uEnergy.value = frame.energy;
|
|
502
|
+
floorMaterial.uniforms.uCalm!.value = frame.reducedMotion ? 1 : 0;
|
|
503
|
+
(floorMaterial.uniforms.uCat!.value as THREE.Vector3).set(frame.catHead.x, frame.catLift, 0);
|
|
504
|
+
backdropMaterial.uniforms.uTime!.value = clock;
|
|
505
|
+
(backdropMaterial.uniforms.uCentre!.value as THREE.Vector2).set(frame.catHead.x, frame.catHead.y + 1.8);
|
|
506
|
+
|
|
507
|
+
// Spotlights sweep slowly across the cat, once every two bars (held still for reduced motion).
|
|
508
|
+
const sweep = frame.reducedMotion ? 0 : Math.sin((frame.beat / 8) * Math.PI * 2);
|
|
509
|
+
for (const beam of beams) {
|
|
510
|
+
const aimX = beam.side * 1.2 + sweep * 2.2, aimY = 0, aimZ = -3.5;
|
|
511
|
+
const dx = aimX - beam.mesh.position.x, dy = aimY - beam.mesh.position.y, dz = aimZ - beam.mesh.position.z, length = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
512
|
+
beam.mesh.scale.set(1, length, 1);
|
|
513
|
+
beam.mesh.quaternion.setFromUnitVectors(place.set(0, -1, 0), size.set(dx / length, dy / length, dz / length));
|
|
514
|
+
beam.material.uniforms.uColor!.value.copy(beam.side < 0 ? accent : second);
|
|
515
|
+
beam.material.uniforms.uStrength!.value = 0.1 + 0.06 * frame.energy * (0.5 + 0.5 * Math.cos(frame.beat * Math.PI * 2));
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Targets breathe on the beat, light up when pressed and burst when hit.
|
|
519
|
+
const pulse = Math.pow(0.5 + 0.5 * Math.cos(frame.beat * Math.PI * 2), 3) * frame.energy;
|
|
520
|
+
for (const lane of LANES) {
|
|
521
|
+
const target = lanes[lane];
|
|
522
|
+
target.glow = Math.max(0, target.glow - seconds * 4);
|
|
523
|
+
target.flash = Math.max(0, target.flash - seconds * 3.5);
|
|
524
|
+
target.strip.uniforms.uGlow!.value = target.glow;
|
|
525
|
+
target.fill.opacity = 0.12 + 0.12 * pulse + 0.75 * target.flash;
|
|
526
|
+
target.frame.scale.setScalar(1 + 0.06 * pulse + 0.08 * target.flash);
|
|
527
|
+
target.frame.material.color.copy(target.color).multiplyScalar(0.75 + 0.25 * pulse + 0.5 * target.flash);
|
|
528
|
+
if (target.burst < 1) {
|
|
529
|
+
target.burst = Math.min(1, target.burst + seconds / 0.35);
|
|
530
|
+
target.ring.visible = target.burst < 1;
|
|
531
|
+
target.ring.scale.setScalar(1 + target.burst * target.burstSize);
|
|
532
|
+
target.ring.material.opacity = (1 - target.burst) * 0.7;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (liveSparks > 0) {
|
|
537
|
+
let alive = 0;
|
|
538
|
+
for (let i = 0; i < SPARKS; i++) {
|
|
539
|
+
if (sparkLife[i]! <= 0) { sparkAlpha[i] = 0; continue; }
|
|
540
|
+
alive++;
|
|
541
|
+
sparkLife[i] = sparkLife[i]! - seconds;
|
|
542
|
+
const o = i * 3;
|
|
543
|
+
sparkVelocity[o + 1] = sparkVelocity[o + 1]! - sparkGravity[i]! * seconds;
|
|
544
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
545
|
+
sparkVelocity[o + axis] = sparkVelocity[o + axis]! * (1 - seconds * 1.2);
|
|
546
|
+
sparkPositions[o + axis] = sparkPositions[o + axis]! + sparkVelocity[o + axis]! * seconds;
|
|
547
|
+
}
|
|
548
|
+
if (sparkPositions[o + 1]! < 0.02) { sparkPositions[o + 1] = 0.02; sparkVelocity[o + 1] = 0; }
|
|
549
|
+
sparkAlpha[i] = Math.min(1, (sparkLife[i]! / sparkSpan[i]!) * 2.5);
|
|
550
|
+
}
|
|
551
|
+
liveSparks = alive;
|
|
552
|
+
for (const attribute of sparkAttributes) attribute.needsUpdate = true;
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
dispose() {
|
|
556
|
+
for (const item of disposables) item.dispose();
|
|
557
|
+
notesMesh.dispose();
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"sdkVersion": 1,
|
|
4
4
|
"id": "paw-beat",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"name": "Paw Beat",
|
|
7
7
|
"tagline": "A 3D cat, four arrows and a beat. Hit the steps, keep the combo.",
|
|
8
8
|
"category": "vibexp-app",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"store": {
|
|
14
14
|
"icon": "store/icon.png",
|
|
15
15
|
"screenshots": ["store/screenshot-1.webp", "store/screenshot-2.webp"],
|
|
16
|
-
"description": "Biscuit the cat dances to a one-minute song made entirely in code. Arrows slide down four lanes toward their
|
|
16
|
+
"description": "Biscuit the cat dances to a one-minute song made entirely in code. Arrows slide down four lanes toward their outlines: press the matching arrow key or WASD, or tap the on-screen pads, as each one lands, and Biscuit dances the step (a side step, a leap or a squat) while the stage pulses with the music.\n\nTiming is judged perfect, great or good, and every ten steps in a row adds 10% to each step, up to double. Long combos earn a spin and confetti; a miss makes Biscuit stumble. The song builds, drops, breaks down and comes back for a finale, and the steps follow it, changing a little every round. Each round ends with a grade, your accuracy and every judgement. Your best score and sound setting are kept while the window stays open.",
|
|
17
17
|
"category": "game",
|
|
18
18
|
"rating": { "violence": "none", "language": "none", "mature": false },
|
|
19
19
|
"support": "https://vibechain.com/os/docs"
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Stamp Club
|
|
2
2
|
|
|
3
|
-
Stamp Club is a small VibeMarket OS app built with TypeScript, and the starting point `os init` gives you. Use it to try your own intro,
|
|
3
|
+
Stamp Club is a small VibeMarket OS app built with TypeScript and a 2D canvas, and the starting point `os init` gives you (`os init --template plain` and `--template three` give the other two). Use it to try your own intro, a saved best, window lifecycle events and a host-owned final score screen, then replace the stamp board with your own idea.
|
|
4
4
|
|
|
5
|
-
Run `npm install`, `npm run build`, then `npm run dev`. Open the printed **127.0.0.1** URL. Start a round,
|
|
5
|
+
Run `npm install`, `npm run build`, then `npm run dev`. Open the printed **127.0.0.1** URL. Start a round, press the board to place stamps and finish the round to see the reported score; a new best is saved with `os.save` and read back with `os.load` the next time the app opens. Rebuild and restart the preview after source changes. `npm run check` (`os check`) lists every problem with the manifest and the build before you submit.
|
|
6
6
|
|
|
7
|
-
The app API
|
|
7
|
+
The app API is `connect()`: `ready()`, `load()` and `save()` (one JSON save of up to 1 MiB per player), pause, resume and resize listeners and `finish({ score })`, plus cards, packs and a player token for apps that declare them in `vibemarket.json`. Your app owns its intro and loading UI; the host owns final results. The preview awards no Cash. Put images, audio and other files in a `public/` folder: `os assets` copies it into `dist/`. See the SDK security documentation before accepting untrusted code.
|
|
8
8
|
|
|
9
9
|
## Before you submit to VibeStore
|
|
10
10
|
|
|
11
|
-
`vibemarket.json` is already a complete VibeStore listing (manifest schema version
|
|
11
|
+
`vibemarket.json` is already a complete VibeStore listing (manifest schema version 3), so `npm run build` and `npm run pack` produce an `app.zip` that passes the submission checks. Its listing is placeholder text and pictures of this starter, though, and **a submission of the unchanged starter will be rejected at review.** Change these first:
|
|
12
12
|
|
|
13
13
|
| Field | Change it to |
|
|
14
14
|
|---|---|
|
|
@@ -16,10 +16,10 @@ The app API has `ready()`, `checkpoint.read()/write()`, lifecycle notifications
|
|
|
16
16
|
| `version` | Your version number. Each version can be submitted once; use a new one for every change. |
|
|
17
17
|
| `name` and `tagline` | Your app's name and one line about it. |
|
|
18
18
|
| `store.description` | 40 to 2,000 characters of plain text about your app. |
|
|
19
|
-
| `store.category` and `store.rating` | `game
|
|
19
|
+
| `store.category` and `store.rating` | `game` or `app`, and an honest content rating. |
|
|
20
20
|
| `store.support` | Your own `https://` support page or email address. Players and reviewers see it. |
|
|
21
|
-
| `store/icon.png` | Your icon: a PNG of exactly 256 x 256 pixels, at most 256 KiB. |
|
|
21
|
+
| `store/icon.png` | Your icon: a PNG of exactly 256 x 256 pixels, at most 256 KiB. Make it a full-bleed, opaque square with the subject inside a margin; VibeStore rounds the corners itself. |
|
|
22
22
|
| `store/screenshot-1.png` | 1 to 4 screenshots of your app (PNG, JPEG or WebP, at most 1 MiB each). List every file in `store.screenshots`. |
|
|
23
23
|
| `window` | The size your app's window opens at: 320 to 1600 by 200 to 1200 pixels, and whether it can be resized. |
|
|
24
24
|
|
|
25
|
-
`npm run build` copies `index.html`, `vibemarket.json
|
|
25
|
+
`npm run build` copies `index.html`, `vibemarket.json`, the listed store images and everything in `public/` into `dist/`. `os preview` and `os pack` check the manifest and images, so a listing mistake shows up locally. Submit `app.zip` from the **Submit** tab of VibeStore in VibeMarket OS. A person reviews every version, and an approved version is copied to public IPFS, so approval is publication: never put anything secret in a bundle.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Stamp Club</title>
|
|
3
|
-
<style>body{margin:0;background:#ece9d8;color:#17233a;font:16px Arial;display:grid;
|
|
4
|
-
<body><
|
|
3
|
+
<style>html,body{height:100%}body{margin:0;background:#ece9d8;color:#17233a;font:16px Arial;display:grid;grid-template-rows:auto 1fr auto}header{display:flex;gap:12px;align-items:center;justify-content:center;padding:12px}h1{font-size:24px;margin:0}output{font-size:24px;font-weight:700;color:#176844;min-width:3ch}canvas{width:100%;height:100%;display:block;touch-action:none;cursor:crosshair}button{border:1px solid #174b9c;border-radius:4px;background:linear-gradient(#fff,#d7e8ff);padding:8px 18px;color:#17233a;font:700 16px Arial;cursor:pointer}button:disabled{opacity:.5}p{margin:0;padding:8px;text-align:center;color:#58637b}</style></head>
|
|
4
|
+
<body><header><h1>Stamp Club</h1><output id="count">0</output><button id="start" type="button" disabled>Start round</button><button id="finish" type="button" disabled>Finish round</button></header>
|
|
5
|
+
<canvas id="board"></canvas><p id="status" role="status">Connecting to the host…</p><script type="module" src="./main.js"></script></body></html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The source of the plain template's game.js (VM_OS_APPS_3.md section 11.7). The package build turns it into JavaScript
|
|
2
|
+
// (dist/templates/plain/game.js) and `os init --template plain` copies that file; edit game.js in your app, not this one.
|
|
3
|
+
// It runs as a classic script after vibemarket-os.js, which defines the global VibemarketOS; the build wraps it in a
|
|
4
|
+
// function, so the type import below leaves nothing behind.
|
|
5
|
+
import type { connect } from "@vibechain/os";
|
|
6
|
+
|
|
7
|
+
declare global { const VibemarketOS: { connect: typeof connect } }
|
|
8
|
+
|
|
9
|
+
VibemarketOS.connect().then(async os => {
|
|
10
|
+
const cat = document.getElementById("cat") as HTMLButtonElement;
|
|
11
|
+
const best = (await os.load<{ best?: number }>())?.best ?? 0;
|
|
12
|
+
let taps = 0;
|
|
13
|
+
cat.onclick = () => { taps++; cat.textContent = `${taps} (best ${best})`; };
|
|
14
|
+
os.ready();
|
|
15
|
+
setTimeout(async () => {
|
|
16
|
+
cat.disabled = true;
|
|
17
|
+
if (taps > best) await os.save({ best: taps });
|
|
18
|
+
await os.finish({ score: taps });
|
|
19
|
+
}, 30_000);
|
|
20
|
+
});
|