39 lines
7.8 KiB
JavaScript
39 lines
7.8 KiB
JavaScript
import {showInvalidKey} from './cp-v2-key-validation.mjs';
|
|
import {parseOrganisationCode} from '../codex-code-format.mjs';
|
|
import {createDeedArtwork} from './cp-v2-deed-art.mjs';
|
|
import {element as el} from './cp-v2-page-template.mjs';
|
|
|
|
// Presentation only. Recognising a format never verifies ownership or grants a right.
|
|
export function describeRedemption(value){
|
|
const entered=String(value||'').trim().toUpperCase();let code=entered,edition=null;try{const parsed=parseOrganisationCode(entered);code=parsed.canonical;edition=parsed.edition;}catch{}
|
|
const types=[
|
|
[/^POL-CLAN-[A-F0-9]{48}$/,'politics-clan','Political clan membership','Bound to the current office deed, not a political decision or Royal appointment.','Open Politics CP',false,'https://www.dunerealms.com/government.html'],
|
|
[/^(?:CLAN-SUB|COM-SUB)-[A-F0-9]{48}$/,'subhouse','Subordinate organisation founding','This key is bound to its mother deed. It cannot create an independent or Royal charter.','Subhouse creation adapter pending',false],
|
|
[/^DRK-[A-Z2-7]{32}$/,'kit','Kit delivery','Requests your kit delivery. The game confirms arrival.','Redeem kit',true],
|
|
[/^DRQ-[A-F0-9]{40}$/,'discovery','Discovery reward','Claims your earned discovery reward. The service checks eligibility before crediting.','Claim reward',true],
|
|
[/^(?:DRU|UP)-[A-F0-9]{48}$/,'token','Upgrade Token','Apply this token to a saved kit in Imperial Tailor.','Open Imperial Tailor',false,'#realm/kits-exchange'],
|
|
[/^CLAN-[A-F0-9]{48}$/,'clan','Clan founding right','Upgrades your existing Basic clan to an Original House that can become a mother house. A Royal House requires a separate political appointment.','Upgrade my Basic clan',true],
|
|
[/^COM-[A-F0-9]{48}$/,'company','Company founding right','Upgrades your existing Basic company using its separate original founding right.','Open Company settings',false,'https://corp.dunerealms.com/#company/settings'],
|
|
[/^POL-[A-F0-9]{48}$/,'politics','Political appointment','Applies the specific appointment recorded by a political decision. The decision determines the organisation and title.','Political appointments coming soon',false]
|
|
];
|
|
for(const [pattern,kind,title,description,action,available,href] of types)if(pattern.test(code))return {code:entered,edition,kind,title,description,action,available,href};
|
|
throw Error('Enter a complete private code. Community commands are used in game.');
|
|
}
|
|
|
|
export function createCodeRedemption(){
|
|
let reviewed=null,locked=false;
|
|
const root=el('section',undefined,'code-redemption'),hero=el('header',undefined,'reward-code-banner'),art=el('img');art.src='https://www.dunerealms.com/assets/imperial-seal-128.png';art.alt='';const heading=el('div');heading.append(el('small','SPOST · IMPERIAL CODE OFFICE'),el('h4','Present your code. Open your next chapter.'),el('p','Your SPost counter for rewards, founding rights and political appointments.'));hero.append(art,heading);
|
|
const layout=el('div',undefined,'code-redemption-layout'),form=el('form',undefined,'code-redemption-card'),entry=el('fieldset'),legend=el('legend','1 · Enter your private code'),label=el('label','Code'),input=el('input');input.type='text';input.autocomplete='off';input.spellcheck=false;input.autocapitalize='characters';input.required=true;input.maxLength=128;input.placeholder='Paste your complete code';input.setAttribute('aria-describedby','redemption-code-help');const help=el('p','Keep your code private. Checking its format does not use it.','code-redemption-muted');help.id='redemption-code-help';label.append(input);const inspect=el('button','Review code');inspect.type='button';entry.append(legend,label,help,inspect);
|
|
const preview=el('fieldset',undefined,'code-redemption-preview');preview.hidden=true;preview.append(el('legend','2 · Review & confirm'));const badge=el('span',undefined,'reward-kind'),title=el('h5'),effect=el('p'),verification=el('p','Format recognised. Ownership and eligibility are checked when you submit.','code-redemption-muted'),check=el('input');check.type='checkbox';const consent=el('label',undefined,'code-redemption-consent');consent.append(check,el('span','I understand this action and want to use my code.'));const submit=el('button','Confirm redemption');submit.type='submit';submit.disabled=true;const destination=el('a');destination.hidden=true;preview.append(badge,title,effect,verification,consent,submit,destination);const result=el('p',undefined,'code-redemption-result');result.setAttribute('role','status');result.setAttribute('aria-live','polite');form.append(entry,preview,result);
|
|
const guide=el('aside',undefined,'code-redemption-card code-redemption-guide');guide.append(el('small','WHAT CAN YOU PRESENT?'),el('h5','Your code chooses the route.'));
|
|
for(const [kind,name,copy] of [['kit','Kits & discoveries','Existing DRK and DRQ codes can be redeemed here.'],['clan','House & company charters','Create your Basic clan first. CLAN upgrades your Basic clan to an Original House. Keep your separate COM code for Company CP.'],['politics','Political appointments','POL codes come from an approved decision. Founding alone does not confer a Royal title.'],['token','Upgrade Tokens','DRU tokens are applied to a saved kit in Imperial Tailor.']]){const card=el('div',undefined,'code-redemption-guide-item');card.append(el('span',name,'reward-kind reward-kind-'+kind),el('p',copy));guide.append(card);}const register=el('a','← View your codes');register.href='#';register.onclick=e=>{e.preventDefault();root.dispatchEvent(new CustomEvent('show-code-register',{bubbles:true}));};guide.append(createDeedArtwork('keys'),register);layout.append(form,guide);root.append(hero,layout);
|
|
function sync(){submit.disabled=locked||!reviewed?.available||!check.checked;inspect.disabled=locked;input.disabled=locked;check.disabled=locked;}
|
|
function invalidate(){reviewed=null;check.checked=false;preview.hidden=true;result.textContent='';sync();}
|
|
input.oninput=invalidate;check.onchange=sync;
|
|
inspect.onclick=()=>{if(locked)return;try{reviewed=describeRedemption(input.value);check.checked=false;badge.className='reward-kind reward-kind-'+reviewed.kind;badge.textContent=reviewed.available?'Ready to submit':'Dedicated route';title.textContent=reviewed.title;effect.textContent=reviewed.description;submit.textContent=reviewed.action;submit.hidden=!reviewed.available;consent.hidden=!reviewed.available;destination.hidden=!reviewed.href;if(reviewed.href){destination.href=reviewed.href;destination.textContent=reviewed.action;}verification.textContent=reviewed.available?'Format recognised. Ownership and eligibility are checked when you submit.':reviewed.href?'Continue in the dedicated workshop to choose your kit.':'This route is being connected. Your code has not been used.';preview.hidden=false;result.textContent='';sync();}catch(error){invalidate();showInvalidKey(result,error.message);void fetch('/api/jarvis/validate',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:input.value})}).catch(()=>{});input.focus();}};
|
|
return {root,form,input,check,submit,result,setLocked(value){locked=!!value;sync();},reset(){form.reset();invalidate();},reviewedCode(){if(!reviewed?.available||describeRedemption(input.value).code!==reviewed.code||!check.checked)throw Error('Review your code and confirm the action first.');return reviewed.code;}};
|
|
}
|
|
|
|
export function createCodeOfficeBranding(){
|
|
const footer=el('footer',undefined,'code-office-provider'),brands=el('div',undefined,'code-office-provider-brands'),logo=el('img');logo.src='https://www.dunerealms.com/assets/spost-logo-v1.svg';logo.alt='SPost';logo.width=130;logo.height=43;const group=el('a');group.href='https://www.dunerealms.com/corrino-group.html';const art=el('img');art.src='https://www.dunerealms.com/assets/corrino-group-v4.png';art.alt='Corrino Group';art.width=116;art.height=42;group.append(el('span','part of'),art);brands.append(logo,group);footer.append(el('span','Code services provided by'),brands);return footer;
|
|
}
|

Staff