Add biome revisions readable content and visible projectile outcomes
This commit is contained in:
@@ -15,7 +15,7 @@ function field(label:string,input:HTMLElement){const wrap=node('label',label);wr
|
||||
function text(value='',max=80){const i=node('input');i.value=value;i.maxLength=max;i.required=true;return i;}
|
||||
function number(value:number,min=0,max=1000000,step='any'){const i=text(String(value));i.type='number';i.min=String(min);i.max=String(max);i.step=step;return i;}
|
||||
function select(keys:string[],value=''){const i=node('select');for(const key of keys)i.append(new Option(statLabel(key),key));i.value=keys.includes(value)?value:keys[0];return i;}
|
||||
function identity(){const group=node('div','','catalog-fields'),name=text(),description=node('textarea');description.maxLength=500;description.rows=3;group.append(field('Name',name),field('Description',description),node('p','A permanent ID is assigned automatically when you publish.','muted'));return {node:group,read:()=>({name:name.value.trim(),description:description.value.trim()})};}
|
||||
function identity(initial?:{name:string;description:string}){const group=node('div','','catalog-fields'),name=text(initial?.name??''),description=node('textarea');description.value=initial?.description??'';description.maxLength=500;description.rows=3;group.append(field('Name',name),field('Description',description),node('p',initial?'This biome keeps its identity. Publishing creates its next revision.':'A permanent ID is assigned automatically when you publish.','muted'));return {node:group,read:()=>({name:name.value.trim(),description:description.value.trim()})};}
|
||||
function repeat<T>(title:string,addLabel:string,make:(value?:T)=>{node:HTMLElement;read:()=>T},initial:T[]=[],max=64){
|
||||
const group=node('fieldset','','catalog-repeatable'),rows=node('div'),entries:{node:HTMLElement;read:()=>T}[]=[];group.append(node('legend',title),rows);
|
||||
const add=button(addLabel,()=>append());group.append(add);
|
||||
@@ -44,7 +44,7 @@ function form(title:string,op:string,payload:()=>object){
|
||||
reason.required=true;reason.minLength=5;reason.maxLength=240;reason.rows=2;error.setAttribute('role','alert');
|
||||
const focus=registerMenu(form,()=>{editing=false;refresh.disabled=saving;forms.replaceChildren();focus.dispose()});
|
||||
const save=node('button','Publish changes','button');save.type='submit';const cancel=button('Cancel',()=>focus.close()),check=button('Preview changes',()=>void previewChanges());const footer=node('footer');footer.append(cancel,check,save);
|
||||
form.append(node('h3',title),node('p',`Based on catalog version ${expectedVersion}. Published definitions and sets cannot be edited or removed.`,'muted'),fields,field('Reason for change',reason),error,preview,footer);forms.replaceChildren(form);
|
||||
form.append(node('h3',title),node('p',`Based on catalog version ${expectedVersion}. Biome edits publish new revisions; other definitions remain immutable.`,'muted'),fields,field('Reason for change',reason),error,preview,footer);forms.replaceChildren(form);
|
||||
const previous=document.activeElement;queueMicrotask(()=>{if(form.isConnected)focus.opened(previous)});
|
||||
form.addEventListener('input',()=>preview.replaceChildren());form.addEventListener('change',()=>preview.replaceChildren());
|
||||
fields.addEventListener('click',event=>{if((event.target as HTMLElement).closest('button'))preview.replaceChildren()});
|
||||
@@ -64,13 +64,13 @@ function form(title:string,op:string,payload:()=>object){
|
||||
function previewView(result:ContentPreview){
|
||||
const root=node('div'),r=result.resolved;root.append(node('h4','Validated publication preview'),node('p',`Version ${result.basedOnVersion} → ${result.proposedVersion}. Nothing has been published.`));
|
||||
const definition=r.title??r.item??r.requirementSet??r.effectSet??r.gatheringSkill??r.resource??r.biome??r.consumable??r.attack??r.mob??r.loot??r.spawn;
|
||||
if(definition)root.append(node('strong',definition.name),node('p',definition.description),node('p','Permanent ID assigned on publication.','muted'));
|
||||
if(definition)root.append(node('strong',definition.name),node('p',definition.description),node('p',r.targetId?`Revision ${r.biome?.revision} of the existing biome`:'Permanent ID assigned on publication.','muted'));
|
||||
const requirements=r.title?.requirements??r.requirementSet?.requirements;
|
||||
if(requirements)root.append(node('p',requirements.map(v=>`${statLabel(v.metric)} ≥ ${v.atLeast}`).join(' / ')));
|
||||
if(r.item)root.append(node('p',`Requires level ${r.item.requirements.level}; ${Object.entries(r.item.requirements.stats??{}).map(([key,n])=>`${statLabel(key)} ≥ ${n}`).join(' / ')}`),node('p',`Required titles: ${(r.item.requirements.titles??[]).join(', ')||'None'}`));
|
||||
const modifiers=r.title?.effects.modifiers??r.item?.modifiers??r.effectSet?.modifiers;if(modifiers)root.append(modifiersView(modifiers));
|
||||
if(r.gatheringSkill||r.resource||r.biome||r.consumable||r.attack||r.mob||r.loot||r.spawn)root.append(node('pre',JSON.stringify(r.gatheringSkill??r.resource??r.biome??r.consumable??r.attack??r.mob??r.loot??r.spawn,null,2)));
|
||||
if(r.stats){root.append(node('p','Validated base values and primary-to-derived coefficients.'));const details=node('details');details.append(node('summary','Review stat formulas'),node('pre',JSON.stringify(r.stats,null,2)));root.append(details);}
|
||||
if(r.gatheringSkill||r.resource||r.biome||r.consumable||r.attack||r.mob||r.loot||r.spawn)root.append(readableDefinition(r.gatheringSkill??r.resource??r.biome??r.consumable??r.attack??r.mob??r.loot??r.spawn));
|
||||
if(r.stats){root.append(node('p','Validated base values and primary-to-derived coefficients.'));const details=node('details');details.append(node('summary','Review stat formulas'),readableDefinition(r.stats));root.append(details);}
|
||||
return root;
|
||||
}
|
||||
function titleForm(){
|
||||
@@ -124,9 +124,34 @@ export function hasCatalogDraft(){return editing;}
|
||||
function contentChoice(values:{id:string;name:string}[]) {
|
||||
const input=node('select');input.required=true;for(const v of values)input.append(new Option(v.name,v.id));return input;
|
||||
}
|
||||
function gatheringForm(kind:string){
|
||||
|
||||
function readableDefinition(value:unknown, context=''):HTMLElement {
|
||||
const names = [...catalog.items,...catalog.titles,...(catalog.gathering?.skills??[]),...(catalog.gathering?.resources??[]),...(catalog.gathering?.biomes??[]),...(catalog.gathering?.consumables??[]),...(catalog.combat?.attacks??[]),...(catalog.combat?.mobs??[]),...(catalog.combat?.loot??[])];
|
||||
const reference=(v:string)=>names.find(n=>n.id===v)?.name??statLabel(v);
|
||||
if(Array.isArray(value)) {
|
||||
const list=node('ul','','catalog-values');
|
||||
if(!value.length)list.append(node('li','None'));
|
||||
for(const entry of value){const row=node('li');row.append(readableDefinition(entry,context));list.append(row)}return list;
|
||||
}
|
||||
if(value!==null && typeof value==='object') {
|
||||
const labels:Record<string,string>={baseXp:'XP to level 2',xpPerLevel:'Additional XP per level',maxLevel:'Maximum level',skillId:'Gathering profession',requiredLevel:'Required level',amount:'Yield / quantity',seconds:'Duration / interval (seconds)',respawnSeconds:'Respawn (seconds)',density:'Nodes per chunk',biomes:'Biomes',resources:'Resources',color:'Terrain color',weight:'Relative weight',revision:'Revision',speed:'Speed (m/s)',dexteritySpeed:'Extra m/s per Dexterity',strengthSpeed:'Extra m/s per Strength',cooldown:'Cooldown (seconds)',stamina:'Stamina cost',range:'Range (m)',radius:'Radius (m)',duration:'Area duration (seconds)',interval:'Pulse interval (seconds)',attackId:'Attack profile',lootId:'Loot table',mobId:'Mob',hp:'Base health',xp:'XP reward',aggroRange:'Detection range (m)',leashRange:'Pursuit limit (m)',scalePerDay:'World-age scaling per day',minPlayerDistance:'Minimum spawn distance (m)',respawn:'Respawn (seconds)',chance:'Chance (%)',group:'Weighted group',item:'Item',stat:'Power stat',multiplier:'Power multiplier'};
|
||||
const fields=node('dl','','catalog-facts');
|
||||
const record=value as Record<string,unknown>;
|
||||
for(const [key,raw] of Object.entries(record)) {
|
||||
if(['id','name','description'].includes(key))continue;
|
||||
let item=raw;
|
||||
if(key==='resources'&&item==null&&typeof record.id==='string')item=(catalog.gathering?.resources??[]).filter(r=>r.biomes.includes(record.id as string)).map(r=>r.id);
|
||||
if(key==='biomes'&&'skillId' in record&&record.id) item=(catalog.gathering?.biomes??[]).filter(b=>b.resources!=null?b.resources.includes(record.id as string):(raw as string[]).includes(b.id)).map(b=>b.id);
|
||||
const term=node('dt',labels[key]??statLabel(key)),detail=node('dd');detail.append(readableDefinition(item,key));fields.append(term,detail);
|
||||
}return fields;
|
||||
}
|
||||
if(value==null||value==='')return node('span',context==='group'?'Independent':'None');
|
||||
if(typeof value==='string')return node('span',context==='color'?value:reference(value));
|
||||
return node('span',typeof value==='boolean'?(value?'Yes':'No'):String(value));
|
||||
}
|
||||
function gatheringForm(kind:string,existing?:NonNullable<Catalog['gathering']>['biomes'][number]){
|
||||
if(editing||saving){show('Finish or cancel the open draft first.');return;}
|
||||
const values=identity(),g=catalog.gathering;
|
||||
const values=identity(existing),g=catalog.gathering;
|
||||
if(kind==='gathering'){
|
||||
const base=number(20,1,1000000,'1'),step=number(10,0,1000000,'1'),max=number(1000,2,10000,'1');
|
||||
const fields=form('Create gathering skill','create-gathering-skill',()=>({gatheringSkill:{...values.read(),baseXp:Number(base.value),xpPerLevel:Number(step.value),maxLevel:Number(max.value)}}));
|
||||
@@ -139,9 +164,12 @@ function gatheringForm(kind:string){
|
||||
const fields=form('Create resource','create-resource',()=>{const biomes=checks.filter(v=>v.input.checked).map(v=>v.id);if(!biomes.length)throw new Error('Choose at least one biome.');return{resource:{...values.read(),skillId:skill.value,model:model.value,output:output.value,requiredLevel:Number(level.value),amount:Number(amount.value),xp:Number(xp.value),seconds:Number(seconds.value),respawnSeconds:Number(respawn.value),density:Number(density.value),biomes}}});
|
||||
fields.append(values.node,field('Gathering skill',skill),field('Model preset',model),field('Gathered material',output),field('Required effective skill level',level),field('Base amount per success',amount),field('Base profession XP per success',xp),field('Gathering interval (seconds)',seconds),field('Respawn interval (seconds)',respawn),field('Nodes per matching chunk (before forest density bonus)',density),biomeFields,node('p','Players may risk attempts up to 20 levels below this requirement. Failures can destroy the node until respawn and inflict damage/fatigue. New definitions appear in unexplored chunks of new-generation worlds; explored layouts stay fixed. Models use existing placeholders until milestone 4.5.','muted'));
|
||||
}else if(kind==='biomes'){
|
||||
const color=text('#426044',7);color.type='color';const weight=number(3,1,100,'1');
|
||||
const fields=form('Create biome','create-biome',()=>({biome:{...values.read(),color:color.value,weight:Number(weight.value)}}));
|
||||
fields.append(values.node,field('Terrain color',color),field('Relative occurrence weight',weight),node('p','Applies to unexplored chunks. Publish resource definitions referencing this biome to populate it. Mob populations arrive in milestone 4.','muted'));
|
||||
const color=text(existing?.color??'#426044',7);color.type='color';const weight=number(existing?.weight??3,1,100,'1');
|
||||
const resources=node('fieldset','','catalog-title-choices');resources.append(node('legend','Resources in this biome'));
|
||||
const selected=existing?.resources??(g?.resources??[]).filter(r=>existing&&r.biomes.includes(existing.id)).map(r=>r.id);
|
||||
const checks=(g?.resources??[]).map(r=>{const input=node('input');input.type='checkbox';input.checked=selected.includes(r.id);resources.append(field(`${r.name} · ${statLabel(r.model)} · level ${r.requiredLevel}`,input));return{id:r.id,input}});
|
||||
const fields=form(existing?`Edit ${existing.name} · publish revision ${(existing.revision??1)+1}`:'Create biome',existing?'update-biome':'create-biome',()=>({...existing?{targetId:existing.id}:{},biome:{...values.read(),color:color.value,weight:Number(weight.value),resources:checks.filter(c=>c.input.checked).map(c=>c.id)}}));
|
||||
fields.append(values.node,field('Terrain color',color),field('Relative occurrence weight',weight),resources,node('p','Reuse any existing resource. Published biome revisions affect unexplored chunks; explored layouts remain unchanged. Adding a new resource from the resource editor also versions its selected biomes.','muted'));
|
||||
}else{
|
||||
const seconds=number(120,1,86400),effects=modifiers();
|
||||
const fields=form('Create gathering consumable','create-consumable',()=>{const mods=effects.read();if(!mods.length||mods.some(m=>!m.stat.startsWith('gathering')))throw new Error('Choose gathering level, yield, speed, or XP modifiers.');return{consumable:{...values.read(),seconds:Number(seconds.value),modifiers:mods}}});
|
||||
@@ -152,7 +180,9 @@ function gatheringList(){
|
||||
const labels:Record<string,string>={gathering:'gathering skill',resources:'resource',biomes:'biome',consumables:'gathering consumable'};
|
||||
list.append(button(`Create ${labels[section]}`,()=>gatheringForm(section)));
|
||||
const g=catalog.gathering;const entries=section==='gathering'?g?.skills:section==='resources'?g?.resources:section==='biomes'?g?.biomes:g?.consumables;
|
||||
for(const v of entries??[]){const d=node('details','','catalog-definition');d.append(node('summary',v.name),node('p',v.description),node('pre',JSON.stringify(v,null,2)));list.append(d);}
|
||||
for(const v of entries??[]){const d=node('details','','catalog-definition');d.append(node('summary',v.name),node('p',v.description),readableDefinition(v));
|
||||
if(section==='biomes') { const b=v as NonNullable<Catalog['gathering']>['biomes'][number]; d.append(node('p',`Current revision ${b.revision??1}`),button('Edit biome',()=>gatheringForm('biomes',b)));const history=node('details');history.append(node('summary','Previous revisions'));for(const old of g?.biomeHistory??[])if(old.id===b.id){const revision=node('section');revision.append(node('h4',`Revision ${old.revision}`),readableDefinition(old));history.append(revision)}d.append(history); }
|
||||
list.append(d);}
|
||||
}
|
||||
|
||||
function combatForm(kind:string){
|
||||
@@ -160,7 +190,7 @@ function combatForm(kind:string){
|
||||
const values=identity(),c=catalog.combat;
|
||||
if(kind==='attacks'){
|
||||
const delivery=select(['melee','projectile']),effect=select(['damage','heal']),stat=select(['meleeDamage','rangedDamage','magicDamage']);
|
||||
const settings=[['multiplier','Stat multiplier',1,.01,100],['range','Range (m)',6,1,128],['cooldown','Cooldown (seconds)',1,.1,120],['stamina','Player stamina cost',0,0,10000],['speed','Projectile speed (m/s)',35,1,100],['radius','Area radius (0 = single target)',0,0,24],['duration','Area duration (0 = burst)',0,0,60],['interval','Area tick interval (seconds)',1,.2,60]] as const;
|
||||
const settings=[['multiplier','Stat multiplier',1,.01,100],['range','Range (m)',6,1,128],['cooldown','Cooldown (seconds)',1,.1,120],['stamina','Player stamina cost',0,0,10000],['speed','Weapon base projectile speed (m/s)',35,1,100],['dexteritySpeed','Extra m/s per Dexterity point',.1,0,5],['strengthSpeed','Extra m/s per Strength point',.05,0,5],['radius','Area radius (0 = single target)',0,0,24],['duration','Area duration (0 = burst)',0,0,60],['interval','Area tick interval (seconds)',1,.2,60]] as const;
|
||||
const inputs=settings.map(([key,label,value,min,max])=>({key,label,input:number(value,min,max)}));
|
||||
const fields=form('Create attack profile','create-attack',()=>({attack:{...values.read(),delivery:delivery.value,effect:effect.value,stat:stat.value,...Object.fromEntries(inputs.map(v=>[v.key,Number(v.input.value)]))}}));
|
||||
fields.append(values.node,field('Delivery',delivery),field('Effect',effect),field('Player stat to scale',stat),...inputs.map(v=>field(v.label,v.input)),node('p','Damage targets opponents; healing targets allies. Players currently target mobs and the Harbinger, while player healing targets living players. Projectiles fly toward the selected position and can miss. Areas remain fixed at impact. Damage is sampled at attack time.','muted'));
|
||||
@@ -184,5 +214,5 @@ function combatList(){
|
||||
const c=catalog.combat,entries=section==='attacks'?c?.attacks:section==='mobs'?c?.mobs:section==='loot'?c?.loot:c?.spawns;
|
||||
const labels:Record<string,string>={attacks:'attack profile',mobs:'mob',loot:'loot table',spawns:'mob spawn rule'};
|
||||
list.append(button(`Create ${labels[section]}`,()=>combatForm(section)));
|
||||
for(const v of entries??[]){const d=node('details','','catalog-definition');d.append(node('summary',v.name),node('p',v.description),node('pre',JSON.stringify(v,null,2)));list.append(d)}
|
||||
for(const v of entries??[]){const d=node('details','','catalog-definition');d.append(node('summary',v.name),node('p',v.description),readableDefinition(v));list.append(d)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user