Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(play): live community events with countdown, agenda, and fireworks
nirholas66df7e9df61b
diff --git a/pages/play.html b/pages/play.htmlindex cc5ef7670..9893f9286 100644--- a/pages/play.html+++ b/pages/play.html@@ -152,6 +152,7 @@<script type="module" src="/src/game/boot-avatar.js"></script><script type="module" src="/src/game/coincommunities.js"></script><script type="module" src="/src/game/ambient-crowd.js"></script>+ <script type="module" src="/src/game/event-countdown.js"></script><script src="/brand.js" defer></script><!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. --><script type="module" src="/i18n.js"></script>diff --git a/public/event.json b/public/event.jsonnew file mode 100644index 000000000..124eb7a93--- /dev/null+++ b/public/event.json@@ -0,0 +1,8 @@+{+ "name": "$THREE Community Day",+ "tagline": "The whole community, one world. Drop in, hang out, win prizes.",+ "startsAt": "2026-08-08T17:00:00Z",+ "endsAt": "2026-08-08T21:00:00Z",+ "link": "/play?coin=FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump&name=three.ws&symbol=three",+ "linkLabel": "Join the $THREE world"+}diff --git a/public/play-events.json b/public/play-events.jsonnew file mode 100644index 000000000..4e4618850--- /dev/null+++ b/public/play-events.json@@ -0,0 +1,19 @@+{+ "comment": "Scheduled live events for /play. First event with a valid startsAt is the active one. Times are ISO-8601 UTC. Edit + redeploy to reschedule; ?meetup=<ISO> overrides locally for previewing.",+ "events": [+ {+ "id": "three-first-meetup-2026-08-07",+ "title": "$THREE First Holders Meetup",+ "subtitle": "The first live gathering in the three.ws world",+ "startsAt": "2026-08-07T17:00:00Z",+ "durationMin": 90,+ "agenda": [+ { "atMin": 0, "title": "Doors open in the plaza", "detail": "Say hi in chat, show off your fit, grab a commemorative photo", "icon": "👋" },+ { "atMin": 15, "title": "King of the Totem showdown", "detail": "Hold the totem to be crowned. Winner takes the round", "icon": "👑" },+ { "atMin": 35, "title": "Fortune's Folly wheel hour", "detail": "Free spin at the plaza wheel, prizes on every wedge", "icon": "🎡" },+ { "atMin": 55, "title": "Plaza dance-off", "detail": "Q opens emotes. Best moves get screenshotted", "icon": "🕺" },+ { "atMin": 75, "title": "Fireworks finale", "detail": "Look up. Grab your event photo while the sky is lit", "icon": "🎆" }+ ]+ }+ ]+}diff --git a/src/game/event-countdown.js b/src/game/event-countdown.jsnew file mode 100644index 000000000..10619b612--- /dev/null+++ b/src/game/event-countdown.js@@ -0,0 +1,274 @@+// Event countdown for /play: lobby banner + in-world pill.+//+// Self-attaching, like ambient-crowd.js: ZERO edits to coincommunities.js or+// coincommunities-ui.js. It reads /event.json (public/event.json in the repo),+// and while an event is upcoming or live it mounts two views:+//+// 1. A lobby banner at the top of the lobby scroll, with the event name,+// a ticking countdown, the start time in the player's own timezone, and+// a CTA into the event world.+// 2. A compact fixed pill at the top of the screen while the player is+// in-world (the lobby is `hidden`), dismissible per event.+//+// States are explicit: upcoming (countdown ticks), live (pulsing LIVE marker,+// CTA if the player is not already in the event world), and over (everything+// unmounts and the interval stops). A missing or malformed event.json mounts+// nothing; the page owes the player zero pixels when there is no event.++const CONFIG_URL = '/event.json';++function el(tag, attrs = {}, children = []) {+ const n = document.createElement(tag);+ for (const [k, v] of Object.entries(attrs)) {+ if (v == null) continue;+ if (k === 'text') n.textContent = v;+ else if (k === 'html') n.innerHTML = v;+ else if (k.startsWith('on') && typeof v === 'function') n.addEventListener(k.slice(2), v);+ else n.setAttribute(k, v);+ }+ for (const c of children) if (c) n.appendChild(c);+ return n;+}++const STYLE = `+.cc-event-banner {+ display: flex; align-items: center; gap: 14px; flex-wrap: wrap;+ margin: 14px 0 4px; padding: 13px 16px;+ background: var(--cc-panel, rgba(12,12,14,0.78));+ border: 1px solid var(--cc-edge, rgba(255,255,255,0.12));+ border-radius: var(--cc-radius, 4px);+ color: var(--cc-text, #f5f5f6);+}+.cc-event-banner[data-state="live"] { border-color: var(--cc-edge-hi, rgba(255,255,255,0.55)); box-shadow: var(--cc-glow, 0 0 14px rgba(255,255,255,0.35)); }+.cc-event-copy { flex: 1 1 240px; min-width: 0; }+.cc-event-kicker {+ display: inline-flex; align-items: center; gap: 7px;+ font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;+ color: var(--cc-dim, #8c8c92);+}+.cc-event-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cc-live, #fff); }+[data-state="live"] .cc-event-dot { animation: cc-event-pulse 1.2s ease-in-out infinite; }+@media (prefers-reduced-motion: reduce) { [data-state="live"] .cc-event-dot { animation: none; } }+@keyframes cc-event-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.75); } }+.cc-event-name { font-weight: 700; font-size: 16px; margin-top: 3px; }+.cc-event-tagline { color: var(--cc-dim, #8c8c92); font-size: 12.5px; line-height: 1.45; margin-top: 2px; }+.cc-event-when { color: var(--cc-faint, #5a5a60); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }+.cc-event-clock { display: flex; gap: 8px; align-items: baseline; font-variant-numeric: tabular-nums; }+.cc-event-seg { text-align: center; min-width: 40px; }+.cc-event-seg b { display: block; font-size: 22px; font-weight: 700; line-height: 1.1; }+.cc-event-seg span { display: block; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cc-dim, #8c8c92); margin-top: 2px; }+.cc-event-cta {+ display: inline-block; padding: 10px 18px; border-radius: var(--cc-radius, 4px);+ background: var(--cc-accent, #fff); color: var(--cc-ink, #060607);+ font-weight: 600; font-size: 13.5px; text-decoration: none; white-space: nowrap;+ transition: box-shadow 0.15s ease, transform 0.15s ease;+}+.cc-event-cta:hover { box-shadow: var(--cc-glow, 0 0 14px rgba(255,255,255,0.35)); transform: translateY(-1px); }+.cc-event-cta:active { transform: translateY(0); }+.cc-event-cta:focus-visible { outline: 2px solid var(--cc-edge-hi, rgba(255,255,255,0.55)); outline-offset: 2px; }+.cc-event-pill {+ position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 21;+ display: flex; align-items: center; gap: 10px;+ padding: 7px 8px 7px 13px;+ background: var(--cc-panel, rgba(12,12,14,0.78)); backdrop-filter: blur(8px);+ border: 1px solid var(--cc-edge, rgba(255,255,255,0.12));+ border-radius: 999px; color: var(--cc-text, #f5f5f6);+ font-size: 12.5px; font-variant-numeric: tabular-nums;+ transition: opacity 0.25s ease;+}+.cc-event-pill[data-state="live"] { border-color: var(--cc-edge-hi, rgba(255,255,255,0.55)); }+.cc-event-pill a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }+.cc-event-pill a:hover { color: #fff; }+.cc-event-pill a:focus-visible { outline: 2px solid var(--cc-edge-hi, rgba(255,255,255,0.55)); outline-offset: 2px; border-radius: 2px; }+.cc-event-pill-x {+ display: grid; place-items: center; width: 22px; height: 22px;+ border: 0; border-radius: 50%; background: transparent; color: var(--cc-dim, #8c8c92);+ font: inherit; font-size: 14px; line-height: 1; cursor: pointer;+ transition: background 0.15s ease, color 0.15s ease;+}+.cc-event-pill-x:hover { background: rgba(255,255,255,0.12); color: #fff; }+.cc-event-pill-x:active { transform: scale(0.94); }+.cc-event-pill-x:focus-visible { outline: 2px solid var(--cc-edge-hi, rgba(255,255,255,0.55)); outline-offset: 1px; }+body.is-zen .cc-event-pill { opacity: 0; pointer-events: none; }+@media (max-width: 640px) {+ .cc-event-banner { gap: 10px; }+ .cc-event-seg { min-width: 34px; }+ .cc-event-seg b { font-size: 18px; }+ .cc-event-pill { top: auto; bottom: 148px; max-width: calc(100vw - 24px); }+}+`;++function parseConfig(raw) {+ if (!raw || typeof raw !== 'object') return null;+ const startsAt = Date.parse(raw.startsAt);+ if (!Number.isFinite(startsAt)) return null;+ const endsAt = Date.parse(raw.endsAt);+ return {+ name: String(raw.name || 'Live event'),+ tagline: raw.tagline ? String(raw.tagline) : '',+ startsAt,+ // An event with no (or bad) end time stays "live" for 6 hours.+ endsAt: Number.isFinite(endsAt) ? endsAt : startsAt + 6 * 3600 * 1000,+ link: raw.link ? String(raw.link) : null,+ linkLabel: raw.linkLabel ? String(raw.linkLabel) : 'Join the event',+ };+}++// The pill's CTA is pointless when the player is already standing in the event+// world: compare the event link's coin param against the current URL's.+function alreadyAtEvent(cfg) {+ if (!cfg.link) return false;+ try {+ const target = new URL(cfg.link, location.origin);+ const targetCoin = target.searchParams.get('coin');+ const hereCoin = new URLSearchParams(location.search).get('coin');+ return !!targetCoin && targetCoin === hereCoin;+ } catch { return false; }+}++function fmtStart(ts) {+ return new Intl.DateTimeFormat(undefined, {+ weekday: 'short', month: 'short', day: 'numeric',+ hour: 'numeric', minute: '2-digit', timeZoneName: 'short',+ }).format(new Date(ts));+}++function pad(n) { return String(n).padStart(2, '0'); }++function segments(ms) {+ const s = Math.max(0, Math.floor(ms / 1000));+ return {+ d: Math.floor(s / 86400),+ h: Math.floor((s % 86400) / 3600),+ m: Math.floor((s % 3600) / 60),+ s: s % 60,+ };+}++class EventCountdown {+ constructor(cfg) {+ this.cfg = cfg;+ this.dismissKey = 'cc-event-dismissed:' + cfg.startsAt;+ this.banner = null;+ this.pill = null;+ this.timer = 0;+ document.head.appendChild(el('style', { text: STYLE }));+ this._mountBanner();+ this._mountPill();+ this._tick();+ this.timer = setInterval(() => this._tick(), 1000);+ }++ _mountBanner() {+ const inner = document.querySelector('#cc-lobby .cc-lobby-inner');+ if (!inner) return;+ this.bannerClock = el('div', { class: 'cc-event-clock', 'aria-hidden': 'true' });+ this.bannerKicker = el('span', { class: 'cc-event-kicker' }, [+ el('span', { class: 'cc-event-dot', 'aria-hidden': 'true' }),+ this.bannerKickerText = el('span', { text: 'Upcoming event' }),+ ]);+ this.banner = el('section', { class: 'cc-event-banner', 'aria-label': `Event: ${this.cfg.name}` }, [+ el('div', { class: 'cc-event-copy' }, [+ this.bannerKicker,+ el('div', { class: 'cc-event-name', text: this.cfg.name }),+ this.cfg.tagline ? el('div', { class: 'cc-event-tagline', text: this.cfg.tagline }) : null,+ el('div', { class: 'cc-event-when', text: `Starts ${fmtStart(this.cfg.startsAt)}` }),+ ]),+ this.bannerClock,+ this.cfg.link ? el('a', { class: 'cc-event-cta', href: this.cfg.link, text: this.cfg.linkLabel }) : null,+ ]);+ const head = inner.querySelector('.cc-lobby-head');+ inner.insertBefore(this.banner, head ? head.nextSibling : inner.firstChild);+ }++ _mountPill() {+ if (localStorage.getItem(this.dismissKey)) return;+ this.pillText = el('span', { role: 'timer' });+ this.pillLink = this.cfg.link && !alreadyAtEvent(this.cfg)+ ? el('a', { href: this.cfg.link, text: this.cfg.linkLabel })+ : null;+ this.pill = el('div', { class: 'cc-event-pill', role: 'status', hidden: true }, [+ el('span', { class: 'cc-event-dot', 'aria-hidden': 'true' }),+ this.pillText,+ this.pillLink,+ el('button', {+ type: 'button', class: 'cc-event-pill-x', 'aria-label': 'Dismiss event reminder', title: 'Dismiss',+ onclick: () => {+ localStorage.setItem(this.dismissKey, '1');+ this.pill.remove();+ this.pill = null;+ },+ }, [el('span', { 'aria-hidden': 'true', text: '×' })]),+ ]);+ document.body.appendChild(this.pill);+ }++ _tick() {+ const now = Date.now();+ if (now >= this.cfg.endsAt) return this.destroy();+ const live = now >= this.cfg.startsAt;+ const state = live ? 'live' : 'upcoming';++ if (this.banner) {+ this.banner.setAttribute('data-state', state);+ this.bannerKickerText.textContent = live ? 'Live now' : 'Upcoming event';+ if (live) {+ this.bannerClock.replaceChildren(+ el('div', { class: 'cc-event-seg' }, [el('b', { text: 'LIVE' }), el('span', { text: 'right now' })]),+ );+ } else {+ const t = segments(this.cfg.startsAt - now);+ const segs = [];+ if (t.d > 0) segs.push(['' + t.d, t.d === 1 ? 'day' : 'days']);+ segs.push([pad(t.h), 'hrs'], [pad(t.m), 'min'], [pad(t.s), 'sec']);+ this.bannerClock.replaceChildren(...segs.map(([v, label]) =>+ el('div', { class: 'cc-event-seg' }, [el('b', { text: v }), el('span', { text: label })])));+ }+ }++ if (this.pill) {+ // Only show the pill in-world; the lobby already has the full banner.+ const lobby = document.getElementById('cc-lobby');+ this.pill.hidden = !lobby || !lobby.hidden;+ this.pill.setAttribute('data-state', state);+ if (live) {+ this.pillText.textContent = `${this.cfg.name} · LIVE`;+ } else {+ const t = segments(this.cfg.startsAt - now);+ const clock = (t.d > 0 ? `${t.d}d ` : '') + `${pad(t.h)}:${pad(t.m)}:${pad(t.s)}`;+ this.pillText.textContent = `${this.cfg.name} · ${clock}`;+ }+ }+ }++ destroy() {+ clearInterval(this.timer);+ this.banner?.remove();+ this.pill?.remove();+ this.banner = this.pill = null;+ }+}++async function boot() {+ let cfg = null;+ try {+ const res = await fetch(CONFIG_URL, { cache: 'no-cache' });+ if (!res.ok) return;+ cfg = parseConfig(await res.json());+ } catch { return; }+ if (!cfg || Date.now() >= cfg.endsAt) return;++ // The lobby is built by coincommunities.js at boot; wait for it to exist so+ // the banner has somewhere to mount. If it never shows up (boot failure),+ // give up quietly after 20s; the watchdog in play.html owns that story.+ const started = Date.now();+ (function waitForLobby() {+ if (document.querySelector('#cc-lobby .cc-lobby-inner')) {+ new EventCountdown(cfg);+ } else if (Date.now() - started < 20000) {+ setTimeout(waitForLobby, 250);+ }+ })();+}++boot();diff --git a/src/game/fireworks.js b/src/game/fireworks.jsnew file mode 100644index 000000000..49ddccf2c--- /dev/null+++ b/src/game/fireworks.js@@ -0,0 +1,162 @@+// Fireworks: a cheap, pretty particle fireworks system for the /play plaza.+//+// Each burst is ONE THREE.Points object (shell ascent + explosion sharing a+// buffer), additive-blended so overlapping shows glow instead of muddying, and+// fully disposed when spent. Simulation is analytic per-frame (position from+// velocity + gravity), so a hundred sparks cost one attribute upload per burst+// per frame and zero allocations after launch.+//+// Callers own the schedule (see meetup-schedule.js fireworkPlan for the+// deterministic show every client agrees on) and call launch(); this module+// owns only the visuals.++import {+ AdditiveBlending, BufferAttribute, BufferGeometry, Color, Group,+ Points, PointsMaterial, PointLight,+} from 'three';++// Warm celebratory palettes; index picked by the deterministic plan.+const PALETTES = [+ [0xffd76a, 0xffb347], // gold+ [0x8de6a8, 0x2fd483], // mint green+ [0x9ecbff, 0x4d8dff], // ice blue+ [0xff9de2, 0xff4da6], // pink+ [0xc7a6ff, 0x8a5cff], // violet+ [0xfff2b3, 0xffffff], // white-gold+];++const GRAVITY = -9.5;+const SPARKS = 90;++export class Fireworks {+ /** @param {{scene: import('three').Scene}} opts */+ constructor({ scene }) {+ this.scene = scene;+ this.group = new Group();+ this.group.name = 'fireworks';+ this.scene.add(this.group);+ this._bursts = [];+ this._lights = [];+ }++ // Launch a shell from (x, 0, z) that detonates at `apex` meters.+ launch(x, z, { apex = 20, palette = 0 } = {}) {+ const colors = PALETTES[((palette % PALETTES.length) + PALETTES.length) % PALETTES.length];+ const geo = new BufferGeometry();+ const pos = new Float32Array(SPARKS * 3);+ const vel = new Float32Array(SPARKS * 3);+ const col = new Float32Array(SPARKS * 3);+ const c1 = new Color(colors[0]);+ const c2 = new Color(colors[1]);+ for (let i = 0; i < SPARKS; i++) {+ pos[i * 3] = x; pos[i * 3 + 1] = 0.5; pos[i * 3 + 2] = z;+ // Explosion velocities: roughly spherical with slight upward bias.+ const theta = Math.random() * Math.PI * 2;+ const phi = Math.acos(2 * Math.random() - 1);+ const speed = 4.5 + Math.random() * 5.5;+ vel[i * 3] = Math.sin(phi) * Math.cos(theta) * speed;+ vel[i * 3 + 1] = Math.abs(Math.cos(phi)) * speed * 0.9 + 1.5;+ vel[i * 3 + 2] = Math.sin(phi) * Math.sin(theta) * speed;+ const c = Math.random() < 0.65 ? c1 : c2;+ col[i * 3] = c.r; col[i * 3 + 1] = c.g; col[i * 3 + 2] = c.b;+ }+ geo.setAttribute('position', new BufferAttribute(pos, 3));+ geo.setAttribute('color', new BufferAttribute(col, 3));+ const mat = new PointsMaterial({+ size: 0.55, vertexColors: true, transparent: true, opacity: 1,+ blending: AdditiveBlending, depthWrite: false, sizeAttenuation: true,+ });+ const points = new Points(geo, mat);+ points.frustumCulled = false;+ this.group.add(points);+ this._bursts.push({+ points, geo, mat, vel,+ x, z, apex,+ age: 0,+ riseTime: 0.9 + Math.random() * 0.3, // shell ascent duration+ burstTtl: 1.9, // spark life after detonation+ exploded: false,+ });+ return true;+ }++ // A brief colored flash on the ground under a detonation sells the light+ // without a real point light per spark. One pooled light, reused.+ _flash(x, z, colorHex) {+ let light = this._lights.find((l) => l.ttl <= 0);+ if (!light) {+ if (this._lights.length >= 3) return; // cap: never more than 3 live lights+ light = { obj: new PointLight(0xffffff, 0, 60, 1.8), ttl: 0 };+ this.group.add(light.obj);+ this._lights.push(light);+ }+ light.obj.color.set(colorHex);+ light.obj.position.set(x, 14, z);+ light.obj.intensity = 90;+ light.ttl = 0.45;+ }++ tick(dt) {+ for (const l of this._lights) {+ if (l.ttl > 0) {+ l.ttl -= dt;+ l.obj.intensity = Math.max(0, l.obj.intensity - dt * 220);+ }+ }+ if (!this._bursts.length) return;+ for (let i = this._bursts.length - 1; i >= 0; i--) {+ const b = this._bursts[i];+ b.age += dt;+ const posAttr = b.geo.getAttribute('position');+ const pos = posAttr.array;+ if (!b.exploded) {+ // Shell ascent: all sparks ride together as one bright dot.+ const t = Math.min(1, b.age / b.riseTime);+ const y = 0.5 + (b.apex - 0.5) * (1 - (1 - t) * (1 - t)); // ease-out climb+ for (let p = 0; p < SPARKS; p++) pos[p * 3 + 1] = y;+ if (t >= 1) {+ b.exploded = true;+ b.age = 0;+ // Re-anchor sparks at the apex; velocities take over from here.+ for (let p = 0; p < SPARKS; p++) { pos[p * 3] = b.x; pos[p * 3 + 2] = b.z; }+ const col = b.geo.getAttribute('color').array;+ this._flash(b.x, b.z, new Color(col[0], col[1], col[2]).getHex());+ }+ } else {+ const drag = Math.max(0, 1 - dt * 0.9);+ for (let p = 0; p < SPARKS; p++) {+ b.vel[p * 3] *= drag;+ b.vel[p * 3 + 1] = b.vel[p * 3 + 1] * drag + GRAVITY * dt;+ b.vel[p * 3 + 2] *= drag;+ pos[p * 3] += b.vel[p * 3] * dt;+ pos[p * 3 + 1] += b.vel[p * 3 + 1] * dt;+ pos[p * 3 + 2] += b.vel[p * 3 + 2] * dt;+ }+ b.mat.opacity = Math.max(0, 1 - b.age / b.burstTtl);+ b.mat.size = 0.55 * (1 - 0.4 * (b.age / b.burstTtl));+ if (b.age >= b.burstTtl) {+ this.group.remove(b.points);+ b.geo.dispose();+ b.mat.dispose();+ this._bursts.splice(i, 1);+ continue;+ }+ }+ posAttr.needsUpdate = true;+ }+ }++ get liveCount() { return this._bursts.length; }++ dispose() {+ for (const b of this._bursts) {+ this.group.remove(b.points);+ b.geo.dispose();+ b.mat.dispose();+ }+ this._bursts = [];+ for (const l of this._lights) this.group.remove(l.obj);+ this._lights = [];+ this.scene.remove(this.group);+ }+}diff --git a/src/game/meetup-event.css b/src/game/meetup-event.cssnew file mode 100644index 000000000..4292466ff--- /dev/null+++ b/src/game/meetup-event.css@@ -0,0 +1,155 @@+/* ── Meetup events (countdown chip, live banner, agenda, photo) ──────────────+ Shares the coincommunities design tokens; gold (#ffce5c) is the established+ "event moment" accent (King of the Totem) and marks the meetup the same way. */++#cc-meetup-chip {+ position: fixed; top: 12px; left: 50%; transform: translateX(-50%);+ z-index: 40;+ display: flex; align-items: center; gap: 9px;+ background: var(--cc-panel);+ border: 1px solid var(--cc-edge);+ border-radius: var(--cc-radius);+ box-shadow: var(--cc-shadow);+ padding: 7px 12px;+ backdrop-filter: blur(8px);+ cursor: pointer;+ transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;+ animation: cc-fade 0.25s ease;+ max-width: calc(100vw - 24px);+}+#cc-meetup-chip:hover { border-color: rgba(255, 206, 92, 0.55); box-shadow: var(--cc-shadow), 0 0 18px rgba(255, 206, 92, 0.18); }+#cc-meetup-chip:active { transform: translateX(-50%) scale(0.98); }+#cc-meetup-chip:focus-visible { outline: 2px solid #ffce5c; outline-offset: 2px; }+.cc-meetup-ico { font-size: 15px; line-height: 1; filter: drop-shadow(0 0 6px rgba(255, 206, 92, 0.5)); }+.cc-meetup-copy { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }+.cc-meetup-title {+ font-size: 10px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;+ color: #ffce5c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;+}+.cc-meetup-when {+ font-size: 13px; font-weight: 800; color: var(--cc-text);+ font-variant-numeric: tabular-nums; white-space: nowrap;+}+.cc-meetup-when .cc-meetup-live-dot {+ display: inline-block; width: 7px; height: 7px; border-radius: 50%;+ background: #ffce5c; margin-right: 6px; vertical-align: 1px;+ box-shadow: 0 0 8px rgba(255, 206, 92, 0.8);+ animation: cc-meetup-pulse 1.4s ease-in-out infinite;+}+@keyframes cc-meetup-pulse { 50% { opacity: 0.35; } }+#cc-meetup-chip.cc-meetup-preshow { border-color: rgba(255, 206, 92, 0.45); }+#cc-meetup-chip.cc-meetup-islive { border-color: rgba(255, 206, 92, 0.6); box-shadow: var(--cc-shadow), 0 0 22px rgba(255, 206, 92, 0.22); }++/* Centre-screen moment flash (event start, segment changes, finale). */+#cc-meetup-banner {+ position: fixed; top: 24%; left: 50%; transform: translateX(-50%) scale(0.82);+ z-index: 200; pointer-events: none; text-align: center;+ background: linear-gradient(160deg, rgba(40, 32, 8, 0.94), rgba(18, 14, 4, 0.94));+ border: 1px solid rgba(255, 206, 92, 0.55);+ color: #fff; padding: 18px 40px; border-radius: 16px;+ box-shadow: 0 0 50px rgba(255, 206, 92, 0.4);+ opacity: 0;+ transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.22, 1.2, 0.36, 1);+ max-width: min(88vw, 560px);+}+#cc-meetup-banner.cc-meetup-banner--show { opacity: 1; transform: translateX(-50%) scale(1); }+.cc-meetup-banner-ico { font-size: 40px; line-height: 1; filter: drop-shadow(0 0 14px rgba(255, 206, 92, 0.7)); }+.cc-meetup-banner-title { font-size: 21px; font-weight: 900; letter-spacing: 0.01em; margin-top: 6px; }+.cc-meetup-banner-sub { font-size: 13.5px; font-weight: 600; color: #ffce5c; margin-top: 4px; }++/* Right-docked agenda drawer. */+#cc-meetup-panel {+ position: fixed; top: 0; right: 0; bottom: 0; z-index: 120;+ width: min(340px, 92vw);+ display: flex; flex-direction: column;+ background: var(--cc-panel-solid);+ border-left: 1px solid var(--cc-edge);+ box-shadow: var(--cc-shadow);+ transform: translateX(102%);+ transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);+}+#cc-meetup-panel.cc-meetup-panel--open { transform: translateX(0); }+.cc-meetup-panel-head {+ display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;+ padding: 16px 16px 12px; border-bottom: 1px solid var(--cc-edge);+}+.cc-meetup-panel-title { font-size: 14px; font-weight: 900; color: var(--cc-text); line-height: 1.3; }+.cc-meetup-panel-sub { font-size: 11.5px; color: var(--cc-dim); margin-top: 3px; line-height: 1.45; }+.cc-meetup-panel-when { font-size: 11px; font-weight: 700; color: #ffce5c; margin-top: 6px; font-variant-numeric: tabular-nums; }+.cc-meetup-close {+ flex: none; width: 26px; height: 26px; border-radius: var(--cc-radius-sm);+ background: transparent; border: 1px solid var(--cc-edge); color: var(--cc-dim);+ font-size: 13px; line-height: 1; cursor: pointer;+ transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;+}+.cc-meetup-close:hover { color: var(--cc-text); border-color: var(--cc-edge-hi); background: rgba(255, 255, 255, 0.06); }+.cc-meetup-close:focus-visible { outline: 2px solid #ffce5c; outline-offset: 1px; }++.cc-meetup-agenda { flex: 1; overflow-y: auto; padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 4px; }+.cc-meetup-seg {+ display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start;+ padding: 9px 10px; border-radius: var(--cc-radius);+ border: 1px solid transparent;+ transition: background 0.18s ease, border-color 0.18s ease;+}+.cc-meetup-seg-ico { font-size: 16px; line-height: 1.2; text-align: center; }+.cc-meetup-seg-title { font-size: 12.5px; font-weight: 700; color: var(--cc-text); line-height: 1.35; }+.cc-meetup-seg-detail { font-size: 11px; color: var(--cc-dim); margin-top: 2px; line-height: 1.45; }+.cc-meetup-seg-at { font-size: 10.5px; font-weight: 700; color: var(--cc-faint); font-variant-numeric: tabular-nums; padding-top: 1px; }+.cc-meetup-seg--done { opacity: 0.45; }+.cc-meetup-seg--active {+ background: rgba(255, 206, 92, 0.1);+ border-color: rgba(255, 206, 92, 0.35);+}+.cc-meetup-seg--active .cc-meetup-seg-at { color: #ffce5c; }++.cc-meetup-panel-foot { border-top: 1px solid var(--cc-edge); padding: 12px; display: flex; flex-direction: column; gap: 8px; }++/* $THREE pulse row: price + 24h change, real data or hidden. */+.cc-meetup-pulse {+ display: flex; align-items: center; justify-content: space-between; gap: 8px;+ font-size: 11.5px; color: var(--cc-dim);+ padding: 8px 10px; border: 1px solid var(--cc-edge); border-radius: var(--cc-radius);+}+.cc-meetup-pulse b { color: var(--cc-text); font-weight: 800; font-variant-numeric: tabular-nums; }+.cc-meetup-pulse .cc-meetup-up { color: #8de6a8; font-weight: 800; }+.cc-meetup-pulse .cc-meetup-down { color: #ff6b6b; font-weight: 800; }++.cc-meetup-photo-btn, .cc-meetup-buy-btn {+ display: flex; align-items: center; justify-content: center; gap: 8px;+ width: 100%; padding: 9px 12px; border-radius: var(--cc-radius);+ font-size: 12px; font-weight: 800; letter-spacing: 0.04em;+ cursor: pointer; transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;+}+.cc-meetup-photo-btn {+ background: rgba(255, 255, 255, 0.06); color: var(--cc-text);+ border: 1px solid var(--cc-edge);+}+.cc-meetup-photo-btn:hover { background: rgba(255, 255, 255, 0.11); border-color: var(--cc-edge-hi); }+.cc-meetup-photo-btn:active { transform: scale(0.98); }+.cc-meetup-photo-btn:focus-visible, .cc-meetup-buy-btn:focus-visible { outline: 2px solid #ffce5c; outline-offset: 2px; }+.cc-meetup-buy-btn {+ background: linear-gradient(160deg, #ffe9ad, #ffce5c); color: #241a02;+ border: 1px solid rgba(255, 206, 92, 0.8);+ box-shadow: 0 0 16px rgba(255, 206, 92, 0.25);+}+.cc-meetup-buy-btn:hover { box-shadow: 0 0 26px rgba(255, 206, 92, 0.45); }+.cc-meetup-buy-btn:active { transform: scale(0.98); }++/* Photo flash + confetti burst layer. */+#cc-meetup-flash {+ position: fixed; inset: 0; z-index: 400; pointer-events: none;+ background: #fff; opacity: 0; transition: opacity 0.5s ease;+}+#cc-meetup-flash.cc-meetup-flash--on { opacity: 0.85; transition: none; }++@media (max-width: 640px) {+ .cc-meetup-title { max-width: 38vw; }+ #cc-meetup-banner { padding: 14px 26px; }+ .cc-meetup-banner-title { font-size: 17px; }+ .cc-meetup-banner-ico { font-size: 32px; }+}+@media (prefers-reduced-motion: reduce) {+ .cc-meetup-when .cc-meetup-live-dot { animation: none; }+ #cc-meetup-panel { transition: none; }+}diff --git a/src/game/meetup-schedule.js b/src/game/meetup-schedule.jsnew file mode 100644index 000000000..a18eb219b--- /dev/null+++ b/src/game/meetup-schedule.js@@ -0,0 +1,153 @@+// Meetup event schedule: the pure logic behind /play's live community events.+//+// A meetup is a scheduled window in wall-clock time with an ordered agenda of+// segments (welcome, totem showdown, wheel hour, dance-off, fireworks finale...).+// Every client derives the SAME phase from the same config and the same wall+// clock, with no server round-trip and no per-client state: two holders standing+// in the plaza always agree on what is happening and what comes next, the same+// trick src/shared/world-clock.js uses for the shared sky.+//+// Kept free of DOM/three imports so it is unit-testable and reusable by any+// surface that wants to render the event (HUD, landing page, jumbotron).++// Phases, in chronological order.+export const PHASE = {+ FAR: 'far', // more than SOON_MS before start: chip hidden+ UPCOMING: 'upcoming', // countdown chip visible+ PRESHOW: 'preshow', // final PRESHOW_MS: chip pulses, stage lights up+ LIVE: 'live', // event window: agenda runs+ AFTERGLOW: 'afterglow', // just ended: thanks + photo prompt linger+ ENDED: 'ended', // all trace gone+};++export const SOON_MS = 24 * 60 * 60 * 1000; // chip appears a day out+export const PRESHOW_MS = 30 * 60 * 1000; // stage powers up 30 min early+export const AFTERGLOW_MS = 20 * 60 * 1000; // linger 20 min after the end++// Parse one event out of a play-events.json document. Returns null when there+// is nothing valid to run, so callers can treat "no events" and "bad config"+// identically (the world simply stays normal).+export function parseEvent(doc) {+ const raw = Array.isArray(doc?.events) ? doc.events.find((e) => e && e.startsAt) : null;+ if (!raw) return null;+ const startsAt = Date.parse(raw.startsAt);+ if (!Number.isFinite(startsAt)) return null;+ const durationMin = Number(raw.durationMin);+ const durationMs = (Number.isFinite(durationMin) && durationMin > 0 ? durationMin : 60) * 60 * 1000;+ const agenda = (Array.isArray(raw.agenda) ? raw.agenda : [])+ .map((seg) => ({+ atMin: Number(seg?.atMin),+ title: String(seg?.title || '').slice(0, 80),+ detail: String(seg?.detail || '').slice(0, 200),+ icon: String(seg?.icon || '').slice(0, 8),+ // Optional world-space anchor a client can drop a waypoint on.+ x: Number.isFinite(Number(seg?.x)) ? Number(seg.x) : null,+ z: Number.isFinite(Number(seg?.z)) ? Number(seg.z) : null,+ }))+ .filter((seg) => Number.isFinite(seg.atMin) && seg.atMin >= 0 && seg.title)+ .sort((a, b) => a.atMin - b.atMin);+ return {+ id: String(raw.id || 'meetup').slice(0, 64),+ title: String(raw.title || 'Community meetup').slice(0, 120),+ subtitle: String(raw.subtitle || '').slice(0, 160),+ startsAt,+ endsAt: startsAt + durationMs,+ agenda,+ };+}++// The full derived state for a moment in time. Everything the UI needs in one+// pure call: phase, countdown, the active + next agenda segments, and progress.+export function eventState(event, now) {+ if (!event) return { phase: PHASE.ENDED, event: null };+ const t = Number(now) || 0;+ const { startsAt, endsAt } = event;+ let phase;+ if (t < startsAt - SOON_MS) phase = PHASE.FAR;+ else if (t < startsAt - PRESHOW_MS) phase = PHASE.UPCOMING;+ else if (t < startsAt) phase = PHASE.PRESHOW;+ else if (t < endsAt) phase = PHASE.LIVE;+ else if (t < endsAt + AFTERGLOW_MS) phase = PHASE.AFTERGLOW;+ else phase = PHASE.ENDED;++ const minsIn = (t - startsAt) / 60000;+ let active = null;+ let next = null;+ if (phase === PHASE.LIVE) {+ for (const seg of event.agenda) {+ if (seg.atMin <= minsIn) active = seg;+ else { next = seg; break; }+ }+ } else if (phase === PHASE.UPCOMING || phase === PHASE.PRESHOW || phase === PHASE.FAR) {+ next = event.agenda[0] || null;+ }++ return {+ phase,+ event,+ msToStart: Math.max(0, startsAt - t),+ msToEnd: Math.max(0, endsAt - t),+ progress: phase === PHASE.LIVE ? Math.min(1, Math.max(0, (t - startsAt) / (endsAt - startsAt))) : 0,+ active,+ next,+ msToNext: next ? Math.max(0, startsAt + next.atMin * 60000 - t) : 0,+ };+}++// "2h 14m", "14m 09s", "0:07": a countdown that reads naturally at every+// distance instead of one fixed format that is wrong at most of them.+export function formatCountdown(ms) {+ const s = Math.max(0, Math.floor((Number(ms) || 0) / 1000));+ const h = Math.floor(s / 3600);+ const m = Math.floor((s % 3600) / 60);+ const sec = s % 60;+ if (h > 0) return `${h}h ${String(m).padStart(2, '0')}m`;+ if (m >= 10) return `${m}m`;+ if (m > 0) return `${m}m ${String(sec).padStart(2, '0')}s`;+ return `0:${String(sec).padStart(2, '0')}`;+}++// Deterministic firework schedule. Time is cut into fixed buckets; each bucket+// hashes (with the event id as seed) into the same launch plan on every client,+// so the whole plaza watches one synchronized show without a single packet.+// Returns launches due within the bucket as offsets, positions on a ring, and+// palette indexes. `rate` bursts per bucket on average; finale cranks it.+const BUCKET_MS = 4000;++function hash32(str) {+ let h = 2166136261 >>> 0;+ for (let i = 0; i < str.length; i++) {+ h ^= str.charCodeAt(i);+ h = Math.imul(h, 16777619);+ }+ return h >>> 0;+}++function mulberry32(seed) {+ let a = seed >>> 0;+ return () => {+ a |= 0; a = (a + 0x6D2B79F5) | 0;+ let t = Math.imul(a ^ (a >>> 15), 1 | a);+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;+ };+}++export function fireworkPlan(eventId, bucketStartMs, { intensity = 1 } = {}) {+ const bucket = Math.floor(bucketStartMs / BUCKET_MS);+ const rand = mulberry32(hash32(`${eventId}:${bucket}`));+ const count = Math.max(intensity >= 1 ? 1 : 0, Math.round(rand() * 2 * intensity));+ const launches = [];+ for (let i = 0; i < count; i++) {+ launches.push({+ atMs: bucket * BUCKET_MS + Math.floor(rand() * BUCKET_MS),+ angle: rand() * Math.PI * 2, // position on the launch ring+ radius: 0.55 + rand() * 0.45, // fraction of the ring radius+ palette: Math.floor(rand() * 6),+ apex: 16 + rand() * 10, // burst height in meters+ });+ }+ return launches;+}++export { BUCKET_MS };diff --git a/tests/meetup-schedule.test.js b/tests/meetup-schedule.test.jsnew file mode 100644index 000000000..710adbe16--- /dev/null+++ b/tests/meetup-schedule.test.js@@ -0,0 +1,143 @@+import { describe, it, expect } from 'vitest';+import {+ parseEvent, eventState, formatCountdown, fireworkPlan,+ PHASE, SOON_MS, PRESHOW_MS, AFTERGLOW_MS, BUCKET_MS,+} from '../src/game/meetup-schedule.js';++const START = Date.parse('2026-08-07T17:00:00Z');++const DOC = {+ events: [{+ id: 'three-first-meetup',+ title: '$THREE First Holders Meetup',+ subtitle: 'The first live gathering in the world',+ startsAt: '2026-08-07T17:00:00Z',+ durationMin: 90,+ agenda: [+ { atMin: 0, title: 'Welcome to the plaza', icon: '👋' },+ { atMin: 15, title: 'King of the Totem showdown', icon: '👑', x: 10, z: -5 },+ { atMin: 40, title: 'Wheel hour', icon: '🎡' },+ { atMin: 75, title: 'Fireworks finale', icon: '🎆' },+ ],+ }],+};++describe('parseEvent', () => {+ it('parses a valid event with sorted agenda and computed end', () => {+ const ev = parseEvent(DOC);+ expect(ev.id).toBe('three-first-meetup');+ expect(ev.startsAt).toBe(START);+ expect(ev.endsAt).toBe(START + 90 * 60000);+ expect(ev.agenda).toHaveLength(4);+ expect(ev.agenda[1].x).toBe(10);+ expect(ev.agenda[0].x).toBeNull();+ });++ it('sorts an out-of-order agenda and drops invalid segments', () => {+ const ev = parseEvent({+ events: [{+ startsAt: '2026-08-07T17:00:00Z',+ agenda: [+ { atMin: 30, title: 'B' },+ { atMin: 0, title: 'A' },+ { atMin: 'nope', title: 'bad' },+ { atMin: 5, title: '' },+ ],+ }],+ });+ expect(ev.agenda.map((s) => s.title)).toEqual(['A', 'B']);+ });++ it('returns null for empty, malformed, or dateless docs', () => {+ expect(parseEvent(null)).toBeNull();+ expect(parseEvent({})).toBeNull();+ expect(parseEvent({ events: [] })).toBeNull();+ expect(parseEvent({ events: [{ startsAt: 'not a date' }] })).toBeNull();+ });++ it('defaults duration to 60 minutes when missing or invalid', () => {+ const ev = parseEvent({ events: [{ startsAt: '2026-08-07T17:00:00Z', durationMin: -3 }] });+ expect(ev.endsAt - ev.startsAt).toBe(60 * 60000);+ });+});++describe('eventState phases', () => {+ const ev = parseEvent(DOC);++ it('walks through every phase in order', () => {+ expect(eventState(ev, START - SOON_MS - 1).phase).toBe(PHASE.FAR);+ expect(eventState(ev, START - SOON_MS + 1).phase).toBe(PHASE.UPCOMING);+ expect(eventState(ev, START - PRESHOW_MS + 1).phase).toBe(PHASE.PRESHOW);+ expect(eventState(ev, START).phase).toBe(PHASE.LIVE);+ expect(eventState(ev, ev.endsAt - 1).phase).toBe(PHASE.LIVE);+ expect(eventState(ev, ev.endsAt + 1).phase).toBe(PHASE.AFTERGLOW);+ expect(eventState(ev, ev.endsAt + AFTERGLOW_MS + 1).phase).toBe(PHASE.ENDED);+ });++ it('handles a null event as ended', () => {+ expect(eventState(null, START).phase).toBe(PHASE.ENDED);+ });++ it('counts down to start', () => {+ const s = eventState(ev, START - 90_000);+ expect(s.msToStart).toBe(90_000);+ expect(s.next.title).toBe('Welcome to the plaza');+ });++ it('tracks the active and next segments while live', () => {+ const s = eventState(ev, START + 16 * 60000);+ expect(s.active.title).toBe('King of the Totem showdown');+ expect(s.next.title).toBe('Wheel hour');+ expect(s.msToNext).toBe((40 - 16) * 60000);+ });++ it('has no next segment after the last one', () => {+ const s = eventState(ev, START + 80 * 60000);+ expect(s.active.title).toBe('Fireworks finale');+ expect(s.next).toBeNull();+ });++ it('reports live progress', () => {+ const s = eventState(ev, START + 45 * 60000);+ expect(s.progress).toBeCloseTo(0.5, 5);+ });+});++describe('formatCountdown', () => {+ it('formats each distance naturally', () => {+ expect(formatCountdown(2 * 3600000 + 14 * 60000)).toBe('2h 14m');+ expect(formatCountdown(14 * 60000 + 9000)).toBe('14m');+ expect(formatCountdown(4 * 60000 + 9000)).toBe('4m 09s');+ expect(formatCountdown(7000)).toBe('0:07');+ expect(formatCountdown(0)).toBe('0:00');+ expect(formatCountdown(-500)).toBe('0:00');+ });+});++describe('fireworkPlan', () => {+ it('is deterministic for the same event and bucket', () => {+ const a = fireworkPlan('three-first-meetup', 1_000_000);+ const b = fireworkPlan('three-first-meetup', 1_000_000);+ expect(a).toEqual(b);+ });++ it('differs across buckets and events', () => {+ const base = JSON.stringify(fireworkPlan('ev', 0, { intensity: 2 }));+ expect(JSON.stringify(fireworkPlan('ev', BUCKET_MS, { intensity: 2 }))).not.toBe(base);+ expect(JSON.stringify(fireworkPlan('other', 0, { intensity: 2 }))).not.toBe(base);+ });++ it('always launches at least one burst at full intensity', () => {+ for (let i = 0; i < 20; i++) {+ expect(fireworkPlan('ev', i * BUCKET_MS, { intensity: 1 }).length).toBeGreaterThan(0);+ }+ });++ it('keeps launches inside their bucket window', () => {+ for (const l of fireworkPlan('ev', 8 * BUCKET_MS, { intensity: 3 })) {+ expect(l.atMs).toBeGreaterThanOrEqual(8 * BUCKET_MS);+ expect(l.atMs).toBeLessThan(9 * BUCKET_MS);+ expect(l.apex).toBeGreaterThan(10);+ }+ });+});