Open exact authoritative web decision workflow from the native NPC dossier
This commit is contained in:
parent
a99e1dd986
commit
378e2b92d7
3 changed files with 16 additions and 4 deletions
|
|
@ -52,9 +52,10 @@ final class QuestMenus implements Listener {
|
|||
if(Set.of("thufir_hawat","piter_de_vries","hasimir_fenring","roma_atani","imperial_attendant","stilgar","jessica_atreides","gaius_helen_mohiam","alia_atreides","edric","guild_navigator","duncan_idaho").contains(role.key()))put(screen,48,"POL decisions","See only current executable political decisions",Material.BOOK,()->roleDecisionDashboard(p,data,role));put(screen,49,"Website journal","Full mission choices and history",Material.MAP,()->website(p));show(p,screen);
|
||||
}
|
||||
private void roleDecisionDashboard(Player p,JsonObject contact,PolQuestNpc.Role role){var input=new JsonObject();input.addProperty("action","read");input.addProperty("npcRole",role.key());decisionRequest(p,role,input,data->{var screen=panel(p,"NPC dashboard decision · "+role.name());screen.description="Choose a decision you currently have the authority to execute.";roleAvatar(screen,contact,role);int slot=9;for(var e:data.getAsJsonArray("decisions")){var row=e.getAsJsonObject();if(slot>=45)break;put(screen,slot++,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\n"+(text(row,"kind","").equals("website")?"Continue through the verified website workflow.":(row.has("fundingRequired")&&!yes(row,"fundingRequired")?"Review the parameter and confirm.":"Review funding and confirm.")),Material.BOOK,()->roleDecisionDetails(p,contact,role,row,null,null));}if(slot==9)put(screen,13,"No executable decisions","Your current office, authority and cooldown determine what appears here.",Material.MAP,null);put(screen,48,"Back","Mission dashboard",Material.ARROW,()->load(p,"pol",null,null,0));put(screen,49,"Website","Full decision definitions and history",Material.MAP,()->decisionWebsite(p));show(p,screen);});}
|
||||
private void decisionWebsite(Player p){p.closeInventory();p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl("https://clans.dunerealms.com/#quests/quests")));}
|
||||
private void decisionWebsite(Player p){decisionWebsite(p,null);}
|
||||
private void decisionWebsite(Player p,String decision){p.closeInventory();String url="https://clans.dunerealms.com/#quests/quests?xp=pol&view=decisions";if(decision!=null&&decision.matches("[A-Z0-9-]{1,32}"))url+="&decision="+decision;p.sendMessage(Component.text("Review POL decisions on the website →",NamedTextColor.GOLD).clickEvent(ClickEvent.openUrl(url)));}
|
||||
private void roleDecisionDetails(Player p,JsonObject contact,PolQuestNpc.Role role,JsonObject row,String account,String parameter){var screen=panel(p,"NPC turn-in decision · "+role.name());screen.description=dialogue(row,"introduction","");roleAvatar(screen,contact,role);String kind=text(row,"kind","");String fee=text(row,"feeMinor","0");String amount;try{amount=new java.math.BigDecimal(fee).movePointLeft(2).toPlainString()+" DM";}catch(NumberFormatException invalid){amount="—";}put(screen,13,text(row,"title","Decision"),"Required Reputation: "+text(row,"level","—")+"\nBase cost: "+amount+"\nAward: "+text(row,"reputation","—")+" Reputation",Material.BOOK,null);
|
||||
if(kind.equals("website")){put(screen,31,"Open website workflow","This decision requires the existing website controls.",Material.MAP,()->decisionWebsite(p));}
|
||||
if(kind.equals("website")){put(screen,31,"Open website workflow","This decision requires the existing website controls.",Material.MAP,()->decisionWebsite(p,text(row,"id","")));}
|
||||
else if(account==null&&(!row.has("fundingRequired")||yes(row,"fundingRequired"))){int slot=18;for(var e:row.getAsJsonArray("accounts")){var a=e.getAsJsonObject();if(slot>=35)break;String id=text(a,"id","");try{if(new java.math.BigInteger(text(a,"availableMinor","0")).compareTo(new java.math.BigInteger(fee))<0)continue;}catch(NumberFormatException invalid){continue;}put(screen,slot++,text(a,"name","Funding account"),"Account "+text(a,"number","")+" · available "+new java.math.BigDecimal(text(a,"availableMinor","0")).movePointLeft(2).toPlainString()+" DM",Material.GOLD_INGOT,()->roleDecisionDetails(p,contact,role,row,id,parameter));}}
|
||||
else if(row.has("parameters")&¶meter==null){int slot=18;for(var item:row.getAsJsonArray("parameters")){var value=item.getAsJsonObject();if(slot>=35)break;put(screen,slot++,text(value,"label","Parameter"),"Select this exact parameter",Material.PAPER,()->roleDecisionDetails(p,contact,role,row,account,text(value,"value","")));}}
|
||||
else{String parameterLabel=parameter;if(parameter!=null&&row.has("parameters"))for(var entry:row.getAsJsonArray("parameters")){var option=entry.getAsJsonObject();if(parameter.equals(text(option,"value",""))){parameterLabel=text(option,"label",parameter);break;}}put(screen,22,"Confirmed selection",(account==null?"No separate funding required":"Funding account "+account)+(parameter==null?"":"\nParameter: "+parameterLabel),Material.GOLD_INGOT,null);UUID requestId=UUID.randomUUID();put(screen,31,"Confirm and execute","Commit the reviewed decision once through J.A.R.V.I.S.",Material.LIME_DYE,()->{var input=new JsonObject();input.addProperty("action","execute");input.addProperty("npcRole",role.key());input.addProperty("decisionId",text(row,"id",""));input.addProperty("requestId",requestId.toString());if(account!=null)input.addProperty("sourceAccount",account);input.addProperty("confirmed",true);if(parameter!=null)input.addProperty("parameter",parameter);decisionRequest(p,role,input,result->roleDecisionResult(p,contact,role,row,result));});}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,12 @@ const artFor=id=>id==='h'?'progression/repair-workshop.webp':id==='i'?'imperial-
|
|||
function image(file,alt=''){const n=el('img');n.src=ASSETS+file;n.alt=alt;n.loading='lazy';return n;}
|
||||
function button(text,action,cls=''){const n=el('button',text,cls);n.type='button';n.onclick=action;return n;}
|
||||
function field(label,values){const wrap=el('label',undefined,'progression-field'),input=el('select');wrap.append(el('span',label));for(const value of values)input.append(el('option',value));wrap.append(input);return wrap;}
|
||||
export function linkedPoliticalDecision(params,context){return context==='personal'&¶ms.get('xp')==='pol'&¶ms.get('view')==='decisions'?DECISION_CATALOGUE.find(d=>d.id===params.get('decision'))||null:null;}
|
||||
export function mountProgressionDesign(host,{context='personal',dashboard=false,organisation=null,members=[],office='IMP',manage=false,initialView=null}={}){
|
||||
if(!Object.hasOwn(CONTEXTS,context))context='personal';
|
||||
if(!document.querySelector('link[data-progression-design]')){const link=el('link');link.rel='stylesheet';link.href=new URL('./cp-v2-progression.css',import.meta.url).href;link.dataset.progressionDesign='';document.head.append(link);}
|
||||
const root=el('section',undefined,'progression-workspace'),notice=el('p','Design preview · Sample layout only. No XP, rewards, appointments or payments are issued.','progression-notice');
|
||||
const routeParams=new URLSearchParams(location.hash.split('?')[1]||'');let xpKind=routeParams.get('xp')==='pol'?'pol':'personal',polDecisionBranch='atreides';let activeContext=context,tab=['missions','decisions','history'].includes(initialView||routeParams.get('view'))?(initialView||routeParams.get('view')):'missions',selected=null,branch='a',officeCode=office,query='';
|
||||
const routeParams=new URLSearchParams(location.hash.split('?')[1]||'');let xpKind=routeParams.get('xp')==='pol'?'pol':'personal',polDecisionBranch='atreides';let activeContext=context,tab=['missions','decisions','history'].includes(initialView||routeParams.get('view'))?(initialView||routeParams.get('view')):'missions',selected=null,branch='a',officeCode=office,query='';let deepLink=linkedPoliticalDecision(routeParams,context);if(deepLink){activeContext='politics';officeCode=deepLink.office;selected=deepLink.id;}
|
||||
let connectorObserver=null,disposePersonal=null;const dossier=createProgressionDialog(root);
|
||||
const hero=el('header',undefined,'progression-hero'),head=el('div');head.append(el('small',manage?'IMPERIAL BUREAU · J.A.R.V.I.S.':'REALM PROGRESSION'),el('h2',manage?'Progression definitions':dashboard?'Quest Dashboard':'Missions & Decisions'),el('p','Your objectives, authority and recorded achievements.'));hero.append(image('exchange-quests-v1.png'),head);if(manage||(context!=='personal'&&context!=='clan')||!applyShellHeading(host,{title:context==='clan'?'Clan Missions & Decisions':dashboard?'Quest Dashboard':'Missions & Decisions',description:'Your objectives, authority and recorded achievements.',artwork:'exchange-quests-v1.png'}))root.append(hero);root.append(notice);
|
||||
const xpNav=el('nav',undefined,'progression-tabs progression-xp-types');xpNav.setAttribute('aria-label','XP type');const contextNav=el('nav',undefined,'progression-contexts'),gallery=el('section',undefined,'progression-gallery'),nav=el('nav',undefined,'progression-tabs'),content=el('section',undefined,'progression-content');nav.setAttribute('aria-label','Progression views');contextNav.setAttribute('aria-label','Progression contexts');
|
||||
|
|
@ -66,7 +67,7 @@ export function mountProgressionDesign(host,{context='personal',dashboard=false,
|
|||
connectorObserver=new ResizeObserver(connect);connectorObserver.observe(tree);requestAnimationFrame(connect);
|
||||
}
|
||||
function renderDecisions(){if(activeContext==='politics')appendOfficeDecisionBanner(content,officeCode);if(activeContext==='politics'&&!manage){const live=el('div');content.append(live);disposePersonal=mountOfficeRebellionDecisions(live,{officeKey:organisation?.id||({IMP:'emperor',ATR:'atreides',HAR:'harkonnen',COR:'corrino',ORD:'ordos',FRE:'fremen',BG:'veiled_concord',NF:'muad_dib',SG:'spacing_guild',CLD:'clan_delegate'})[officeCode]});}const toolbar=el('div',undefined,'progression-toolbar'),search=el('input');search.type='search';search.placeholder='Search decisions';search.setAttribute('aria-label','Search decisions');search.value=query;search.oninput=()=>{query=search.value;renderDecisionsList();};toolbar.append(search);if(activeContext==='personal'&&xpKind==='pol'){const chooser=field('Questgiver',POL_QUEST_BRANCHES.map(b=>b.title));chooser.querySelector('select').selectedIndex=POL_QUEST_BRANCHES.findIndex(b=>b.id===polDecisionBranch);chooser.onchange=e=>{polDecisionBranch=POL_QUEST_BRANCHES[e.target.selectedIndex].id;selected=null;render();};toolbar.append(chooser);}if((dashboard&&activeContext==='politics')||manage){const chooser=field('Office catalogue',OFFICES.map(([,name])=>name));chooser.querySelector('select').selectedIndex=OFFICES.findIndex(([id])=>id===officeCode);chooser.onchange=e=>{officeCode=OFFICES[e.target.selectedIndex][0];selected=null;render();};toolbar.append(chooser);}content.append(toolbar);const listHost=el('div');content.append(listHost);
|
||||
function renderDecisionsList(){listHost.replaceChildren();let rows=activeContext==='politics'||manage?[...DECISION_CATALOGUE.filter(d=>d.office===officeCode),...officeDecisionPreviews(officeCode)]:activeContext==='personal'&&xpKind==='pol'?(POL_QUEST_BRANCHES.find(b=>b.id===polDecisionBranch)?.decisions||[]):activeContext==='personal'?[{id:'P-MARK',title:'Equipment Mark eligibility',effect:'Level, materials and equipment restrictions remain necessary.',level:0,xp:0,cost:'Pending configuration'},{id:'P-RARITY',title:'Rarity enhancement eligibility',effect:'Use the existing rarity and Legendary upgrade policy.',level:0,xp:0,cost:'Pending configuration'},{id:'P-SEASON',title:'Seasonal completion entitlement',effect:'One non-tradable completion kit after all mandatory objectives.',level:0,xp:0,cost:'Earned entitlement'}]:[];rows=rows.filter(r=>(r.title+' '+r.effect).toLowerCase().includes(query.toLowerCase()));if(!rows.length){listHost.append(el('p','No decision definitions available for this selection. No authority is inferred.'));return;}selected=rows.find(r=>r.id===selected)?.id||rows[0].id;const layout=el('div',undefined,'progression-layout'),cards=el('div',undefined,'progression-decisions');for(const row of rows){const card=button('',()=>{selected=row.id;dossier.show(details(row,true),{title:lore(row.title),returnFocus:card});},'progression-decision');card.setAttribute('aria-haspopup','dialog');card.setAttribute('aria-pressed',String(row.id===selected));const art=activeContext==='politics'?POL_PLANNING_ART[officeCode]:activeContext==='personal'&&xpKind==='pol'?POL_PLANNING_ART[POL_QUEST_BRANCHES.find(b=>b.id===polDecisionBranch)?.office]:null;card.append(image(art?.banner||'exchange-political-positions-v1.png'),...(art?[planningImage(art.seal,art.title+' seal','pol-decision-seal')]:[]),el('small',row.id),el('strong',row.title),el('span',row.executionStatus==='clan-faith-controller'?'Invite a clan':row.executionStatus==='house-faith-controller'?'Review House referendum':row.executionStatus==='world-trade-controller'?'Review trade decision':politicalDecision(row.id)?'Review funded decision':row.id==='IMP-10'?'Manage House passage':faithBlessing(row.id)?'Prepare clan blessing':row.executionStatus==='war-exchange-controller'?'Manage war agreement':'View proposal · execution unavailable'));cards.append(card);}layout.append(cards);listHost.append(layout);}renderDecisionsList();
|
||||
function renderDecisionsList(){listHost.replaceChildren();let rows=activeContext==='politics'||manage?[...DECISION_CATALOGUE.filter(d=>d.office===officeCode),...officeDecisionPreviews(officeCode)]:activeContext==='personal'&&xpKind==='pol'?(POL_QUEST_BRANCHES.find(b=>b.id===polDecisionBranch)?.decisions||[]):activeContext==='personal'?[{id:'P-MARK',title:'Equipment Mark eligibility',effect:'Level, materials and equipment restrictions remain necessary.',level:0,xp:0,cost:'Pending configuration'},{id:'P-RARITY',title:'Rarity enhancement eligibility',effect:'Use the existing rarity and Legendary upgrade policy.',level:0,xp:0,cost:'Pending configuration'},{id:'P-SEASON',title:'Seasonal completion entitlement',effect:'One non-tradable completion kit after all mandatory objectives.',level:0,xp:0,cost:'Earned entitlement'}]:[];rows=rows.filter(r=>(r.title+' '+r.effect).toLowerCase().includes(query.toLowerCase()));if(!rows.length){listHost.append(el('p','No decision definitions available for this selection. No authority is inferred.'));return;}selected=rows.find(r=>r.id===selected)?.id||rows[0].id;const layout=el('div',undefined,'progression-layout'),cards=el('div',undefined,'progression-decisions');for(const row of rows){const card=button('',()=>{selected=row.id;dossier.show(details(row,true),{title:lore(row.title),returnFocus:card});},'progression-decision');card.setAttribute('aria-haspopup','dialog');card.setAttribute('aria-pressed',String(row.id===selected));const art=activeContext==='politics'?POL_PLANNING_ART[officeCode]:activeContext==='personal'&&xpKind==='pol'?POL_PLANNING_ART[POL_QUEST_BRANCHES.find(b=>b.id===polDecisionBranch)?.office]:null;card.append(image(art?.banner||'exchange-political-positions-v1.png'),...(art?[planningImage(art.seal,art.title+' seal','pol-decision-seal')]:[]),el('small',row.id),el('strong',row.title),el('span',row.executionStatus==='clan-faith-controller'?'Invite a clan':row.executionStatus==='house-faith-controller'?'Review House referendum':row.executionStatus==='world-trade-controller'?'Review trade decision':politicalDecision(row.id)?'Review funded decision':row.id==='IMP-10'?'Manage House passage':faithBlessing(row.id)?'Prepare clan blessing':row.executionStatus==='war-exchange-controller'?'Manage war agreement':'View proposal · execution unavailable'));cards.append(card);if(deepLink?.id===row.id){deepLink=null;queueMicrotask(()=>{if(card.isConnected)card.click();});}}layout.append(cards);listHost.append(layout);}renderDecisionsList();
|
||||
}
|
||||
function render(){dossier.close();connectorObserver?.disconnect();disposePersonal?.();disposePersonal=null;notice.textContent=activeContext==='personal'&&!manage?(xpKind==='pol'?'Reputation missions use verified J.A.R.V.I.S. records and their system questgivers. Decision execution awaits configuration.':'Personal missions use verified J.A.R.V.I.S. records. Decision and organisation integrations remain in preview.'):'Connected decisions open a review and confirmation. Other proposals remain unavailable until their consumers are connected.';root.dataset.context=activeContext;notice.hidden=activeContext==='personal'&&!manage;nav.hidden=report.available&&activeContext==='personal'&&!manage;report.setNavigation(xpKind,tab);report.showBranches(activeContext==='personal');xpNav.replaceChildren();xpNav.hidden=activeContext!=='personal'||manage||report.available;if(!xpNav.hidden)for(const [kind,label]of [['personal','Personal level'],['pol','Reputation level']]){const b=button(label,()=>{xpKind=kind;selected=null;render();});b.setAttribute('aria-pressed',String(kind===xpKind));xpNav.append(b);}contextNav.replaceChildren();for(const[id,[label]]of Object.entries(CONTEXTS)){const b=button(label,()=>{activeContext=id;selected=null;query='';render();});b.setAttribute('aria-pressed',String(id===activeContext));contextNav.append(b);}renderGallery();nav.replaceChildren();for(const[id,label]of [['missions',manage?'Mission Definitions':'Missions'],['decisions',manage?'Decision Definitions':'Decisions'],...(manage?[['rewards','Progression & Rewards']]:[]),['history','History']]){const b=button(label,()=>{tab=id;selected=null;render();});b.setAttribute('aria-pressed',String(tab===id));nav.append(b);}content.replaceChildren();if(activeContext==='clan'&&!manage){notice.hidden=true;disposePersonal=mountClanRebellions(content,{clanId:organisation?.id||null,embedded:true,view:tab,onDecisions:()=>{tab='decisions';render();}});return;}if(activeContext==='personal'&&!manage&&['missions','history'].includes(tab))disposePersonal=mountPersonalProgression(content,{view:tab,apiBase:xpKind==='pol'?'/api/progression/pol':'/api/progression',externalBranches:report.available,initialBranch:branch,onCareerNavigate:id=>{xpKind='pol';tab='missions';branch=id;selected=null;render();},onData:data=>report.setJournal(xpKind,data),onBranches:(rows,id)=>{branch=id;report.setBranches(rows,id);}});else if(tab==='missions')renderMissions();else if(tab==='decisions')renderDecisions();else if(tab==='rewards'){content.append(el('h3','Progression & Rewards'),field('Season cap',['70 · proposed']),field('Milestone announcements',['Halfway and completion only']),el('p','Rewards, XP curves, repair recipes and signing editions await backend review. No configuration writes enabled.'));}else content.append(el('h3','J.A.R.V.I.S. History'),el('p','Verified completion, claims, decisions and any staff overrides will appear here after integration. No sample audit records are shown.'));}
|
||||
render();return()=>{dossier.dispose();connectorObserver?.disconnect();disposePersonal?.();report.dispose();root.remove();};
|
||||
|
|
|
|||
10
website/tests/pol-decision-deeplink.test.mjs
Normal file
10
website/tests/pol-decision-deeplink.test.mjs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {linkedPoliticalDecision} from '../control-panel/public/cp-v2/cp-v2-progression.mjs';
|
||||
test('native decision links open the exact existing political catalogue entry, not an action or arbitrary route',()=>{
|
||||
for(const [id,office] of [['IMP-02','IMP'],['FRE-07','FRE'],['NF-CONVERT','NF'],['ORD-03','ORD']]){
|
||||
assert.equal(linkedPoliticalDecision(new URLSearchParams({xp:'pol',view:'decisions',decision:id}),'personal')?.office,office);
|
||||
}
|
||||
for(const params of [{xp:'personal',view:'decisions',decision:'IMP-02'},{xp:'pol',view:'missions',decision:'IMP-02'},{xp:'pol',view:'decisions',decision:'unknown'}])assert.equal(linkedPoliticalDecision(new URLSearchParams(params),'personal'),null);
|
||||
assert.equal(linkedPoliticalDecision(new URLSearchParams({xp:'pol',view:'decisions',decision:'IMP-02'}),'clan'),null);
|
||||
});
|
||||
Loading…
Reference in a new issue

Staff