Add character levels and permanent player titles

This commit is contained in:
dingo
2026-09-07 07:58:34 -04:00
parent 5a48a3c739
commit bc0ffbbbe5
30 changed files with 1594 additions and 62 deletions
+9
View File
@@ -2,6 +2,7 @@ import './style.css';
import { createIcons, Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords, Pickaxe, HeartPulse, Gem, Backpack, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ArrowRight, RefreshCw } from 'lucide';
import { WorldView } from './world-view';
import type { Character, Chunk, Entity, Intent, Snapshot } from './generated';
import { experienceText, permanentTitles, statPointsText, updateExperienceMeter } from './progression';
type Recipe = { Inputs: Record<string, number>; Outputs: Record<string, number> };
type Config = { worldId: string; development: boolean; worlds: { id: string; url: string }[]; recipes: Record<string, Recipe>; playerSpeed: number; gatherRange: number; attackRange: number };
@@ -114,6 +115,8 @@ function showEnding(title: string, detail: string, survivor: boolean) {
$<HTMLDialogElement>('ending').show();
}
function inventory(c: Character) {
$('saved-stat-points').textContent = statPointsText(c);
$('earned-titles').replaceChildren(permanentTitles(c.titles));
const parent = $('inventory-items'); parent.replaceChildren();
for (const [item, count] of Object.entries(c.inventory).filter(([, n]) => n > 0)) {
const div = document.createElement('div'); div.className = 'item';
@@ -148,6 +151,12 @@ function updateHUD(s: Snapshot) {
const c = s.self, w = s.world;
visible('game-controls', true); visible('movement', c.entity.state === 'alive' && $('inventory').hidden && $('settings').hidden);
$('character-name').textContent = c.entity.name;
$('character-level').textContent = `Level ${c.level || 1}`;
$('character-experience').textContent = experienceText(c);
updateExperienceMeter($<HTMLProgressElement>('experience-meter'), c);
$('stat-point-bank').textContent = statPointsText(c);
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)}`;
$('health-fill').style.width = `${Math.max(0, c.entity.hp / c.entity.maxHp * 100)}%`;
$('play-time').textContent = `${time(c.remainingSeconds)} left today`;