Tossing in changes before ready

This commit is contained in:
dingo
2026-09-10 13:51:58 -04:00
parent 65249ad0a4
commit 747d5dae99
7 changed files with 155 additions and 35 deletions
+16 -14
View File
@@ -2,13 +2,12 @@ import './style.css';
import { showTravel } from './travel';
import { createHousingPanel } from './housing-panel';
import { buildingPanel } from './building-panel';
import { craftingPanel } from './crafting-panel';
import { createPlayerDrawer } from './player-drawer';
import { createPowerPanel, revivalPanel } from './power-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';
import { experienceText, permanentTitles, statPointsText, updateExperienceMeter } from './progression';
import { characterPanel } from './character-panel';
import { experienceText, statPointsText, updateExperienceMeter } from './progression';
import { InputActions, isEditing, type InputAction } from './input-actions';
import { hasOpenMenu, registerMenu } from './menu-focus';
@@ -54,6 +53,7 @@ let requestedClose = false;
let input: InputActions;
let powers:ReturnType<typeof createPowerPanel>;
let housing:ReturnType<typeof createHousingPanel>;
let drawer:ReturnType<typeof createPlayerDrawer>;
let placement:{id:string;rotation:string;range:number}|undefined;
let view: WorldView;
const selectedWorld = new URLSearchParams(location.search).get('world');
@@ -99,6 +99,8 @@ function action(op: string) {
}
function connect() {
requestedClose = false; sequence = 0; snapshot = undefined;
powers.hotbar.hidden = true;
visible('game-controls',false); visible('movement',false); visible('inventory',false);
const ending = $<HTMLDialogElement>('ending'); ending.close();
ws = new WebSocket(`${location.protocol === 'https:' ? 'wss:' : 'ws:'}//${location.host}${worldPrefix}/ws`);
ws.onopen = () => { $('connection-status').textContent = 'Synchronizing world'; };
@@ -118,6 +120,8 @@ function connect() {
} else if (value.self.remainingSeconds <= 0 && !ending.open) showEnding('Rest until tomorrow.', 'Your daily play time is complete. Your keystone will return you to your previous location after 00:00 UTC.', false);
};
ws.onclose = async () => {
powers.hotbar.hidden = true;
visible('game-controls',false); visible('movement',false); visible('inventory',false);
$('connection-status').textContent = 'Disconnected'; $('connection-dot').parentElement!.classList.add('offline'); input.clear(); walkTo = undefined;
if (requestedClose || $<HTMLDialogElement>('ending').open) return;
let detail = 'The connection ended. Your character state is held by the server.';
@@ -127,6 +131,8 @@ function connect() {
}
function showEnding(title: string, detail: string, survivor: boolean) {
input.clear(); walkTo = undefined; pendingAction = undefined;
if(powers)powers.hotbar.hidden=true;
visible('game-controls',false);visible('movement',false);visible('inventory',false);
$('ending-title').textContent = title; $('ending-detail').textContent = detail;
$('ending-eyebrow').textContent = survivor ? 'WORLD SURVIVED' : 'JOURNEY PAUSED';
if (snapshot?.self.entity.state === 'dead') $('ending-eyebrow').textContent = 'JOURNEY ENDED';
@@ -141,14 +147,7 @@ function showEnding(title: string, detail: string, survivor: boolean) {
$<HTMLDialogElement>('ending').show();
}
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'),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); }
drawer.update(c);
}
function minimap(s: Snapshot) {
const canvas = $<HTMLCanvasElement>('minimap'), ctx = canvas.getContext('2d')!;
@@ -166,7 +165,9 @@ function updateHUD(s: Snapshot) {
const c = s.self, w = s.world;
housing?.update(c);
powers?.update(c);
visible('game-controls', true); visible('movement', ['alive','eligible'].includes(c.entity.state) && $('inventory').hidden && $('settings').hidden);
const playable=['alive','eligible'].includes(c.entity.state)&&c.remainingSeconds>0;
powers.hotbar.hidden=!playable;
visible('game-controls', playable); visible('movement', playable && !hasOpenMenu());
$('character-name').textContent = c.entity.name;
$('character-level').textContent = `Level ${c.level || 1}`;
$('character-experience').textContent = experienceText(c);
@@ -271,8 +272,9 @@ async function boot() {
}, 50);
const [loadedConfig, chunks] = await Promise.all([api<Config>('/api/config'), api<Chunk[]>('/api/preview'), view.load()]);
config = loadedConfig;
housing=createHousingPanel(()=>snapshot?.self,worldPrefix,()=>config.kind==='hub',()=>{input.clear();walkTo=undefined;pendingAction=undefined;placement=undefined;visible('inventory',false);selection()});$('recipes').after(housing.root);$('hud').append(housing.toolbar);
powers=createPowerPanel((op,target,x,z,slot)=>{if(op==='cast'){input.clear();walkTo=undefined;pendingAction=undefined;send('move')}send(op,target,x,z,slot)},()=>view.selected,notice,worldPrefix);$('recipes').after(powers.root);$('hud').append(powers.hotbar);$('settings').append(input.settings());$('recipes').after(buildingPanel(()=>snapshot?.self,(id,rotation,range)=>{placement={id,rotation,range};input.clear();walkTo=undefined;pendingAction=undefined;send('move');$('inventory-toggle').click();notice('Click clear ground to build. Esc cancels.');},worldPrefix));
housing=createHousingPanel(()=>snapshot?.self,worldPrefix,()=>config.kind==='hub',()=>{input.clear();walkTo=undefined;pendingAction=undefined;placement=undefined;visible('inventory',false);selection()});$('hud').append(housing.toolbar);
powers=createPowerPanel((op,target,x,z,slot)=>{if(op==='cast'){input.clear();walkTo=undefined;pendingAction=undefined;send('move')}send(op,target,x,z,slot)},()=>view.selected,notice,worldPrefix);$('hud').append(powers.hotbar);$('settings').append(input.settings());
drawer=createPlayerDrawer($('inventory'),powers,send,worldPrefix,housing.root,buildingPanel(()=>snapshot?.self,(id,rotation,range)=>{placement={id,rotation,range};input.clear();walkTo=undefined;pendingAction=undefined;send('move');$('inventory-toggle').click();notice('Click clear ground to build. Esc cancels.');},worldPrefix));
const travelButton=document.createElement('button');travelButton.id='travel';travelButton.textContent='Travel';travelButton.title='World travel';$('inventory-toggle').before(travelButton);
travelButton.onclick=()=>{if(!snapshot)return;input.clear();walkTo=undefined;pendingAction=undefined;send('move');void showTravel({worldId:config.worldId,route:config.kind==='hub'?'hub':snapshot.world.phase==='won'?'portal':'escape',beforeTravel:()=>{requestedClose=true;},afterTravel:departed=>{requestedClose=departed;}});};
$<HTMLInputElement>('zoom').value = String(view.distance);