forked from unimatrix/web
32 lines
4.4 KiB
JavaScript
32 lines
4.4 KiB
JavaScript
// Five curated, self-contained designs. No political seals or remote resources.
|
|
const designs=Object.freeze([
|
|
{id:'desert-crest',name:'Desert crest',modes:['clan','company']},
|
|
{id:'caravan-mark',name:'Caravan mark',modes:['clan','company']},
|
|
{id:'service-seal',name:'Service seal',modes:['seal']},
|
|
{id:'service-award',name:'Service award',modes:['award']},
|
|
{id:'desert-traveller',name:'Desert traveller',modes:['character']}
|
|
]);
|
|
export const templateModes=Object.freeze(['clan','company','character','seal','award']);
|
|
export const templateCatalogue=mode=>designs.filter(d=>d.modes.includes(mode)).map(({id,name})=>({id,name,version:1}));
|
|
const escape=value=>value.replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
export function renderPaintTemplate({mode,id,title='YOUR NAME',primary='#143E30',secondary='#D7B65D',trim='#F3E5B8',outfit='hood',sealData=null}){
|
|
if(!designs.some(d=>d.id===id&&d.modes.includes(mode)))throw TypeError('Choose an available design.');
|
|
if(typeof title!=='string'||title.length>40||/[\u0000-\u001f]/.test(title))throw TypeError('Use a name up to 40 characters.');
|
|
for(const colour of [primary,secondary,trim])if(typeof colour!=='string'||!/^#[a-f0-9]{6}$/i.test(colour))throw TypeError('Choose valid design colours.');
|
|
if(!['hood','armour','headscarf'].includes(outfit))throw TypeError('Choose a character outfit.');
|
|
const text=(y,size=27)=>`<text x="256" y="${y}" text-anchor="middle" font-family="Georgia,serif" font-size="${size}" fill="${trim}">${escape(title)}</text>`;
|
|
const star=`<path d="M256 116 274 164 325 168 285 201 297 251 256 223 215 251 227 201 187 168 238 164Z" fill="${secondary}" stroke="${trim}" stroke-width="4"/>`;
|
|
let art;
|
|
if(id==='desert-crest')art=`<path d="M92 58H420V264Q414 373 256 452 98 373 92 264Z" fill="${primary}" stroke="${secondary}" stroke-width="14"/><path d="M115 80H397V263Q389 354 256 425 123 354 115 263Z" fill="none" stroke="${trim}" stroke-width="3"/>${star}<path d="M130 308Q190 248 256 308 322 248 382 308M145 333Q210 290 256 333 302 290 367 333" fill="none" stroke="${secondary}" stroke-width="8"/>${text(379,24)}`;
|
|
if(id==='caravan-mark')art=`<path d="M256 44 450 154V358L256 468 62 358V154Z" fill="${primary}" stroke="${secondary}" stroke-width="12"/><path d="M256 72 425 169V343L256 440 87 343V169Z" fill="none" stroke="${trim}" stroke-width="3"/>${star}<path d="M126 280H386L362 337H150Z" fill="${secondary}"/><path d="M174 279 218 229 256 270 294 229 338 279" fill="none" stroke="${trim}" stroke-width="7"/>${text(386,24)}`;
|
|
if(id==='service-seal'||id==='service-award'){
|
|
if(typeof sealData!=='string'||!/^data:image\/png;base64,[a-zA-Z0-9+/]+=*$/.test(sealData))throw TypeError('Current service artwork is unavailable.');
|
|
const ribbons=id==='service-award'?`<path d="M154 300 110 466 185 432 225 477 255 326M258 326 294 477 334 432 406 466 360 300" fill="${primary}" stroke="${secondary}" stroke-width="8"/>`:'';
|
|
art=`${ribbons}<circle cx="256" cy="235" r="190" fill="${primary}" stroke="${secondary}" stroke-width="12"/><circle cx="256" cy="235" r="172" fill="none" stroke="${trim}" stroke-width="3"/><image href="${sealData}" x="151" y="102" width="210" height="210"/>${text(348,23)}<path d="M166 371H346" stroke="${secondary}" stroke-width="4"/>`;
|
|
}
|
|
if(id==='desert-traveller'){
|
|
const head=outfit==='hood'?`<path d="M128 240V112L192 48H320L384 112V240H344V135L304 96H208L168 135V240Z" fill="${primary}" stroke="${secondary}" stroke-width="8"/>`:outfit==='headscarf'?`<path d="M144 112V64H368V112H392V256H352V136H160V256H120V112Z" fill="${trim}"/><path d="M136 104H376V128H136Z" fill="${primary}"/>`:`<path d="M160 96V64H352V96H376V160H136V96Z" fill="${secondary}"/>`;
|
|
art=`<path d="M104 456V304L168 248H344L408 304V456Z" fill="${primary}" stroke="${secondary}" stroke-width="8"/><path d="M176 304H336V432H176Z" fill="${secondary}"/><path d="M200 320H312V352H200ZM200 376H312V408H200Z" fill="${primary}"/><path d="M176 112H336V224L304 256H208L176 224Z" fill="#C99670"/><path d="M192 160H224V176H192ZM288 160H320V176H288Z" fill="#80CFE6"/><path d="M224 216H288V224H224Z" fill="#81533F"/>${head}<path d="M152 268 200 300H312L360 268" fill="none" stroke="${trim}" stroke-width="12"/>${text(493,22)}`;
|
|
}
|
|
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512"><title>${escape(title)}</title><g id="editable-design">${art}</g></svg>`;
|
|
}
|

Staff