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: collection tab, prop thumbnails, confirm-buy CSS, test coverage

nirholas0e9f929a58da
diff --git a/src/game/game-hud.js b/src/game/game-hud.js
index fd6089e99..8409cf769 100644
--- a/src/game/game-hud.js
+++ b/src/game/game-hud.js
@@ -614,6 +614,7 @@ export class GameHud {
// The live shop board (offers + rotation deadlines + owned ids + equipped + gold).
setShop(snapshot) {
this.shop = snapshot || null;
+ this._clearConfirm();
if (snapshot) {
this._dailyResetAt = snapshot.offers?.dailyResetAt || 0;
this._weeklyResetAt = snapshot.offers?.weeklyResetAt || 0;
@@ -638,6 +639,7 @@ export class GameHud {
// Drop any uncommitted wardrobe preview — revert the avatar to the
// server-authoritative equipped look.
if (this._previewId !== null) { this._previewId = null; this.opts.onStopPreview?.(); }
+ this._clearConfirm();
}
_setShopTab(tab) {
@@ -701,6 +703,52 @@ export class GameHud {
return frag;
}
+ // Collection tab: the entire catalogue at a glance — owned looks (tappable to
+ // preview, even here) and locked ones with their price + how they're obtained.
+ // A completion count gives players something to chase.
+ _renderCollection() {
+ const frag = document.createDocumentFragment();
+ const all = [...this.cosmetics.values()];
+ if (!all.length) { frag.appendChild(el('p', 'kq-empty', 'Loading…')); return frag; }
+ const owned = new Set(this.shop?.owned || []);
+ const order = Object.keys(this.rarities);
+ const rank = (r) => { const i = order.indexOf(r); return i < 0 ? 99 : i; };
+ all.sort((a, b) => rank(a.rarity) - rank(b.rarity) || a.price - b.price);
+ const ownedN = all.filter((c) => owned.has(c.id)).length;
+ frag.appendChild(el('p', 'kq-shop-sub', `${ownedN} / ${all.length} collected. Tap any look to preview it on your avatar.`));
+ const grid = el('div', 'kq-cos-grid');
+ const SRC = { always: 'Always in shop', daily: 'Daily rotation', weekly: 'Weekly rotation' };
+ for (const c of all) {
+ const have = owned.has(c.id);
+ const isPreview = this._previewId === c.id;
+ const card = el('div', `kq-cos-card kq-cos-card--pick kq-cos--${c.rarity}`
+ + (have ? '' : ' kq-cos--locked') + (isPreview ? ' kq-cos--preview' : ''));
+ card.style.setProperty('--cos-accent', this._rarityColor(c.rarity));
+ card.dataset.cosId = c.id;
+ card.setAttribute('role', 'button');
+ card.tabIndex = 0;
+ card.setAttribute('aria-label', `Preview ${c.name}`);
+ card.addEventListener('click', () => this._previewCosmetic(c.id));
+ card.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); this._previewCosmetic(c.id); } });
+ card.appendChild(this._cosSwatch(c));
+ const meta = el('div', 'kq-cos-meta');
+ meta.appendChild(el('div', 'kq-cos-name', c.name));
+ meta.appendChild(el('div', 'kq-cos-rarity', this._rarityLabel(c.rarity)));
+ card.appendChild(meta);
+ const foot = el('div', 'kq-cos-foot');
+ if (have) {
+ foot.appendChild(el('span', 'kq-cos-owned', '✓ Owned'));
+ } else {
+ foot.appendChild(el('span', 'kq-cos-price', `🪙 ${c.price.toLocaleString('en-US')}`));
+ foot.appendChild(el('span', 'kq-cos-src', SRC[c.rotation] || ''));
+ }
+ card.appendChild(foot);
+ grid.appendChild(card);
+ }
+ frag.appendChild(grid);
+ return frag;
+ }
+
_shopCard(c, owned) {
const equipped = this.shop?.equipped || '';
const affordable = this.gold >= c.price;
@@ -708,6 +756,7 @@ export class GameHud {
+ (owned ? ' kq-cos--owned' : affordable ? '' : ' kq-cos--short')
+ (equipped === c.id ? ' kq-cos--equipped' : ''));
card.style.setProperty('--cos-accent', this._rarityColor(c.rarity));
+ card.dataset.cosId = c.id;
card.appendChild(this._cosSwatch(c));
const meta = el('div', 'kq-cos-meta');
meta.appendChild(el('div', 'kq-cos-name', c.name));
@@ -777,6 +826,7 @@ export class GameHud {
const card = el('div', 'kq-cos-card kq-cos-card--pick' + rarityCls
+ (isEq ? ' kq-cos--equipped' : '') + (isPreview ? ' kq-cos--preview' : ''));
if (c) card.style.setProperty('--cos-accent', this._rarityColor(c.rarity));
+ if (id) card.dataset.cosId = id;
card.setAttribute('role', 'button');
card.tabIndex = 0;
card.setAttribute('aria-pressed', String(isEq));
@@ -846,7 +896,17 @@ export class GameHud {
} else if (v.tint) {
sw.style.background = `linear-gradient(150deg, ${v.tint}, rgba(255,255,255,0.18))`;
}
- if (v.prop) sw.textContent = PROP_ICON[c.id] || '🎩';
+ if (v.prop) {
+ // Real rendered thumbnail of the worn prop, falling back to the emoji glyph
+ // if the image is missing so a card never renders blank.
+ const base = v.prop.split('/').pop().replace(/\.[^.]+$/, '');
+ const img = el('img', 'kq-cos-thumb');
+ img.src = `/accessories/thumbs/${base}.png`;
+ img.alt = '';
+ img.loading = 'lazy';
+ img.addEventListener('error', () => { img.remove(); sw.textContent = PROP_ICON[c.id] || '🎩'; });
+ sw.appendChild(img);
+ }
return sw;
}
diff --git a/src/game/iso-game.css b/src/game/iso-game.css
index 80a58ed22..174a5012c 100644
--- a/src/game/iso-game.css
+++ b/src/game/iso-game.css
@@ -2561,6 +2561,11 @@ body.kg-loading-cursor {
.kq-cos-card--pick:hover { border-color: var(--cos-accent); transform: translateY(-1px); }
.kq-cos-card--pick:focus-visible { outline: 2px solid var(--kg-accent); outline-offset: 2px; }
.kq-cos-card.kq-cos--preview { border-color: var(--cos-accent); box-shadow: 0 0 0 1px var(--cos-accent) inset, 0 0 16px -4px var(--cos-accent); }
+.kq-cos-thumb { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
+.kq-cos-card.kq-cos--locked { opacity: 0.62; }
+.kq-cos-card.kq-cos--locked:hover { opacity: 1; }
+.kq-cos-src { font-size: 10px; font-weight: 700; color: var(--kg-dim); }
+.kq-cos-buy--confirm { background: #ffce5c; color: #2a1c00; animation: kq-pulse 1s ease-in-out infinite; }
.kq-cos-card.kq-cos--short { opacity: 0.78; }
.kq-cos-swatch {
width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
diff --git a/tests/cosmetics-hud.test.js b/tests/cosmetics-hud.test.js
index 7f526962a..1b451f1c2 100644
--- a/tests/cosmetics-hud.test.js
+++ b/tests/cosmetics-hud.test.js
@@ -11,7 +11,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
globalThis.self = globalThis;
import { GameHud } from '../src/game/game-hud.js';
-import { clientCatalog, currentOffers } from '../multiplayer/src/cosmetics.js';
+import { clientCatalog, currentOffers, cosmeticById } from '../multiplayer/src/cosmetics.js';
const CAT = clientCatalog();
const T = Date.UTC(2026, 5, 1, 12, 0, 0);
@@ -21,12 +21,14 @@ let calls;
afterEach(() => { hud?.destroy(); hud = null; document.body.innerHTML = ''; });
function mount() {
- calls = { buy: [], equip: [], unequip: 0, shopOpen: 0 };
+ calls = { buy: [], equip: [], unequip: 0, shopOpen: 0, preview: [], stop: 0 };
hud = new GameHud({
onShopOpen: () => calls.shopOpen++,
onBuyCosmetic: (id) => calls.buy.push(id),
onEquipCosmetic: (id) => calls.equip.push(id),
onUnequipCosmetic: () => calls.unequip++,
+ onPreviewCosmetic: (id) => calls.preview.push(id),
+ onStopPreview: () => calls.stop++,
});
hud.setCosmeticCatalog(CAT.cosmetics, CAT.rarities);
return hud;
@@ -37,6 +39,12 @@ function board({ gold = 1000, owned = [], equipped = '' } = {}) {
return { offers: currentOffers(T), owned, equipped, gold };
}
+// Every id currently on the board (all three buckets).
+function offeredIds() {
+ const o = currentOffers(T);
+ return [...o.daily, ...o.weekly, ...o.always];
+}
+
describe('gold readout', () => {
it('reflects setGold in the toolbar and shop header', () => {
mount();
@@ -63,15 +71,28 @@ describe('shop tab — buy board', () => {
expect(document.querySelectorAll('#kq-shop-body .kq-cos-card').length).toBe(total);
});
- it('a buy click on an affordable card routes the cosmetic id to the server', () => {
+ it('a cheap affordable card buys on the first click', () => {
+ mount();
+ hud.openShop();
+ hud.setShop(board({ gold: 100000 }));
+ const cheap = offeredIds().find((id) => cosmeticById(id).price < 400);
+ expect(cheap).toBeTruthy();
+ document.querySelector(`#kq-shop-body [data-cos-id="${cheap}"] .kq-cos-buy`).click();
+ expect(calls.buy).toEqual([cheap]);
+ });
+
+ it('a pricey card needs a confirming second click before it buys', () => {
mount();
hud.openShop();
hud.setShop(board({ gold: 100000 }));
- const buy = document.querySelector('#kq-shop-body .kq-cos-buy');
- expect(buy).toBeTruthy();
- buy.click();
- expect(calls.buy.length).toBe(1);
- expect(typeof calls.buy[0]).toBe('string');
+ const pricey = offeredIds().find((id) => cosmeticById(id).price >= 400);
+ expect(pricey).toBeTruthy();
+ const sel = `#kq-shop-body [data-cos-id="${pricey}"] .kq-cos-buy`;
+ document.querySelector(sel).click(); // first click arms "Confirm?"
+ expect(calls.buy.length).toBe(0);
+ expect(document.querySelector(sel).textContent).toMatch(/confirm/i);
+ document.querySelector(sel).click(); // second click commits
+ expect(calls.buy).toEqual([pricey]);
});
it('disables buying when the purse is short and shows the shortfall', () => {
@@ -86,13 +107,18 @@ describe('shop tab — buy board', () => {
expect(calls.buy.length).toBe(0); // a disabled button never fires
});
- it('marks an owned cosmetic as Owned instead of offering a buy button', () => {
+ it('lets you equip an owned cosmetic straight from the shop tab', () => {
mount();
hud.openShop();
const ownedId = currentOffers(T).always[0];
hud.setShop(board({ gold: 5000, owned: [ownedId] }));
- const ownedTag = [...document.querySelectorAll('#kq-shop-body .kq-cos-owned')];
- expect(ownedTag.length).toBeGreaterThan(0);
+ const card = document.querySelector(`#kq-shop-body [data-cos-id="${ownedId}"]`);
+ expect(card).toBeTruthy();
+ expect(card.querySelector('.kq-cos-buy')).toBeNull(); // owned → no buy button
+ const equip = card.querySelector('.kq-cos-equip');
+ expect(equip).toBeTruthy();
+ equip.click();
+ expect(calls.equip).toEqual([ownedId]);
});
});
@@ -134,3 +160,23 @@ describe('wardrobe tab — equip / unequip', () => {
expect(calls.unequip).toBe(1);
});
});
+
+
+describe('collection tab', () => {
+ it('lists the whole catalogue with a completion count and previews on click', () => {
+ mount();
+ hud.openShop();
+ const ownedId = currentOffers(T).always[0];
+ hud.setShop(board({ owned: [ownedId] }));
+ hud._setShopTab('collection');
+ const cards = document.querySelectorAll('#kq-shop-body .kq-cos-card');
+ expect(cards.length).toBe(CAT.cosmetics.length);
+ expect(document.querySelector('#kq-shop-body .kq-shop-sub').textContent).toMatch(/^1 \/ /);
+ // The owned one reads as owned; a locked one shows price + source.
+ expect(document.querySelector(`#kq-shop-body [data-cos-id="${ownedId}"] .kq-cos-owned`)).toBeTruthy();
+ expect(document.querySelector('#kq-shop-body .kq-cos-src')).toBeTruthy();
+ // Tapping any card previews it on the local avatar.
+ document.querySelector(`#kq-shop-body [data-cos-id="${ownedId}"]`).click();
+ expect(calls.preview).toEqual([ownedId]);
+ });
+});