Show encumbrance on HUD and document modular creator direction

This commit is contained in:
dingo
2026-09-12 08:53:32 -04:00
parent faf2ab3040
commit 75f71d5ded
9 changed files with 218 additions and 5 deletions
+14
View File
@@ -14,6 +14,7 @@ import type { BuildingContent, Character, Chunk, Entity, Intent, Snapshot } from
import { experienceText, statPointsText, updateExperienceMeter } from './progression';
import { InputActions, isEditing, type InputAction } from './input-actions';
import { hasOpenMenu, registerMenu } from './menu-focus';
import { carryStatus } from './character-stats';
type Config = { worldId: string; kind: string; development: boolean; worlds: { id: string; url: string }[]; playerSpeed: number; gatherRange: number; attackRange: number };
const $ = <T extends HTMLElement = HTMLElement>(id: string) => document.getElementById(id) as T;
@@ -204,6 +205,13 @@ function updateHUD(s: Snapshot) {
$('character-experience').textContent = experienceText(c);
updateExperienceMeter($<HTMLProgressElement>('experience-meter'), c);
$('stat-point-bank').textContent = statPointsText(c);
const carry = carryStatus(c);
$('carry-weight').textContent = carry.weight;
// Keep the explanation visible even when the bag is closed. The server owns
// the movement factor; do not reproduce encumbrance tuning in the browser.
if ($('carry-movement').textContent !== carry.movement) $('carry-movement').textContent = carry.movement;
$('carry-manage').classList.toggle('encumbered', carry.impaired);
$('carry-manage').title = `${carry.help} Open bag to manage carried items.`.trim();
const titleCount = c.titles?.length ?? 0;
$('title-count').textContent = `${titleCount} title${titleCount === 1 ? '' : 's'}`;
$('health-number').textContent = `${Math.max(0, Math.ceil(c.entity.hp))} / ${Math.ceil(c.entity.maxHp)}`;
@@ -232,6 +240,12 @@ function updateHUD(s: Snapshot) {
if (s.message && s.message !== lastNotice) { notice(s.message); lastNotice = s.message; }
}
async function boot() {
$('carry-manage').onclick = () => {
if ($('inventory').hidden) $('inventory-toggle').click();
const bag = $('inventory').querySelector<HTMLButtonElement>('[data-view="bag"]');
bag?.click();
bag?.focus();
};
$<HTMLAnchorElement>('login').href = `/auth/login?return=${encodeURIComponent(location.pathname + location.search)}`;
createIcons({ icons: { Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords, Pickaxe, HeartPulse, Gem, Backpack, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ArrowRight, RefreshCw } });
view = new WorldView($<HTMLCanvasElement>('world'));