Complete player stats inventory and Control content editors
This commit is contained in:
+6
-11
@@ -3,6 +3,7 @@ import { createIcons, Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords,
|
||||
import { WorldView } from './world-view';
|
||||
import type { Character, Chunk, Entity, Intent, Snapshot } from './generated';
|
||||
import { experienceText, permanentTitles, statPointsText, updateExperienceMeter } from './progression';
|
||||
import { characterPanel } from './character-panel';
|
||||
|
||||
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 };
|
||||
@@ -38,7 +39,7 @@ function progressSignature(): number | undefined {
|
||||
if (pendingAction.target === 'boss') return snapshot.world.bossHp;
|
||||
return snapshot.entities.find(e => e.id === pendingAction!.target)?.hp;
|
||||
}
|
||||
return Object.values(snapshot.self.inventory).reduce((a: number, b: number) => a + b, 0);
|
||||
return Object.values(snapshot.self.inventory).reduce((a: number, b: number) => a + b, 0) + (snapshot.self.items?.length ?? 0);
|
||||
}
|
||||
const avoidUntil = new Map<string, number>();
|
||||
let requestedClose = false;
|
||||
@@ -54,9 +55,9 @@ async function api<T>(path: string, body?: unknown): Promise<T> {
|
||||
return result as T;
|
||||
}
|
||||
function notice(message: string) { $('notice').textContent = message; visible('notice', true); clearTimeout(noticeTimer); noticeTimer = setTimeout(() => visible('notice', false), 3500); }
|
||||
function send(op: string, target = '', x = 0, z = 0) {
|
||||
function send(op: string, target = '', x = 0, z = 0, slot = '') {
|
||||
if (ws?.readyState !== WebSocket.OPEN || !snapshot || snapshot.self.entity.state !== 'alive') return;
|
||||
const intent: Intent = { op, target, x, z, seq: ++sequence };
|
||||
const intent: Intent = { op, target, x, z, slot, seq: ++sequence };
|
||||
ws.send(JSON.stringify(intent));
|
||||
}
|
||||
function selection(entity?: Entity) {
|
||||
@@ -115,15 +116,9 @@ 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';
|
||||
const text = document.createElement('span'); text.textContent = pretty(item);
|
||||
const quantity = document.createElement('b'); quantity.textContent = String(count);
|
||||
div.append(text, quantity); parent.append(div);
|
||||
}
|
||||
const parent = $('inventory-items'), panel = characterPanel(c, send);
|
||||
if (panel.parentElement !== parent) parent.replaceChildren(panel);
|
||||
const recipes = $('recipes'); recipes.replaceChildren();
|
||||
for (const [name, recipe] of Object.entries(config.recipes)) {
|
||||
const row = document.createElement('div'); row.className = 'recipe';
|
||||
|
||||
Reference in New Issue
Block a user