web/website/control-panel/public/imperial-atelier.mjs
Dev 6deb4a2e7d DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
2026-11-13 00:05:14 +01:00

7 lines
3.1 KiB
JavaScript

import {createKitGenerator} from './kit-generator.mjs';
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
const dashboard=document.getElementById('dashboard'),section=el('section');section.id='imperial-atelier';section.className='clan-center';section.hidden=true;const hero=el('header');hero.className='imperial-atelier-hero';const img=el('img');img.src='https://www.dunerealms.com/assets/imperial-atelier-v1.webp';img.alt='The Imperial Atelier ceremonial stillsuit workshop';img.className='atelier-banner';const copy=el('div');copy.append(el('p','REGALIA OF THE REALM'),el('h2','The Imperial Atelier'),el('p','Ceremonial stillsuits for the Emperor and current officeholders.'));hero.append(copy);const notice=el('p');notice.role='status';const content=el('div');section.append(hero,img,el('p','* Your linked Minecraft UUID must currently hold the office. Designs apply before the first kit claim of a term. Editing later does not issue another kit or restyle items already claimed.'),notice,content);dashboard?.append(section);let generation=0,actor=null;const link=el('a','The Imperial Atelier *');link.href='#imperial-atelier';
async function api(body){const r=await fetch('/api/imperial-atelier',{method:body?'POST':'GET',cache:'no-store',headers:body?{'Content-Type':'application/json'}:{},...(body?{body:JSON.stringify(body)}:{})});const d=await r.json();if(!r.ok)throw Error(d.message||'Atelier unavailable.');return d;}
async function load(){const g=generation;if(!actor)return;try{const d=await api();if(g!==generation)return;content.replaceChildren();if(!d.canDesign){link.remove();notice.textContent=d.linked?'Only current officeholders can commission ceremonial regalia.':'Link your Minecraft identity to check your current office.';return;}dashboard.querySelector('nav')?.append(link);notice.textContent='Current offices confirmed by the game.';for(const office of d.offices){const box=el('article');box.append(el('h3',office.office.replaceAll('_',' ').replace(/\b\w/g,c=>c.toUpperCase())));const generator=createKitGenerator({context:'Current office · '+office.office,initial:office,quality:office.quality||'Uncommon',art:'imperial-atelier-v1.webp',maxLoreLines:6,maxLoreLineLength:120,onSave:async values=>{const current=generation;await api({...values,office:office.office,term:office.term,version:office.version});if(current===generation)await load();}});box.append(generator.element);content.append(box);}}catch(e){if(g===generation)notice.textContent=e.message;}}
function session(user){generation++;actor=user?.permissions?.includes('web.menu.game')?user.username:null;link.remove();content.replaceChildren();section.hidden=!actor;if(actor)load();}
window.addEventListener('dune:session',e=>session(e.detail));window.addEventListener('dune:page',e=>{if(e.detail?.page==='imperial-atelier')load();});window.addEventListener('hashchange',()=>{if(location.hash==='#imperial-atelier')load();});const g=generation;try{const r=await fetch('/api/auth/session',{cache:'no-store'});if(r.ok){const d=await r.json();if(g===generation)session(d.user);}}catch{}