@vibechain/os 0.4.0 → 0.4.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 +111 -208
- package/README.md +7 -7
- package/dist/cli.js +1 -1
- package/dist/scaffold.js +10 -4
- package/examples/vibexp-app/README.md +19 -3
- package/examples/vibexp-app/store/icon.png +0 -0
- package/examples/vibexp-app/store/screenshot-1.png +0 -0
- package/examples/vibexp-app/vibemarket.json +21 -1
- package/package.json +3 -2
- package/examples/chonk-stack/card-slice.ts +0 -17
- package/examples/chonk-stack/cat3d.ts +0 -57
- package/examples/chonk-stack/game.css +0 -174
- package/examples/chonk-stack/index.html +0 -32
- package/examples/chonk-stack/main.ts +0 -149
- package/examples/chonk-stack/model.ts +0 -40
- package/examples/chonk-stack/renderer.ts +0 -263
- package/examples/chonk-stack/skins.ts +0 -47
- package/examples/chonk-stack/vibemarket.json +0 -21
- package/examples/collection-room/index.html +0 -3
- package/examples/collection-room/main.ts +0 -31
- package/examples/collection-room/vibemarket.json +0 -12
- package/examples/tsconfig.json +0 -4
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
|
-
import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";
|
|
3
|
-
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
|
4
|
-
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
|
5
|
-
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
|
|
6
|
-
import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPass.js";
|
|
7
|
-
import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
|
|
8
|
-
import { advance, drop, newStack, START_WIDTH, type CardLayer } from "./model";
|
|
9
|
-
import { centeredCardSlice, cutCardSlice, type CardSlice } from './card-slice';
|
|
10
|
-
import { createChonk } from "./cat3d";
|
|
11
|
-
const UNIT = 0.02, STEP = 0.34;
|
|
12
|
-
const COLORS = ["#ff65c9", "#78fff0", "#ffcd67", "#a993ff", "#fa8379", "#85aaff"];
|
|
13
|
-
interface Piece { mesh: THREE.Group; velocity: THREE.Vector3; age: number; spin: number }
|
|
14
|
-
interface Particle { position: THREE.Vector3; velocity: THREE.Vector3; age: number }
|
|
15
|
-
function foil(color: string, index: number) {
|
|
16
|
-
const canvas = document.createElement("canvas"); canvas.width = 512; canvas.height = 256;
|
|
17
|
-
const c = canvas.getContext("2d")!;
|
|
18
|
-
const gradient = c.createLinearGradient(0, 0, 512, 256); gradient.addColorStop(0, color); gradient.addColorStop(0.3, "#f6edff"); gradient.addColorStop(0.52, color); gradient.addColorStop(0.77, "#695af2"); gradient.addColorStop(1, color);
|
|
19
|
-
c.fillStyle = gradient; c.fillRect(0, 0, 512, 256);
|
|
20
|
-
c.strokeStyle = "#ffffffaf"; c.lineWidth = 3; c.strokeRect(16, 16, 480, 224); c.strokeRect(22, 22, 468, 212);
|
|
21
|
-
c.fillStyle = "#15132e"; c.font = "bold 19px monospace"; c.fillText("CHONK / AFTER HOURS", 39, 61);
|
|
22
|
-
c.font = "900 70px Arial"; c.fillText("STACK", 34, 152); c.font = "12px monospace"; c.fillText("COLLECTOR SERIES / 00" + (index + 1), 39, 215);
|
|
23
|
-
c.save(); c.translate(410, 123); c.rotate(Math.PI / 4); c.strokeStyle = "#ffffffd0";
|
|
24
|
-
for (let i = 0; i < 5; i++) c.strokeRect(-45 + i * 7, -45 + i * 7, 90 - i * 14, 90 - i * 14); c.restore();
|
|
25
|
-
const texture = new THREE.CanvasTexture(canvas); texture.colorSpace = THREE.SRGBColorSpace; return texture;
|
|
26
|
-
}
|
|
27
|
-
export class StackRenderer {
|
|
28
|
-
readonly state = newStack();
|
|
29
|
-
private renderer: THREE.WebGLRenderer;
|
|
30
|
-
private scene = new THREE.Scene();
|
|
31
|
-
private lights = new THREE.Group();
|
|
32
|
-
private camera = new THREE.PerspectiveCamera(38, 1, 0.1, 140);
|
|
33
|
-
private composer: EffectComposer;
|
|
34
|
-
private bloom: UnrealBloomPass;
|
|
35
|
-
private environment: THREE.WebGLRenderTarget;
|
|
36
|
-
private cat = createChonk();
|
|
37
|
-
private tower = new Map<number, { mesh: THREE.Group; born: number }>();
|
|
38
|
-
private moving: THREE.Group;
|
|
39
|
-
private introCards: THREE.Group[] = [];
|
|
40
|
-
private fragments: Piece[] = [];
|
|
41
|
-
private particles: Particle[] = [];
|
|
42
|
-
private sparks = new THREE.InstancedMesh(new THREE.OctahedronGeometry(0.055), new THREE.MeshBasicMaterial({ color: "#fff4cb", toneMapped: false }), 80);
|
|
43
|
-
private dummy = new THREE.Object3D();
|
|
44
|
-
private platform = new THREE.Group();
|
|
45
|
-
private rings = new THREE.Group();
|
|
46
|
-
private stars: THREE.Points;
|
|
47
|
-
private textures = COLORS.map(foil);
|
|
48
|
-
private faces = COLORS.map((color, index) => new THREE.MeshPhysicalMaterial({ map: this.textures[index], metalness: 0.6, roughness: 0.23, clearcoat: 1, iridescence: 0.8, iridescenceIOR: 1.4, emissive: color, emissiveIntensity: 0.09, side: THREE.DoubleSide }));
|
|
49
|
-
private edges = COLORS.map(color => new THREE.MeshStandardMaterial({ color, metalness: 0.65, roughness: 0.22 }));
|
|
50
|
-
private cardGeometry = new RoundedBoxGeometry(1, 0.18, 2.75, 2, 0.035);
|
|
51
|
-
private faceGeometry = new THREE.PlaneGeometry(0.97, 2.67);
|
|
52
|
-
private lineGeometry = new THREE.BoxGeometry(1.005, 0.025, 2.73);
|
|
53
|
-
private lineMaterial = new THREE.MeshBasicMaterial({ color: "#c9faff", toneMapped: false });
|
|
54
|
-
private guides: THREE.LineSegments;
|
|
55
|
-
private frame = 0; private previous = 0; private elapsed = 0; private lastInput = -10; private landed = -10; private cameraY = 0;
|
|
56
|
-
private mode: "intro" | "playing" | "ended" = "intro";
|
|
57
|
-
private paused = false; private destroyed = false; private width = 480; private height = 640;
|
|
58
|
-
private cardDepth = 2.75;
|
|
59
|
-
private artworkOrder = COLORS.map((_, index) => index);
|
|
60
|
-
private suppliedArtwork = false;
|
|
61
|
-
private nextArtwork: readonly HTMLImageElement[] | null = null;
|
|
62
|
-
private layerSlices = new Map<number, CardSlice>();
|
|
63
|
-
private croppedFaces = new Map<THREE.Group, THREE.BufferGeometry>();
|
|
64
|
-
private reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
65
|
-
private resizeObserver: ResizeObserver;
|
|
66
|
-
private pointer = new THREE.Vector2();
|
|
67
|
-
private aim = new THREE.Vector3();
|
|
68
|
-
private onPointer = (event: PointerEvent) => { this.pointer.set(event.offsetX / this.width - 0.5, event.offsetY / this.height - 0.5); };
|
|
69
|
-
private onVisibility = () => { if (document.hidden) this.cancel(); else this.schedule(); };
|
|
70
|
-
constructor(private canvas: HTMLCanvasElement, private onDrop: (score: number, combo: number, ended: boolean) => void) {
|
|
71
|
-
this.renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false, powerPreference: "high-performance" });
|
|
72
|
-
this.renderer.setClearColor("#090519"); this.renderer.toneMapping = THREE.ACESFilmicToneMapping; this.renderer.toneMappingExposure = 0.95;
|
|
73
|
-
this.renderer.shadowMap.enabled = true; this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
74
|
-
this.scene.background = new THREE.Color("#090519"); this.scene.environmentIntensity = 0.35;
|
|
75
|
-
this.scene.fog = new THREE.FogExp2("#090519", 0.018);
|
|
76
|
-
const room = new RoomEnvironment(), pmrem = new THREE.PMREMGenerator(this.renderer);
|
|
77
|
-
this.environment = pmrem.fromScene(room, 0.04); this.scene.environment = this.environment.texture; room.dispose(); pmrem.dispose();
|
|
78
|
-
this.scene.add(new THREE.HemisphereLight("#b5aaff", "#26112e", 1.2));
|
|
79
|
-
const key = new THREE.DirectionalLight("#fff1d5", 2.6); key.position.set(-4, 12, 8); key.castShadow = true; key.shadow.mapSize.set(1024, 1024); key.shadow.camera.left = -8; key.shadow.camera.right = 8; key.shadow.camera.top = 10; key.shadow.camera.bottom = -6; key.shadow.bias = -0.001; this.lights.add(key, key.target);
|
|
80
|
-
const cyan = new THREE.PointLight("#4df5ff", 35, 30); cyan.position.set(-6, 5, 3); this.lights.add(cyan);
|
|
81
|
-
const pink = new THREE.PointLight("#ff48c4", 45, 30); pink.position.set(5, 6, -4); this.lights.add(pink); this.scene.add(this.lights);
|
|
82
|
-
const base = new THREE.Mesh(new THREE.CylinderGeometry(3.3, 2.9, 0.35, 64), new THREE.MeshStandardMaterial({ color: "#251741", metalness: 0.8, roughness: 0.25 })); base.position.y = -0.35; base.receiveShadow = true; this.platform.add(base);
|
|
83
|
-
for (let i = 0; i < 3; i++) { const ring = new THREE.Mesh(new THREE.TorusGeometry(3.25 + i * 0.16, 0.025, 6, 80), new THREE.MeshBasicMaterial({ color: i === 1 ? "#ff63d9" : "#65fff2", toneMapped: false })); ring.rotation.x = Math.PI / 2; ring.position.y = -0.23 - i * 0.12; this.platform.add(ring); }
|
|
84
|
-
this.scene.add(this.platform, this.cat.root, this.rings, this.sparks); this.sparks.count = 0; this.sparks.frustumCulled = false;
|
|
85
|
-
for (let i = 0; i < 4; i++) {
|
|
86
|
-
const ring = new THREE.Mesh(new THREE.TorusGeometry(6.1 + i * 1.8, 0.012, 5, 128), new THREE.MeshBasicMaterial({ color: i % 2 ? "#653ae1" : "#ff4698", transparent: true, opacity: 0.45, toneMapped: false }));
|
|
87
|
-
ring.position.set(0, 3, -6); ring.rotation.set(0.3 + i * 0.22, 0.4, i * 0.4); this.rings.add(ring);
|
|
88
|
-
}
|
|
89
|
-
const positions = new Float32Array(900 * 3);
|
|
90
|
-
for (let i = 0; i < 900; i++) { const a = i * 2.39996, radius = 15 + (i % 53) * 0.5; positions[i * 3] = Math.cos(a) * radius; positions[i * 3 + 1] = (i % 71) - 20; positions[i * 3 + 2] = Math.sin(a) * radius - 8; }
|
|
91
|
-
const geometry = new THREE.BufferGeometry(); geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
92
|
-
this.stars = new THREE.Points(geometry, new THREE.PointsMaterial({ color: "#a6c9ff", size: 0.06, transparent: true, opacity: 0.8, sizeAttenuation: true })); this.scene.add(this.stars);
|
|
93
|
-
const guideGeometry = new THREE.BufferGeometry(); guideGeometry.setAttribute("position", new THREE.Float32BufferAttribute(new Float32Array(12), 3));
|
|
94
|
-
this.guides = new THREE.LineSegments(guideGeometry, new THREE.LineBasicMaterial({ color: "#7bffe2", transparent: true, opacity: 0.32 })); this.guides.frustumCulled = false; this.scene.add(this.guides);
|
|
95
|
-
this.moving = this.makeCard(0); this.scene.add(this.moving);
|
|
96
|
-
for (let i = 0; i < 7; i++) { const card = this.makeCard(i); card.scale.x = 4.55; card.position.y = i * 0.36; this.introCards.push(card); this.scene.add(card); }
|
|
97
|
-
this.composer = new EffectComposer(this.renderer); this.composer.addPass(new RenderPass(this.scene, this.camera));
|
|
98
|
-
this.bloom = new UnrealBloomPass(new THREE.Vector2(480, 640), 0.25, 0.3, 1.8); this.composer.addPass(this.bloom); this.composer.addPass(new OutputPass());
|
|
99
|
-
this.cat.skin(0); this.resizeObserver = new ResizeObserver(() => this.resize()); this.resizeObserver.observe(canvas);
|
|
100
|
-
canvas.addEventListener("pointermove", this.onPointer); document.addEventListener("visibilitychange", this.onVisibility);
|
|
101
|
-
this.resize(); this.schedule();
|
|
102
|
-
}
|
|
103
|
-
private makeCard(level: number, slice = centeredCardSlice(START_WIDTH)) {
|
|
104
|
-
const group = new THREE.Group(); const index = this.artworkOrder[level % this.artworkOrder.length];
|
|
105
|
-
const body = new THREE.Mesh(this.cardGeometry, this.edges[index % this.edges.length]); body.receiveShadow = true; group.add(body);
|
|
106
|
-
const geometry = slice.left === 0 && slice.right === 1 ? this.faceGeometry : this.faceGeometry.clone();
|
|
107
|
-
if (geometry !== this.faceGeometry) {
|
|
108
|
-
const uv = geometry.getAttribute('uv');
|
|
109
|
-
for (let i = 0; i < uv.count; i++) uv.setX(i, slice.left + uv.getX(i) * (slice.right - slice.left));
|
|
110
|
-
uv.needsUpdate = true; this.croppedFaces.set(group, geometry);
|
|
111
|
-
}
|
|
112
|
-
const face = new THREE.Mesh(geometry, this.faces[index]); face.rotation.x = -Math.PI / 2; face.position.y = 0.094; face.receiveShadow = true; group.add(face);
|
|
113
|
-
const line = new THREE.Mesh(this.lineGeometry, this.lineMaterial); line.position.y = -0.01; group.add(line); return group;
|
|
114
|
-
}
|
|
115
|
-
private removeCard(mesh: THREE.Group): void {
|
|
116
|
-
this.scene.remove(mesh); this.croppedFaces.get(mesh)?.dispose(); this.croppedFaces.delete(mesh);
|
|
117
|
-
}
|
|
118
|
-
private resize() {
|
|
119
|
-
if (this.destroyed) return; const bounds = this.canvas.getBoundingClientRect(); if (!bounds.width || !bounds.height) return;
|
|
120
|
-
this.width = bounds.width; this.height = bounds.height;
|
|
121
|
-
const ratio = Math.min(devicePixelRatio || 1, this.width < 600 ? 1.25 : 1.5);
|
|
122
|
-
this.renderer.setPixelRatio(ratio); this.renderer.setSize(this.width, this.height, false); this.composer.setPixelRatio(ratio); this.composer.setSize(this.width, this.height);
|
|
123
|
-
this.bloom.enabled = this.width >= 600 && !this.reduced;
|
|
124
|
-
this.camera.aspect = this.width / this.height; this.camera.updateProjectionMatrix(); this.draw();
|
|
125
|
-
}
|
|
126
|
-
setSkin(index: number) { this.cat.skin(index); this.draw(); }
|
|
127
|
-
/** Background artwork can change the intro, or wait for the next fresh run. */
|
|
128
|
-
setNextCardArtwork(images: readonly HTMLImageElement[]): void {
|
|
129
|
-
if (this.destroyed) return;
|
|
130
|
-
if (this.mode === 'intro') { this.setCardArtwork(images); return; }
|
|
131
|
-
if (images.length < 1 || images.length > 12 || images.some(image => !image.complete || image.naturalWidth < 1 || image.naturalHeight < 1 || image.naturalWidth > 2048 || image.naturalHeight > 2048))
|
|
132
|
-
throw new Error('Supply one to twelve decoded card faces');
|
|
133
|
-
this.nextArtwork = [...images];
|
|
134
|
-
}
|
|
135
|
-
/** First-party hosts can supply decoded, origin-clean full slabs. This performs no network or inventory work. */
|
|
136
|
-
setCardArtwork(images: readonly HTMLImageElement[]): void {
|
|
137
|
-
if (this.destroyed) return;
|
|
138
|
-
if (this.mode !== 'intro') throw new Error('Load card artwork before play');
|
|
139
|
-
if (images.length < 1 || images.length > 12) throw new Error('Supply one to twelve card faces');
|
|
140
|
-
const prepared = images.map(image => {
|
|
141
|
-
if (!image.complete || image.naturalWidth < 1 || image.naturalHeight < 1 || image.naturalWidth > 2048 || image.naturalHeight > 2048)
|
|
142
|
-
throw new Error('Card artwork is not decoded or exceeds its size limit');
|
|
143
|
-
const canvas = document.createElement('canvas'); canvas.width = 512; canvas.height = 806;
|
|
144
|
-
const context = canvas.getContext('2d'); if (!context) throw new Error('Card artwork canvas unavailable');
|
|
145
|
-
context.fillStyle = '#16161a'; context.fillRect(0, 0, 512, 806);
|
|
146
|
-
const scale = Math.min(512 / image.naturalWidth, 806 / image.naturalHeight);
|
|
147
|
-
const width = image.naturalWidth * scale, height = image.naturalHeight * scale;
|
|
148
|
-
context.drawImage(image, (512 - width) / 2, (806 - height) / 2, width, height);
|
|
149
|
-
// Refuse a tainted source before replacing any texture used by recording.
|
|
150
|
-
context.getImageData(0, 0, 1, 1); return canvas;
|
|
151
|
-
});
|
|
152
|
-
// The intro has already uploaded the procedural textures. WebGL's immutable
|
|
153
|
-
// storage cannot be resized from those landscape faces to portrait slabs.
|
|
154
|
-
const previousTextures = this.textures;
|
|
155
|
-
this.textures = prepared.map(canvas => { const texture = new THREE.CanvasTexture(canvas); texture.colorSpace = THREE.SRGBColorSpace; return texture; });
|
|
156
|
-
while (this.faces.length < prepared.length) this.faces.push(this.faces[0].clone());
|
|
157
|
-
this.faces.forEach((face, index) => { face.map = this.textures[index % this.textures.length]; });
|
|
158
|
-
previousTextures.forEach(texture => texture.dispose());
|
|
159
|
-
this.faces.forEach(face => { face.metalness = 0; face.roughness = 0.6; face.iridescence = 0; face.clearcoat = 0.25; face.emissiveIntensity = 0; face.needsUpdate = true; });
|
|
160
|
-
this.edges.forEach(edge => { edge.color.set('#50535c'); edge.metalness = 0.1; edge.roughness = 0.25; });
|
|
161
|
-
this.artworkOrder = prepared.map((_, index) => index); this.suppliedArtwork = true;
|
|
162
|
-
const replace = <T extends THREE.BufferGeometry>(previous: T, next: T): T => {
|
|
163
|
-
this.scene.traverse(object => { if (object instanceof THREE.Mesh && object.geometry === previous) object.geometry = next; });
|
|
164
|
-
previous.dispose(); return next;
|
|
165
|
-
};
|
|
166
|
-
this.cardDepth = 7.15;
|
|
167
|
-
this.cardGeometry = replace(this.cardGeometry, new RoundedBoxGeometry(1, 0.18, this.cardDepth, 2, 0.035));
|
|
168
|
-
this.faceGeometry = replace(this.faceGeometry, new THREE.PlaneGeometry(0.97, this.cardDepth - 0.08));
|
|
169
|
-
this.lineGeometry = replace(this.lineGeometry, new THREE.BoxGeometry(1.005, 0.025, this.cardDepth - 0.02));
|
|
170
|
-
this.draw();
|
|
171
|
-
}
|
|
172
|
-
start() {
|
|
173
|
-
for (const entry of this.tower.values()) this.removeCard(entry.mesh); this.tower.clear(); this.layerSlices.clear();
|
|
174
|
-
for (const piece of this.fragments) this.removeCard(piece.mesh); this.fragments = []; this.particles = [];
|
|
175
|
-
if (this.nextArtwork) {
|
|
176
|
-
const images = this.nextArtwork; this.nextArtwork = null; this.mode = 'intro'; this.setCardArtwork(images);
|
|
177
|
-
}
|
|
178
|
-
if (this.suppliedArtwork) for (let i = this.artworkOrder.length - 1; i > 0; i--) {
|
|
179
|
-
const j = Math.floor(crypto.getRandomValues(new Uint32Array(1))[0] / 0x1_0000_0000 * (i + 1));
|
|
180
|
-
[this.artworkOrder[i], this.artworkOrder[j]] = [this.artworkOrder[j], this.artworkOrder[i]];
|
|
181
|
-
}
|
|
182
|
-
Object.assign(this.state, newStack()); this.mode = "playing"; this.paused = false; this.cameraY = 0; this.elapsed = 0; this.landed = -10; this.lastInput = -10;
|
|
183
|
-
this.syncCards(); this.draw(); this.schedule();
|
|
184
|
-
}
|
|
185
|
-
private syncCards() {
|
|
186
|
-
const keep = new Set(this.state.layers.map(layer => layer.level));
|
|
187
|
-
for (const [level, entry] of this.tower) if (!keep.has(level)) { this.removeCard(entry.mesh); this.tower.delete(level); this.layerSlices.delete(level); }
|
|
188
|
-
for (const layer of this.state.layers) if (!this.tower.has(layer.level)) {
|
|
189
|
-
const mesh = this.makeCard(layer.level, this.layerSlices.get(layer.level) ?? centeredCardSlice(layer.width)); mesh.scale.x = layer.width * UNIT; mesh.position.x = (layer.x + layer.width / 2 - 240) * UNIT;
|
|
190
|
-
this.scene.add(mesh); this.tower.set(layer.level, { mesh, born: layer.level ? this.elapsed : -10 });
|
|
191
|
-
}
|
|
192
|
-
this.removeCard(this.moving); this.moving = this.makeCard(this.state.moving.level, centeredCardSlice(this.state.moving.width)); this.scene.add(this.moving);
|
|
193
|
-
}
|
|
194
|
-
input() {
|
|
195
|
-
if (this.mode !== "playing" || this.paused || this.elapsed - this.lastInput < 0.2) return;
|
|
196
|
-
this.lastInput = this.elapsed; const incoming = { ...this.state.moving }, result = drop(this.state); this.landed = this.elapsed;
|
|
197
|
-
if (!this.state.ended) {
|
|
198
|
-
const landed = this.state.layers[this.state.layers.length - 1];
|
|
199
|
-
this.layerSlices.set(landed.level, result.perfect ? centeredCardSlice(landed.width) : cutCardSlice(incoming, landed));
|
|
200
|
-
}
|
|
201
|
-
if (result.offcut && !this.reduced) this.fall(result.offcut, cutCardSlice(incoming, result.offcut));
|
|
202
|
-
const top = this.state.layers[this.state.layers.length - 1];
|
|
203
|
-
if (!this.reduced) for (let i = 0; i < (result.perfect ? 24 : 8); i++) this.particles.push({ position: new THREE.Vector3((top.x + top.width / 2 - 240) * UNIT, top.level * STEP + 0.2, 0), velocity: new THREE.Vector3(Math.sin(i * 2.4) * 3.2, 2 + (i % 3), Math.cos(i * 2.4) * 3.2), age: 0 });
|
|
204
|
-
this.particles = this.particles.slice(-80); this.syncCards();
|
|
205
|
-
if (this.state.ended) this.mode = "ended";
|
|
206
|
-
this.onDrop(this.state.score, this.state.combo, this.state.ended); this.draw();
|
|
207
|
-
}
|
|
208
|
-
private fall(card: CardLayer, slice: CardSlice) {
|
|
209
|
-
const mesh = this.makeCard(card.level, slice); mesh.scale.x = card.width * UNIT; mesh.position.set((card.x + card.width / 2 - 240) * UNIT, card.level * STEP + 2.1, 0); this.scene.add(mesh);
|
|
210
|
-
this.fragments.push({ mesh, velocity: new THREE.Vector3(card.x > 240 ? 2 : -2, 0.3, 0.2), age: 0, spin: card.x > 240 ? -1 : 1 });
|
|
211
|
-
while (this.fragments.length > 8) this.removeCard(this.fragments.shift()!.mesh);
|
|
212
|
-
}
|
|
213
|
-
pause(value: boolean) { this.paused = value; this.previous = 0; if (value) this.cancel(); else this.schedule(); this.draw(); }
|
|
214
|
-
private schedule() { if (!this.frame && !this.paused && !this.destroyed && !document.hidden && !(this.reduced && this.mode !== "playing")) this.frame = requestAnimationFrame(time => this.tick(time)); }
|
|
215
|
-
private cancel() { cancelAnimationFrame(this.frame); this.frame = 0; this.previous = 0; }
|
|
216
|
-
private tick(time: number) {
|
|
217
|
-
this.frame = 0; if (this.paused || this.destroyed || document.hidden) return;
|
|
218
|
-
if (this.mode === "intro" && this.previous && time - this.previous < 32) { this.schedule(); return; }
|
|
219
|
-
const dt = this.previous ? Math.min(0.05, (time - this.previous) / 1000) : 0; this.previous = time; this.elapsed += dt;
|
|
220
|
-
if (this.mode === "playing") advance(this.state, dt);
|
|
221
|
-
this.cameraY += (Math.max(0, this.state.score - 2) * STEP - this.cameraY) * Math.min(1, dt * 5);
|
|
222
|
-
for (const piece of this.fragments) { piece.age += dt; piece.velocity.y -= 10 * dt; piece.mesh.position.addScaledVector(piece.velocity, dt); piece.mesh.rotation.z += dt * piece.spin * 2; piece.mesh.rotation.x += dt; }
|
|
223
|
-
this.fragments = this.fragments.filter(piece => { if (piece.age < 1.8) return true; this.removeCard(piece.mesh); return false; });
|
|
224
|
-
for (const particle of this.particles) { particle.age += dt; particle.velocity.y -= 6 * dt; particle.position.addScaledVector(particle.velocity, dt); }
|
|
225
|
-
this.particles = this.particles.filter(particle => particle.age < 1.2); this.draw();
|
|
226
|
-
if (this.mode !== "ended" || this.elapsed - this.landed < 1.8) this.schedule();
|
|
227
|
-
}
|
|
228
|
-
private draw() {
|
|
229
|
-
if (this.destroyed) return;
|
|
230
|
-
const intro = this.mode === "intro", t = this.elapsed, top = this.state.layers[this.state.layers.length - 1];
|
|
231
|
-
this.platform.position.y = -Math.max(0, this.cameraY * 0.1); this.platform.visible = this.cameraY < 7;
|
|
232
|
-
this.introCards.forEach((mesh, index) => { mesh.visible = intro; mesh.rotation.y = this.reduced ? index * 0.05 : Math.sin(t * 0.35 + index * 0.4) * 0.2; mesh.position.y = index * 0.36 + (this.reduced ? 0 : Math.sin(t * 0.8 + index) * 0.035); });
|
|
233
|
-
for (const [level, entry] of this.tower) { const progress = this.reduced ? 1 : Math.min(1, (t - entry.born) / 0.18); entry.mesh.position.y = level * STEP + (1 - progress) ** 3 * 2.1; }
|
|
234
|
-
this.moving.visible = this.mode === "playing"; this.moving.scale.x = this.state.moving.width * UNIT;
|
|
235
|
-
this.moving.position.set((this.state.moving.x + this.state.moving.width / 2 - 240) * UNIT, this.state.moving.level * STEP + 2.1, 0);
|
|
236
|
-
const bounce = this.reduced ? 0 : Math.max(0, 1 - (t - this.landed) / 0.5);
|
|
237
|
-
this.cat.root.position.set(intro ? 0 : (top.x + top.width / 2 - 240) * UNIT, (intro ? 6 * 0.36 : top.level * STEP) + 0.11 + Math.sin(bounce * Math.PI) * 0.65, 0);
|
|
238
|
-
this.cat.root.scale.set(0.85 + bounce * 0.05, 0.85 - bounce * 0.07, 0.85 + bounce * 0.05);
|
|
239
|
-
this.cat.root.rotation.y = 0.38 + (!this.reduced && intro ? Math.sin(t * 0.5) * 0.1 : 0); this.cat.root.rotation.z = Math.sin(bounce * Math.PI * 2) * 0.08;
|
|
240
|
-
this.lights.position.y = this.cameraY; this.rings.position.y = this.cameraY; if (!this.reduced) this.rings.rotation.z = t * 0.018; this.stars.position.y = this.cameraY * 0.7;
|
|
241
|
-
this.particles.forEach((particle, index) => { this.dummy.position.copy(particle.position); this.dummy.rotation.set(particle.age * 3, particle.age * 5, 0); this.dummy.scale.setScalar((1 - particle.age / 1.2) * 1.8); this.dummy.updateMatrix(); this.sparks.setMatrixAt(index, this.dummy.matrix); }); this.sparks.count = this.particles.length; this.sparks.instanceMatrix.needsUpdate = true;
|
|
242
|
-
const array = this.guides.geometry.attributes.position.array;
|
|
243
|
-
const x1 = (top.x - 240) * UNIT, x2 = (top.x + top.width - 240) * UNIT, y1 = top.level * STEP + 0.15, y2 = this.state.moving.level * STEP + 2.0;
|
|
244
|
-
const guideZ = this.cardDepth / 2 + 0.025;
|
|
245
|
-
array.set([x1, y1, guideZ, x1, y2, guideZ, x2, y1, guideZ, x2, y2, guideZ]); this.guides.geometry.attributes.position.needsUpdate = true; this.guides.visible = this.mode === "playing";
|
|
246
|
-
const distance = Math.max(14, Math.min(25, 15 / Math.pow(this.camera.aspect, 0.55))) * (intro && this.width <= 650 ? 1.12 : 1);
|
|
247
|
-
const orbit = 0.44 + (this.reduced ? 0 : this.pointer.x * 0.1);
|
|
248
|
-
this.aim.set(intro && this.width > 650 ? -1.9 : 0, this.cameraY + (intro ? 1.65 : 1.0), 0);
|
|
249
|
-
const impact = !this.reduced && this.state.combo >= 3 ? Math.sin(bounce * 28) * bounce * 0.035 : 0;
|
|
250
|
-
this.camera.position.set(Math.sin(orbit) * distance + impact, this.cameraY + distance * 0.57, Math.cos(orbit) * distance);
|
|
251
|
-
this.camera.lookAt(this.aim); this.composer.render();
|
|
252
|
-
}
|
|
253
|
-
destroy() {
|
|
254
|
-
if (this.destroyed) return;
|
|
255
|
-
this.destroyed = true; this.cancel(); this.resizeObserver.disconnect(); this.canvas.removeEventListener("pointermove", this.onPointer); document.removeEventListener("visibilitychange", this.onVisibility);
|
|
256
|
-
const geometries = new Set<THREE.BufferGeometry>(), materials = new Set<THREE.Material>();
|
|
257
|
-
this.scene.traverse(object => { if (object instanceof THREE.DirectionalLight) object.shadow.dispose(); if (object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points) { geometries.add(object.geometry); for (const material of Array.isArray(object.material) ? object.material : [object.material]) materials.add(material); } });
|
|
258
|
-
this.faces.forEach(material => materials.add(material)); this.edges.forEach(material => materials.add(material));
|
|
259
|
-
geometries.forEach(geometry => geometry.dispose()); materials.forEach(material => material.dispose()); this.textures.forEach(texture => texture.dispose());
|
|
260
|
-
this.croppedFaces.clear(); this.layerSlices.clear(); this.nextArtwork = null;
|
|
261
|
-
this.environment.dispose(); for (const pass of this.composer.passes) pass.dispose(); this.composer.dispose(); this.renderer.dispose(); this.renderer.forceContextLoss();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { GameCard } from "@vibechain/os";
|
|
2
|
-
|
|
3
|
-
export const COLLECTION = "4663:0x733f92170fa7d42bdb6f35fb7d37af97208ff124:6";
|
|
4
|
-
export const SKINS = [
|
|
5
|
-
{ name: "Cloud", fur: "#f7f0dc", belly: "#fffbee", accent: "#c3d4d7", eyes: "#324b55", label: "STARTER" },
|
|
6
|
-
{ name: "Ginger", fur: "#df9859", belly: "#ffe1ad", accent: "#eaae72", eyes: "#4d6154", label: "COMMON" },
|
|
7
|
-
{ name: "Bubblegum", fur: "#e7a5c7", belly: "#ffe3ef", accent: "#edb8d0", eyes: "#665281", label: "RARE" },
|
|
8
|
-
{ name: "Mint Condition", fur: "#7fcbb2", belly: "#dcffec", accent: "#8ed3b7", eyes: "#29534d", label: "EPIC" },
|
|
9
|
-
{ name: "Midnight", fur: "#515066", belly: "#e9e5ff", accent: "#b3aedc", eyes: "#dbd5fc", label: "LEGENDARY" },
|
|
10
|
-
{ name: "Solar Gold", fur: "#e4b546", belly: "#fff3c2", accent: "#f3cf76", eyes: "#6b5735", label: "MYTHIC" },
|
|
11
|
-
] as const;
|
|
12
|
-
export function ownedSkins(cards: readonly GameCard[]): Set<number> {
|
|
13
|
-
return new Set([0, ...cards.filter(card => card.packId === COLLECTION && card.state === "collected" && Number.isInteger(card.rarity) && card.rarity >= 0 && card.rarity < 5).map(card => card.rarity + 1)]);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** The same cosmetic characters, drawn locally; no remote art or wallet code. */
|
|
17
|
-
export function drawCat(c: CanvasRenderingContext2D, x: number, y: number, size: number, skin: number, squash = 0) {
|
|
18
|
-
const look = SKINS[skin] ?? SKINS[0];
|
|
19
|
-
c.save(); c.translate(x, y); c.scale(size / 100 * (1 + squash * 0.12), size / 100 * (1 - squash * 0.12));
|
|
20
|
-
c.lineCap = "round"; c.lineJoin = "round";
|
|
21
|
-
// Tail, haunches and the oversized head are the silhouette at small sizes.
|
|
22
|
-
c.strokeStyle = look.fur; c.lineWidth = 13; c.beginPath(); c.moveTo(30, -17); c.bezierCurveTo(62, -3, 57, -43, 42, -38); c.stroke();
|
|
23
|
-
c.fillStyle = look.fur; c.beginPath(); c.ellipse(0, -24, 37, 26, 0, 0, Math.PI * 2); c.fill();
|
|
24
|
-
c.beginPath(); c.moveTo(-31, -55); c.lineTo(-34, -88); c.quadraticCurveTo(-27, -94, -12, -72); c.lineTo(14, -72); c.quadraticCurveTo(30, -94, 35, -88); c.lineTo(32, -52); c.closePath(); c.fill();
|
|
25
|
-
c.fillStyle = "#eab8b0"; c.beginPath(); c.moveTo(-28, -65); c.lineTo(-28, -80); c.lineTo(-17, -69); c.moveTo(27, -65); c.lineTo(28, -80); c.lineTo(17, -69); c.fill();
|
|
26
|
-
c.fillStyle = look.fur; c.beginPath(); c.ellipse(0, -54, 40, 29, 0, 0, Math.PI * 2); c.fill();
|
|
27
|
-
c.fillStyle = look.belly; c.beginPath(); c.ellipse(0, -15, 22, 12, 0, 0, Math.PI * 2); c.fill();
|
|
28
|
-
c.beginPath(); c.ellipse(-12, -43, 16, 11, 0, 0, Math.PI * 2); c.ellipse(12, -43, 16, 11, 0, 0, Math.PI * 2); c.fill();
|
|
29
|
-
c.fillStyle = look.eyes; for (const side of [-1, 1]) { c.beginPath(); c.ellipse(side * 17, -56, 4, 6, 0, 0, Math.PI * 2); c.fill(); }
|
|
30
|
-
c.fillStyle = "#fff"; for (const side of [-1, 1]) { c.beginPath(); c.arc(side * 17 - 1, -58, 1.4, 0, Math.PI * 2); c.fill(); }
|
|
31
|
-
c.fillStyle = "#b97c79"; c.beginPath(); c.moveTo(-4, -45); c.lineTo(4, -45); c.lineTo(0, -41); c.fill();
|
|
32
|
-
c.strokeStyle = "#6b6261"; c.lineWidth = 1.5; c.beginPath(); c.moveTo(-6, -38); c.quadraticCurveTo(-2, -35, 0, -40); c.quadraticCurveTo(2, -35, 6, -38); c.stroke();
|
|
33
|
-
c.strokeStyle = look.belly; c.lineWidth = 3; c.beginPath(); c.moveTo(-27, -41); c.lineTo(-43, -43); c.moveTo(27, -41); c.lineTo(43, -43); c.stroke();
|
|
34
|
-
c.fillStyle = look.fur; for (const side of [-1, 1]) { c.beginPath(); c.ellipse(side * 22, -3, 12, 6, 0, 0, Math.PI * 2); c.fill(); }
|
|
35
|
-
if (skin === 1 || skin === 5) {
|
|
36
|
-
c.strokeStyle = skin === 5 ? "#b48836" : "#ad713c"; c.lineWidth = 3;
|
|
37
|
-
for (const dx of [-9, 0, 9]) { c.beginPath(); c.moveTo(dx, -80); c.lineTo(dx * 0.7, -70); c.stroke(); }
|
|
38
|
-
}
|
|
39
|
-
if (skin === 3 || skin === 4) {
|
|
40
|
-
c.strokeStyle = "#303940"; c.lineWidth = 3;
|
|
41
|
-
for (const side of [-1, 1]) { c.beginPath(); c.roundRect(side * 17 - 11, -65, 22, 17, 5); if (skin === 4) { c.fillStyle = "#273341"; c.fill(); } c.stroke(); }
|
|
42
|
-
c.beginPath(); c.moveTo(-6, -57); c.lineTo(6, -57); c.stroke();
|
|
43
|
-
}
|
|
44
|
-
if (skin === 5) { c.strokeStyle = "#fff1a1"; c.lineWidth = 4; c.beginPath(); c.arc(0, -28, 17, 0.15, Math.PI - 0.15); c.stroke(); }
|
|
45
|
-
if (skin === 2) { c.fillStyle = "#cb88b4"; c.beginPath(); c.roundRect(-32, -8, 20, 6, 3); c.roundRect(12, -8, 20, 6, 3); c.fill(); }
|
|
46
|
-
c.restore();
|
|
47
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schemaVersion": 1,
|
|
3
|
-
"sdkVersion": 1,
|
|
4
|
-
"id": "chonk-stack-lab",
|
|
5
|
-
"version": "2.1.0",
|
|
6
|
-
"name": "Chonk Stack Lab",
|
|
7
|
-
"tagline": "Stack the impossible. Your cards. Your cat. No ceiling.",
|
|
8
|
-
"category": "3D arcade \u00b7 collect \u00b7 stack",
|
|
9
|
-
"entry": "index.html",
|
|
10
|
-
"permissions": [
|
|
11
|
-
"inventory.get",
|
|
12
|
-
"catalog.list",
|
|
13
|
-
"packs.buy",
|
|
14
|
-
"packs.sell",
|
|
15
|
-
"packs.open",
|
|
16
|
-
"cards.reveal",
|
|
17
|
-
"cards.sell",
|
|
18
|
-
"cards.collect"
|
|
19
|
-
],
|
|
20
|
-
"collectionId": "4663:0x733f92170fa7d42bdb6f35fb7d37af97208ff124:6"
|
|
21
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Collection Room</title><style>
|
|
2
|
-
*{box-sizing:border-box}body{margin:0;background:#14191b;color:#f5f0dc;font:16px system-ui;min-height:100vh;display:grid;place-items:center}main{text-align:center;padding:32px 20px;width:min(100%,720px)}small{color:#afc48f;letter-spacing:.2em;font:11px monospace}h1{font-size:clamp(30px,6vw,60px);letter-spacing:-.05em;margin:14px 0}#status{font:12px monospace;color:#a8aaa1;line-height:1.6}#cat{display:block;margin:28px auto 12px;background:#ecdcaf;color:#191919;font-size:100px;width:200px;height:200px;border-radius:50%;border:0;cursor:pointer;box-shadow:0 0 0 12px #ecdcaf0c}button{cursor:pointer;padding:12px 20px;border:1px solid #677362;background:transparent;color:inherit;border-radius:4px}#count{color:#d0e5ad;font-size:18px}#inventory{font:12px monospace;color:#a8aaa1;margin:24px 0}#inventory button{margin:4px}footer{margin-top:30px;font:10px monospace;color:#758072}
|
|
3
|
-
</style></head><body><main><small>VIBEMARKET DEVELOPER EXAMPLE</small><h1>Collection Room</h1><p id="status">Connecting to VibeMarket…</p><button id="cat" aria-label="Pat the cat">🐈</button><p id="count">Give your cat a pat.</p><div id="inventory"></div><button id="shop">MY PACKS ↗</button><footer>STANDALONE BUNDLE · SCOPED SDK · FREE PLAY</footer></main><script type="module" src="./game.js"></script></body></html>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { connectGameSdk } from "@vibechain/os";
|
|
2
|
-
const status = document.querySelector<HTMLElement>("#status")!;
|
|
3
|
-
const count = document.querySelector<HTMLElement>("#count")!;
|
|
4
|
-
const cat = document.querySelector<HTMLButtonElement>("#cat")!;
|
|
5
|
-
const inventory = document.querySelector<HTMLElement>("#inventory")!;
|
|
6
|
-
const abort = new AbortController();
|
|
7
|
-
let taps = 0;
|
|
8
|
-
cat.onclick = () => { taps += 1; count.textContent = `${taps} happy pats`; cat.animate([{ transform: "scale(1) rotate(0deg)" }, { transform: "scale(1.15) rotate(-5deg)" }, { transform: "scale(1) rotate(0deg)" }], { duration: 220 }); };
|
|
9
|
-
async function boot() {
|
|
10
|
-
const sdk = await connectGameSdk(abort.signal);
|
|
11
|
-
const refresh = async () => {
|
|
12
|
-
try {
|
|
13
|
-
const [profile, catalog, own] = await Promise.all([sdk.profile.get(), sdk.catalog.list(), sdk.inventory.get()]);
|
|
14
|
-
status.textContent = profile ? `Welcome, ${profile.name}` : "Guest play · connect in VibeMarket for your collection";
|
|
15
|
-
inventory.replaceChildren();
|
|
16
|
-
const label = document.createElement("p");
|
|
17
|
-
label.textContent = `${catalog.length} linked collections · ${own.packs.reduce((sum, pack) => sum + pack.quantity, 0)} packs · ${own.cards.length} cards on this page`;
|
|
18
|
-
inventory.append(label);
|
|
19
|
-
for (const card of own.cards.filter(card => card.state === "collected")) {
|
|
20
|
-
const button = document.createElement("button"); button.textContent = `Equip ${card.name}`;
|
|
21
|
-
button.onclick = () => { cat.style.filter = `hue-rotate(${card.rarity * 55}deg)`; }; inventory.append(button);
|
|
22
|
-
}
|
|
23
|
-
} catch (error) { status.textContent = error instanceof Error ? error.message : "Inventory unavailable"; }
|
|
24
|
-
};
|
|
25
|
-
const unsubscribe = sdk.inventory.onChanged(() => void refresh());
|
|
26
|
-
document.querySelector<HTMLButtonElement>("#shop")!.onclick = () => { void sdk.showShop().catch(error => { status.textContent = String(error); }); };
|
|
27
|
-
window.addEventListener("pagehide", () => { unsubscribe(); sdk.destroy(); abort.abort(); }, { once: true });
|
|
28
|
-
await sdk.ready();
|
|
29
|
-
await refresh();
|
|
30
|
-
}
|
|
31
|
-
void boot().catch(error => { status.textContent = `Open this game through VibeMarket. ${String(error)}`; });
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schemaVersion": 1,
|
|
3
|
-
"sdkVersion": 1,
|
|
4
|
-
"id": "collection-room",
|
|
5
|
-
"version": "1.0.0",
|
|
6
|
-
"name": "Collection Room",
|
|
7
|
-
"tagline": "Your cards. Your cozy corner.",
|
|
8
|
-
"category": "Collect · customize · play",
|
|
9
|
-
"entry": "index.html",
|
|
10
|
-
"permissions": ["profile.get", "catalog.list", "inventory.get"],
|
|
11
|
-
"collectionId": null
|
|
12
|
-
}
|
package/examples/tsconfig.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "Bundler", "lib": ["ES2022", "DOM"], "strict": true, "skipLibCheck": true, "noEmit": true, "allowImportingTsExtensions": true, "paths": { "@vibechain/os": ["../src/index.ts"], "@vibechain/os/loop": ["../src/loop.ts"], "@vibechain/os/canvas": ["../src/canvas.ts"], "@vibechain/os/testing": ["../src/testing.ts"] } },
|
|
3
|
-
"include": ["../tools/*.ts", "../tools/*.mts", "collection-room/main.ts", "chonk-stack/*.ts", "paw-beat/*.ts", "vibexp-app/src/*.ts", "../tests/**/*.ts", "../vitest.config.ts"]
|
|
4
|
-
}
|