Add durable recipe discovery and profession crafting
This commit is contained in:
+3
-10
@@ -1,5 +1,6 @@
|
||||
import './style.css';
|
||||
import { showTravel } from './travel';
|
||||
import { craftingPanel } from './crafting-panel';
|
||||
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';
|
||||
@@ -8,8 +9,7 @@ import { characterPanel } from './character-panel';
|
||||
import { InputActions, isEditing, type InputAction } from './input-actions';
|
||||
import { hasOpenMenu, registerMenu } from './menu-focus';
|
||||
|
||||
type Recipe = { Inputs: Record<string, number>; Outputs: Record<string, number> };
|
||||
type Config = { worldId: string; kind: string; development: boolean; worlds: { id: string; url: string }[]; recipes: Record<string, Recipe>; playerSpeed: number; gatherRange: number; attackRange: number };
|
||||
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;
|
||||
const visible = (id: string, show: boolean) => { $(id).hidden = !show; };
|
||||
const pretty = (s: string) => s.replaceAll('_', ' ').replace(/^./, c => c.toUpperCase());
|
||||
@@ -133,14 +133,7 @@ function inventory(c: Character) {
|
||||
$('earned-titles').replaceChildren(permanentTitles(c.titles));
|
||||
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';
|
||||
const label = document.createElement('div'), title = document.createElement('strong'), cost = document.createElement('small');
|
||||
title.textContent = pretty(name); cost.textContent = Object.entries(recipe.Inputs).map(([k, n]) => `${n} ${pretty(k)}`).join(' + '); label.append(title, cost);
|
||||
const button = document.createElement('button'); button.textContent = 'Craft'; button.title = `Craft ${name}`; button.disabled = Object.entries(recipe.Inputs).some(([item, count]) => (c.inventory[item] ?? 0) < count); button.onclick = () => send('craft', name);
|
||||
row.append(label, button); recipes.append(row);
|
||||
}
|
||||
const recipes=$('recipes'),workbench=craftingPanel(c,worldPrefix);if(workbench.parentElement!==recipes)recipes.replaceChildren(workbench);
|
||||
const skills = $('skills'); skills.replaceChildren();
|
||||
for(const g of Object.values(c.gathering??{})){const label=document.createElement('span');label.textContent=`${g.name} · Level ${g.level} (effective ${g.effectiveLevel})`;const amount=document.createElement('b');amount.textContent=`${g.xp} XP · ${g.xpToNextLevel} to next`;label.append(amount);skills.append(label);}
|
||||
for (const skill of ['crafting', 'combat']) { const label = document.createElement('span'); label.textContent = pretty(skill); const amount = document.createElement('b'); amount.textContent = `${c.skills[skill] ?? 0} XP`; label.append(amount); skills.append(label); }
|
||||
|
||||
Reference in New Issue
Block a user