Add persistent destructible world structures and building kits
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import type {BuildingContent, Character} from './generated';
|
||||
import {api} from './portal-shared';
|
||||
import {node} from './character-stats';
|
||||
|
||||
export function buildingPanel(character:()=>Character|undefined,start:(id:string,rotation:string,range:number)=>void,prefix:string){
|
||||
const root=node('details'),summary=node('summary','Building'),list=node('div'),message=node('p');root.append(summary,node('p','Craft a structure kit, then choose a clear spot in the survival world. Placing consumes one kit. Structures can be destroyed by players and mobs.'),list,message);
|
||||
root.addEventListener('toggle',()=>{if(root.open)void refresh()});
|
||||
async function refresh(){try{const b=await api<BuildingContent>(prefix+'/api/building'),c=character();list.replaceChildren();
|
||||
for(const d of b.definitions){const held=c?.inventory['kit_'+d.id]??0;if(!held)continue;const row=node('section'),rotation=node('select'),place=node('button','Choose placement');rotation.setAttribute('aria-label',d.name+' orientation');rotation.append(new Option('Width along east/west','0'),new Option('Width along north/south','1'));place.type='button';place.onclick=()=>start(d.id,rotation.value,b.range);row.append(node('h4',d.name+' · '+held+' kits'),node('p',`${d.width} × ${d.depth} × ${d.height}m · ${d.hp} health · ${d.profession} level ${d.level}`),rotation,place);list.append(row)}
|
||||
message.textContent=list.children.length?'Click clear ground within '+b.range+'m after choosing placement. Esc cancels.':'No structure kits held. Craft one or ask an administrator for a playtest kit.';
|
||||
}catch(e){message.textContent=(e as Error).message}}
|
||||
return root;
|
||||
}
|
||||
Reference in New Issue
Block a user