Skip to content

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.

feat: shop collection tab, buy confirm, tint blend, schema guards

nirholasa5399eb86e24
diff --git a/api/friends/index.js b/api/friends/index.js
index d574add36..0ab023f46 100644
--- a/api/friends/index.js
+++ b/api/friends/index.js
@@ -82,7 +82,16 @@ export default wrap(async (req, res) => {
});
async function graphWithPresence(me) {
- const graph = await listGraph(me);
+ let graph;
+ try {
+ graph = await listGraph(me);
+ } catch (err) {
+ // Friends tables may not be migrated yet — return an empty graph rather than 500.
+ if (err?.message?.includes('relation') || err?.message?.includes('does not exist')) {
+ return { friends: [], incoming: [], outgoing: [] };
+ }
+ throw err;
+ }
const ids = [
...graph.friends.map((f) => f.id),
...graph.incoming.map((f) => f.id),
diff --git a/deploy/world/cloudrun.yaml b/deploy/world/cloudrun.yaml
index 5b48abc04..f2ff74355 100644
--- a/deploy/world/cloudrun.yaml
+++ b/deploy/world/cloudrun.yaml
@@ -59,6 +59,11 @@ spec:
value: /world/assets
- name: ASSETS_BASE_URL
value: https://world.three.ws/assets
+ - name: JWT_SECRET
+ valueFrom:
+ secretKeyRef:
+ name: hyperfy-jwt-secret
+ key: latest
resources:
limits:
cpu: "2"
diff --git a/scripts/verify-chat-commands.mjs b/scripts/verify-chat-commands.mjs
index 4ede6c5ae..c2f772286 100644
--- a/scripts/verify-chat-commands.mjs
+++ b/scripts/verify-chat-commands.mjs
@@ -117,9 +117,7 @@ check(await page.locator('#kg-chat-hint').isHidden(), 'mouse pick completes + cl
// Seed the history directly via the game instance (net is offline so chat() is a no-op).
await page.evaluate(() => {
const g = window.__ISO__;
- if (!g._chatHistory) g._chatHistory = [];
- g._chatHistory.push('hello realm');
- g._chatHistory.push('/who');
+ g._chatHistory = ['hello realm', '/who']; // reset to a known state
g._chatHistoryCursor = -1;
g._chatHistoryDraft = '';
});
diff --git a/src/game/community-net.js b/src/game/community-net.js
index 03a27fe40..7b0c7d800 100644
--- a/src/game/community-net.js
+++ b/src/game/community-net.js
@@ -187,40 +187,52 @@ export class CommunityNet {
this.room.onMessage('edit-reject', (msg) => this._emit('editReject', msg || {}));
const $ = getStateCallbacks(this.room);
- $(this.room.state).players.onAdd((player, id) => {
- this._emit('add', player, id);
- $(player).onChange(() => {
- // The server echoes our own authoritative state back after each
- // move; the gap from send → echo is a real network+server RTT.
- if (id === this.sessionId && this._pingSentAt) {
- const rtt = performance.now() - this._pingSentAt;
- this._pingSentAt = 0;
- if (rtt > 0 && rtt < 5000) {
- this.ping = this.ping == null ? rtt : this.ping * 0.7 + rtt * 0.3;
- this._emit('ping', Math.round(this.ping));
+ const $state = $(this.room.state);
+
+ // Guard each collection: if the server is running an older schema that
+ // doesn't include a field yet, the proxy returns undefined for that key
+ // and calling .onAdd() on undefined throws — breaking the connect loop.
+ const $players = $state?.players;
+ if ($players) {
+ $players.onAdd((player, id) => {
+ this._emit('add', player, id);
+ $(player).onChange(() => {
+ // The server echoes our own authoritative state back after each
+ // move; the gap from send → echo is a real network+server RTT.
+ if (id === this.sessionId && this._pingSentAt) {
+ const rtt = performance.now() - this._pingSentAt;
+ this._pingSentAt = 0;
+ if (rtt > 0 && rtt < 5000) {
+ this.ping = this.ping == null ? rtt : this.ping * 0.7 + rtt * 0.3;
+ this._emit('ping', Math.round(this.ping));
+ }
}
- }
- this._emit('change', player, id);
+ this._emit('change', player, id);
+ });
});
- });
- $(this.room.state).players.onRemove((_p, id) => this._emit('remove', id));
+ $players.onRemove((_p, id) => this._emit('remove', id));
+ }
// Voxel builds: the server is authoritative for every block, so the
// world's geometry is driven entirely by these state callbacks — local
// place/break clicks only *send*; the block appears when the server
// echoes it back, keeping every client's build identical. onAdd fires
// for the full persisted build at join time and for each new placement.
- $(this.room.state).blocks.onAdd((block, key) => {
- this._emit('blockAdd', key, block.t);
- $(block).onChange(() => this._emit('blockChange', key, block.t));
- });
- $(this.room.state).blocks.onRemove((_b, key) => this._emit('blockRemove', key));
+ // blocks field is optional (servers pre-dating voxel builds omit it).
+ const $blocks = $state?.blocks;
+ if ($blocks) {
+ $blocks.onAdd((block, key) => {
+ this._emit('blockAdd', key, block.t);
+ $(block).onChange(() => this._emit('blockChange', key, block.t));
+ });
+ $blocks.onRemove((_b, key) => this._emit('blockRemove', key));
+ }
// Durability flag for this world's build (Redis-backed vs memory-only).
// Set once at room creation; listen so the HUD reflects it as soon as the
// first state patch lands and if it ever degrades mid-session.
this.persistent = !!this.room.state.persistent;
- $(this.room.state).listen('persistent', (v) => { this.persistent = !!v; this._emit('persistent', !!v); });
+ $state?.listen?.('persistent', (v) => { this.persistent = !!v; this._emit('persistent', !!v); });
this.room.onLeave((code) => {
this._setStatus('offline');
diff --git a/src/game/cosmetics-visual.js b/src/game/cosmetics-visual.js
index 7dfd49111..562402f5c 100644
--- a/src/game/cosmetics-visual.js
+++ b/src/game/cosmetics-visual.js
@@ -4,10 +4,10 @@
// here reads or writes any gameplay value.
//
// Three visual primitives, any of which a cosmetic may combine:
-// tint — recolour the avatar's body materials (a dye). Multiplies into each
-// material's colour so textured models shift hue instead of going flat.
-// prop — a GLB worn on the head (hats), auto-fitted to the avatar's height so
-// one asset sits correctly on any model.
+// tint — recolour the avatar's body materials (a dye). Blends toward the tint
+// while keeping some original lightness, so shading/detail survive.
+// prop — a GLB worn on the head (hats) or face (glasses), auto-fitted and
+// anchored to the head bone so one asset sits right on any model.
// aura — a glowing, slowly-spinning ring at the avatar's feet.
//
// applyCosmetic() returns a handle: tick(dt) animates the aura, dispose() fully
@@ -15,7 +15,7 @@
// re-applies after every avatar (re)load, since loading clears the rig.
import {
- Group, Mesh, MeshBasicMaterial, RingGeometry, Box3, Vector3,
+ Group, Mesh, MeshBasicMaterial, RingGeometry, Box3, Vector3, Color,
AdditiveBlending, DoubleSide,
} from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
@@ -38,10 +38,15 @@ function loadProp(url) {
return _propCache.get(url);
}
-// Recolour every body material, remembering each material's original colour so
-// dispose() can restore it exactly. Dedupes by material (a model often shares
-// one across meshes) so we store/restore each once.
+// Recolour every body material as a *dye*: blend each material's colour most of
+// the way toward the tint while keeping a fraction of the original, so the
+// model's light/dark shading and detail survive instead of going flat (a hard
+// `color.set(hex)` washes untextured meshes into a single block). Dedupes by
+// material (a model often shares one across meshes) and remembers each original
+// so dispose() restores it exactly.
+const TINT_STRENGTH = 0.72; // how far toward the dye; the rest preserves detail
function applyTint(rig, hex) {
+ const tint = new Color(hex);
const restore = new Map(); // material -> original hex
rig.traverse((n) => {
if (!n.isMesh) return;
@@ -49,7 +54,7 @@ function applyTint(rig, hex) {
for (const m of mats) {
if (!m || !m.color || restore.has(m)) continue;
restore.set(m, m.color.getHex());
- m.color.set(hex);
+ m.color.lerp(tint, TINT_STRENGTH);
}
});
return () => { for (const [m, orig] of restore) m.color?.setHex(orig); };
diff --git a/src/game/game-hud.js b/src/game/game-hud.js
index 53213e12e..fd6089e99 100644
--- a/src/game/game-hud.js
+++ b/src/game/game-hud.js
@@ -47,6 +47,10 @@ const PROP_ICON = {
'glasses-shades': '🕶️',
};
+// Cosmetics at or above this price ask for a second confirming click before the
+// gold is spent, so a stray tap never burns a big purchase.
+const CONFIRM_PRICE = 400;
+
const SKILL_LABEL = { combat: 'Combat', woodcutting: 'Woodcutting', mining: 'Mining', fishing: 'Fishing', cooking: 'Cooking' };
function fmtCountdown(ms) {
@@ -95,6 +99,10 @@ export class GameHud {
// Wardrobe try-before-equip: the id currently previewed on the local
// avatar (null = none). Local-only; cleared when the shop closes.
this._previewId = null;
+ // Two-step buy confirmation for pricier cosmetics: the id awaiting a second
+ // click (null = none) and the timer that resets it if the player hesitates.
+ this._confirmBuyId = null;
+ this._confirmTimer = null;
// Marketplace (Task 20): the latest board (active listings + your own), the
// token-payment capability flags, the open flag + active tab, per-listing
// "busy" labels driven by the controller during an on-chain buy, an error
@@ -192,6 +200,7 @@ export class GameHud {
<div class="kq-shop-tabs" role="tablist">
<button class="kq-shop-tab kq-shop-tab--on" id="kq-shop-tab-shop" type="button" role="tab" aria-selected="true">Shop</button>
<button class="kq-shop-tab" id="kq-shop-tab-wardrobe" type="button" role="tab" aria-selected="false">Wardrobe</button>
+ <button class="kq-shop-tab" id="kq-shop-tab-collection" type="button" role="tab" aria-selected="false">Collection</button>
</div>
<p class="kq-shop-note">Cosmetics are purely cosmetic — they change how you look, never how you play.</p>
<div class="kq-shop-body" id="kq-shop-body"></div>
@@ -244,6 +253,7 @@ export class GameHud {
this.elShopGold = root.querySelector('#kq-shop-gold');
this.elShopTabShop = root.querySelector('#kq-shop-tab-shop');
this.elShopTabWardrobe = root.querySelector('#kq-shop-tab-wardrobe');
+ this.elShopTabCollection = root.querySelector('#kq-shop-tab-collection');
this.elQuestBtn.addEventListener('click', () => this.toggleQuests());
root.querySelector('#kq-quests-x').addEventListener('click', () => this.closeQuests());
@@ -262,6 +272,7 @@ export class GameHud {
this.elShop.addEventListener('click', (e) => { if (e.target === this.elShop) this.closeShop(); });
this.elShopTabShop.addEventListener('click', () => this._setShopTab('shop'));
this.elShopTabWardrobe.addEventListener('click', () => this._setShopTab('wardrobe'));
+ this.elShopTabCollection.addEventListener('click', () => this._setShopTab('collection'));
// Marketplace (Task 20).
this.elMarketBtn = root.querySelector('#kq-market-btn');
@@ -630,20 +641,31 @@ export class GameHud {
}
_setShopTab(tab) {
- this._shopTab = tab === 'wardrobe' ? 'wardrobe' : 'shop';
- const onShop = this._shopTab === 'shop';
- this.elShopTabShop.classList.toggle('kq-shop-tab--on', onShop);
- this.elShopTabWardrobe.classList.toggle('kq-shop-tab--on', !onShop);
- this.elShopTabShop.setAttribute('aria-selected', String(onShop));
- this.elShopTabWardrobe.setAttribute('aria-selected', String(!onShop));
+ this._shopTab = ['shop', 'wardrobe', 'collection'].includes(tab) ? tab : 'shop';
+ this._clearConfirm();
+ const tabs = { shop: this.elShopTabShop, wardrobe: this.elShopTabWardrobe, collection: this.elShopTabCollection };
+ for (const [name, btn] of Object.entries(tabs)) {
+ const on = name === this._shopTab;
+ btn.classList.toggle('kq-shop-tab--on', on);
+ btn.setAttribute('aria-selected', String(on));
+ }
this._renderShop();
}
+ // Reset any pending two-step buy confirmation (tab switch, close, board refresh).
+ _clearConfirm() {
+ if (this._confirmTimer) { clearTimeout(this._confirmTimer); this._confirmTimer = null; }
+ this._confirmBuyId = null;
+ }
+
_renderShop() {
if (!this._shopOpen) return;
const body = this.elShopBody;
if (!this.cosmetics.size) { body.replaceChildren(el('p', 'kq-empty', 'Loading the shop…')); return; }
- body.replaceChildren(this._shopTab === 'wardrobe' ? this._renderWardrobe() : this._renderShopCatalog());
+ const view = this._shopTab === 'wardrobe' ? this._renderWardrobe()
+ : this._shopTab === 'collection' ? this._renderCollection()
+ : this._renderShopCatalog();
+ body.replaceChildren(view);
}
// Buy tab: the rotating board grouped by bucket, each rotating group headed by a
@@ -680,8 +702,11 @@ export class GameHud {
}
_shopCard(c, owned) {
+ const equipped = this.shop?.equipped || '';
const affordable = this.gold >= c.price;
- const card = el('div', `kq-cos-card kq-cos--${c.rarity}${owned ? ' kq-cos--owned' : affordable ? '' : ' kq-cos--short'}`);
+ const card = el('div', `kq-cos-card kq-cos--${c.rarity}`
+ + (owned ? ' kq-cos--owned' : affordable ? '' : ' kq-cos--short')
+ + (equipped === c.id ? ' kq-cos--equipped' : ''));
card.style.setProperty('--cos-accent', this._rarityColor(c.rarity));
card.appendChild(this._cosSwatch(c));
const meta = el('div', 'kq-cos-meta');
@@ -690,19 +715,47 @@ export class GameHud {
card.appendChild(meta);
const foot = el('div', 'kq-cos-foot');
if (owned) {
- foot.appendChild(el('span', 'kq-cos-owned', '✓ Owned'));
+ // Already bought — equip straight from the shop (no trip to the wardrobe).
+ if (equipped === c.id) {
+ foot.appendChild(el('span', 'kq-cos-equipped', '✓ Equipped'));
+ } else {
+ const b = el('button', 'kq-btn kq-cos-equip', 'Equip');
+ b.type = 'button';
+ b.addEventListener('click', () => this._commitCosmetic(c.id));
+ foot.appendChild(b);
+ }
} else {
foot.appendChild(el('span', 'kq-cos-price' + (affordable ? '' : ' kq-cos-price--short'), `🪙 ${c.price.toLocaleString('en-US')}`));
- const btn = el('button', 'kq-btn kq-cos-buy' + (affordable ? '' : ' kq-btn-disabled'), affordable ? 'Buy' : `Need ${(c.price - this.gold).toLocaleString('en-US')}`);
+ const confirming = this._confirmBuyId === c.id;
+ const label = !affordable ? `Need ${(c.price - this.gold).toLocaleString('en-US')}` : confirming ? 'Confirm?' : 'Buy';
+ const btn = el('button', 'kq-btn kq-cos-buy' + (affordable ? '' : ' kq-btn-disabled') + (confirming ? ' kq-cos-buy--confirm' : ''), label);
btn.type = 'button';
btn.disabled = !affordable;
- if (affordable) btn.addEventListener('click', () => this.opts.onBuyCosmetic?.(c.id));
+ if (affordable) btn.addEventListener('click', () => this._buyClicked(c));
foot.appendChild(btn);
}
card.appendChild(foot);
return card;
}
+ // Buy with a one-tap confirm for pricier cosmetics: cheap looks buy on the first
+ // click; anything >= CONFIRM_PRICE arms a "Confirm?" state that the next click
+ // (within a few seconds) commits, so a misclick never spends a big sum.
+ _buyClicked(c) {
+ if (c.price < CONFIRM_PRICE || this._confirmBuyId === c.id) {
+ this._clearConfirm();
+ this.opts.onBuyCosmetic?.(c.id);
+ return;
+ }
+ this._clearConfirm();
+ this._confirmBuyId = c.id;
+ this._confirmTimer = setTimeout(() => {
+ this._confirmBuyId = null;
+ if (this._shopOpen && this._shopTab === 'shop') this._renderShop();
+ }, 4000);
+ this._renderShop();
+ }
+
// Wardrobe tab: a "Default look" tile (unequip) plus every owned cosmetic, with
// the equipped one highlighted. Equipping previews live on the avatar in-world.
_renderWardrobe() {
diff --git a/src/game/game-net.js b/src/game/game-net.js
index 31b20e383..217133646 100644
--- a/src/game/game-net.js
+++ b/src/game/game-net.js
@@ -9,6 +9,7 @@
// all of it.
import { Client, getStateCallbacks } from 'colyseus.js';
+import { GameState } from '../../multiplayer/src/schemas/game.js';
const REALMS = ['mainland', 'wilderness', 'whisperwood', 'pond', 'mine', 'wilderness_north', 'wilderness_cave', 'wilderness_east', 'arena'];
const DEFAULT_REALM = 'mainland';
@@ -185,7 +186,7 @@ export class GameNet {
try {
this.client = new Client(this.url);
const presence = this.getPresence ? await this.getPresence().catch(() => null) : null;
- this.room = await this.client.joinOrCreate(this.roomName, { name: this.name, avatar: this.avatar, pid: this.pid, server: this.server, ...(presence ? { presence } : {}) });
+ this.room = await this.client.joinOrCreate(this.roomName, { name: this.name, avatar: this.avatar, pid: this.pid, server: this.server, ...(presence ? { presence } : {}) }, GameState);
this.sessionId = this.room.sessionId;
this._bindRoom();
this._announcePresence();
@@ -289,7 +290,7 @@ export class GameNet {
// Fade out first, then do the room swap — so the player never sees a
// half-rebuilt world flash.
if (this.onBeforeHandoff) await this.onBeforeHandoff();
- const next = await this.client.consumeSeatReservation(reservation);
+ const next = await this.client.consumeSeatReservation(reservation, GameState);
this.room = next;
this.sessionId = next.sessionId;
this.realm = REALMS.includes(to) ? to : this.realm;
diff --git a/src/game/iso-game.js b/src/game/iso-game.js
index 6f1bd338e..d14949c65 100644
--- a/src/game/iso-game.js
+++ b/src/game/iso-game.js
@@ -3106,7 +3106,10 @@ export class IsoGame {
this._chatHistoryCursor = next;
input.value = next === -1 ? (this._chatHistoryDraft || '') : hist[hist.length - 1 - next];
this._updateChatCounter();
- this._refreshCmdHint();
+ // Hide the hint while scrolling history — it would open for any '/…'
+ // entry and steal subsequent ArrowUp/Down from the history path.
+ // When the user stops navigating and edits manually the hint reopens.
+ this._hideCmdHint();
return;
}
}
diff --git a/src/walk-net.js b/src/walk-net.js
index 67f91b204..e653b9621 100644
--- a/src/walk-net.js
+++ b/src/walk-net.js
@@ -163,14 +163,17 @@ export class WalkNet {
// Colyseus 0.16 moved schema callbacks behind getStateCallbacks(room)
// — the legacy `state.players.onAdd(fn)` form no longer exists.
const $ = getStateCallbacks(this.room);
- $(this.room.state).players.onAdd((player, sessionId) => {
- this._emit('add', player, sessionId);
- // Per-instance onChange fires on every field delta.
- $(player).onChange(() => this._emit('change', player, sessionId));
- });
- $(this.room.state).players.onRemove((_player, sessionId) => {
- this._emit('remove', sessionId);
- });
+ const $players = $(this.room.state)?.players;
+ if ($players) {
+ $players.onAdd((player, sessionId) => {
+ this._emit('add', player, sessionId);
+ // Per-instance onChange fires on every field delta.
+ $(player).onChange(() => this._emit('change', player, sessionId));
+ });
+ $players.onRemove((_player, sessionId) => {
+ this._emit('remove', sessionId);
+ });
+ }
// Chat is broadcast (not schema state) so it arrives as a room message.
// We relay it through our own event API; walk.js renders the bubble +