Add walkable housing interiors and cross-hub visitors

This commit is contained in:
dingo
2026-09-10 10:48:26 -04:00
parent b2dd2cb3ba
commit 1bd5d487e2
28 changed files with 721 additions and 52 deletions
+7 -3
View File
@@ -141,7 +141,7 @@ function showEnding(title: string, detail: string, survivor: boolean) {
$<HTMLDialogElement>('ending').show();
}
function inventory(c: Character) {
housing?.update(c);
$('earned-titles').replaceChildren(permanentTitles(c.titles));
const parent = $('inventory-items'), panel = characterPanel(c, send);
if (panel.parentElement !== parent) parent.replaceChildren(panel);
@@ -164,6 +164,7 @@ function minimap(s: Snapshot) {
}
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);
$('character-name').textContent = c.entity.name;
@@ -194,6 +195,7 @@ function updateHUD(s: Snapshot) {
visible('target-boss',w.kind!=='hub');$('target-boss').textContent=w.phase==='won'?'Find victory portal':'Target Harbinger';$('target-boss').setAttribute('aria-label',w.phase==='won'?'Find victory portal':'Target Harbinger');
visible('dev-boss',config.development&&w.kind!=='hub');
$<HTMLButtonElement>('attack').disabled=w.kind==='hub'||w.phase==='won';$<HTMLButtonElement>('gather').disabled=w.kind==='hub'||w.phase==='won';
if(c.houseId){$('phase-label').textContent=s.house?.name??'HOUSE';$('season-detail').textContent='WASD / stick to walk · Jump onto furniture · I for house controls';$('coordinates').textContent=`${c.housePosition?.x.toFixed(1)??0}, ${c.housePosition?.z.toFixed(1)??0}`;}
selection(view.selected); minimap(s);
if (s.message && s.message !== lastNotice) { notice(s.message); lastNotice = s.message; }
}
@@ -202,6 +204,7 @@ async function boot() {
createIcons({ icons: { Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords, Pickaxe, HeartPulse, Gem, Backpack, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ArrowRight, RefreshCw } });
view = new WorldView($<HTMLCanvasElement>('world'));
input = new InputActions(() => hasOpenMenu() || isEditing(document.activeElement) || $<HTMLDialogElement>('arrival').open || $<HTMLDialogElement>('ending').open, key => {
if(snapshot?.self.houseId){if(key==='inventory'||key==='gather'){housing.open();return}if(key==='jump'){send('jump');return}return}
if(key==='attack'||key==='gather')action(key);
else if(key==='inventory')$('inventory-toggle').click();
else if(key.startsWith('slot'))powers.useSlot(Number(key.slice(4))-1);
@@ -219,11 +222,11 @@ async function boot() {
inputElapsed += dt;
input.pollController();
if (!snapshot || ws?.readyState !== WebSocket.OPEN || $<HTMLDialogElement>('ending').open) return;
if(snapshot.self.houseId){input.clear();walkTo=undefined;pendingAction=undefined;return}
if(document.hidden||hasOpenMenu()||isEditing(document.activeElement)){
input.clear();walkTo=undefined;pendingAction=undefined;view.moving=false;
if(inputElapsed>=0.05){send('move');inputElapsed=0;}return;
}
if(snapshot.self.houseId){let {x,z}=input.movement;if(x||z)walkTo=undefined;const p=snapshot.self.housePosition;if(walkTo&&p){const dx=walkTo.x-p.x,dz=walkTo.z-p.z,n=Math.hypot(dx,dz);if(n>.25){x=dx/n;z=dz/n}else walkTo=undefined}if(inputElapsed>=.05){send('move','',x,z);inputElapsed=0}return}
let {x,z} = input.movement;
if (x || z) { walkTo = undefined; pendingAction = undefined; }
const actionTarget = pendingAction?.target === snapshot.self.entity.id ? snapshot.self.entity : snapshot.entities.find(e => e.id === pendingAction?.target);
@@ -268,7 +271,7 @@ 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');$('recipes').after(housing.root);
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));
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;}});};
@@ -326,6 +329,7 @@ async function boot() {
view.canvas.addEventListener('pointerdown', event => {
if (!snapshot || hasOpenMenu() || $<HTMLDialogElement>('arrival').open || $<HTMLDialogElement>('ending').open || event.button !== 0) return;
const hit = view.pick(event.clientX, event.clientY);
if(snapshot.self.houseId){if(hit.entity?.kind==='house-exit')void housing.leave();else if(hit.entity)housing.open(hit.entity.id);else if(hit.point)walkTo=hit.point;return}
if(placement){if(!hit.point||hit.entity){notice('Choose unoccupied ground. Esc cancels.');return}const p=snapshot.self.entity.position,x=(hit.point.x-p.x)/placement.range,z=(hit.point.z-p.z)/placement.range;if(Math.hypot(x,z)>1){notice('Choose ground within '+placement.range+'m.');return}send('build',placement.id,x,z,placement.rotation);placement=undefined;return;}
if (hit.entity) { if(hit.entity.kind==='portal'){$('travel').click();return;} selection(hit.entity); action(['boss', 'sentinel','mob','player','structure'].includes(hit.entity.kind) ? 'attack' : 'gather'); }