fix(v2): pack fill — count children directly from items array
Instead of relying on the packItems Map (which may have key matching issues), count pack children directly by filtering the normalized items array for items whose container_id matches the pack's item_id. Also removed debug console.log spam from WindowRenderer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f9ae3d6b96
commit
8e77274316
4 changed files with 21 additions and 26 deletions
|
|
@ -166,17 +166,13 @@ export const InventoryWindow: React.FC<Props> = ({ id, charName, zIndex }) => {
|
|||
const [cantripState, setCantripState] = useState<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('[INV] Loading inventory for', charName);
|
||||
setLoading(true);
|
||||
Promise.all([
|
||||
apiFetch<any>(`/inventory/${encodeURIComponent(charName)}?limit=1000`).catch(e => { console.error('[INV] fetch error:', e); return { items: [] }; }),
|
||||
apiFetch<any>(`/inventory/${encodeURIComponent(charName)}?limit=1000`).catch(() => ({ items: [] })),
|
||||
apiFetch<any>(`/character-stats/${encodeURIComponent(charName)}`).catch(() => null),
|
||||
]).then(([inv, stats]) => {
|
||||
const rawItems = inv.items ?? [];
|
||||
console.log('[INV] Got', rawItems.length, 'raw items, first:', rawItems[0]);
|
||||
const normalized = rawItems.map(normalizeItem);
|
||||
console.log('[INV] Normalized', normalized.length, 'items, sample container_ids:', normalized.slice(0, 5).map((i: any) => i.container_id));
|
||||
setItems(normalized);
|
||||
setItems(rawItems.map(normalizeItem));
|
||||
setCharStats(stats);
|
||||
}).finally(() => setLoading(false));
|
||||
}, [charName]);
|
||||
|
|
@ -346,11 +342,13 @@ export const InventoryWindow: React.FC<Props> = ({ id, charName, zIndex }) => {
|
|||
label={`Backpack (${mainItems.length}/102)`} onClick={() => setActivePack(null)} />
|
||||
{containers.map((c: any) => {
|
||||
const cid = c.item_id;
|
||||
const pItems = packItems.get(cid) ?? [];
|
||||
// Count items directly from normalized items array instead of relying on packItems map
|
||||
const childCount = items.filter((i: any) => i.container_id === cid && i.item_id !== cid).length;
|
||||
const cap = c.items_capacity ?? 24;
|
||||
const pct = cap > 0 ? Math.min(100, (childCount / cap) * 100) : 0;
|
||||
return <PackIcon key={cid} iconSrc={`/icons/${iconHex(c.icon)}.png`} isActive={activePack === cid}
|
||||
fillPct={Math.min(100, (pItems.length / cap) * 100)}
|
||||
label={`${c.name} (${pItems.length}/${cap})`} onClick={() => setActivePack(cid)} />;
|
||||
fillPct={pct}
|
||||
label={`${c.name} (${childCount}/${cap})`} onClick={() => setActivePack(cid)} />;
|
||||
})}
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,11 @@ interface Props {
|
|||
export const WindowRenderer: React.FC<Props> = ({ characters, chatMessages, nearbyObjects, socket }) => {
|
||||
const { windows } = useWindowManager();
|
||||
|
||||
console.log('[WR] Rendering', windows.length, 'windows:', windows.map(w => w.id));
|
||||
|
||||
return (
|
||||
<>
|
||||
{windows.map(w => {
|
||||
const charName = w.charName ?? '';
|
||||
const prefix = w.id.split('-')[0];
|
||||
console.log('[WR] Window:', w.id, 'prefix:', prefix, 'charName:', charName);
|
||||
|
||||
switch (prefix) {
|
||||
case 'chat':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue