v1.5.24 - smarter generation

This commit is contained in:
Azgaar 2021-02-13 21:52:50 +03:00
parent e4e40fab49
commit 2f3f5d05fb
4 changed files with 17 additions and 24 deletions

View file

@ -16,8 +16,8 @@
const charges = { const charges = {
// categories selection // categories selection
types: { conventional: 30, crosses: 8, animals: 2, animalHeads: 1, birds: 2, aquatic: 1, seafaring: 1, fantastic: 3, plants: 1, agriculture: 1, arms: 3, bodyparts: 1, people: 1, architecture: 1, miscellaneous: 3, inescutcheon: 3 }, types: { conventional: 30, crosses: 8, animals: 2, animalHeads: 1, birds: 2, fantastic: 3, plants: 1, agriculture: 1, arms: 3, bodyparts: 1, people: 1, architecture: 1, miscellaneous: 3, inescutcheon: 3 },
single: { conventional: 12, crosses: 8, plants: 2, animals: 10, animalHeads: 2, birds: 4, aquatic: 2, seafaring: 2, fantastic: 7, agriculture: 1, arms: 6, bodyparts: 1, people: 1, architecture: 1, miscellaneous: 9, inescutcheon: 5 }, single: { conventional: 12, crosses: 8, plants: 2, animals: 10, animalHeads: 2, birds: 4, fantastic: 7, agriculture: 1, arms: 6, bodyparts: 1, people: 1, architecture: 1, miscellaneous: 9, inescutcheon: 5 },
semy: { conventional: 12, crosses: 3, plants: 1 }, semy: { conventional: 12, crosses: 3, plants: 1 },
// generic categories // generic categories
conventional: { conventional: {
@ -35,19 +35,17 @@
lionRampant: 5, lionPassant: 2, wolfRampant: 1, wolfPassant: 1, wolfStatant: 1, greyhoundCourant: 1, boarRampant: 1, lionRampant: 5, lionPassant: 2, wolfRampant: 1, wolfPassant: 1, wolfStatant: 1, greyhoundCourant: 1, boarRampant: 1,
horseRampant: 2, horseSalient: 1, bearRampant: 2, bearPassant: 1, bullPassant: 1, goat: 1, lamb: 1, elephant: 1 horseRampant: 2, horseSalient: 1, bearRampant: 2, bearPassant: 1, bullPassant: 1, goat: 1, lamb: 1, elephant: 1
}, },
animalHeads: { wolfHeadErased: 2, bullHeadCaboshed: 1, deerHeadCaboshed: 1 }, animalHeads: { wolfHeadErased: 1, bullHeadCaboshed: 1, deerHeadCaboshed: 1 },
fantastic: { dragonPassant: 2, dragonRampant: 2, wyvern: 1, wyvernWithWingsDisplayed: 1, griffinPassant: 1, griffinRampant: 1, eagleTwoHeards: 2, unicornRampant: 1, pegasus: 1, serpent: 1 }, fantastic: { dragonPassant: 2, dragonRampant: 2, wyvern: 1, wyvernWithWingsDisplayed: 1, griffinPassant: 1, griffinRampant: 1, eagleTwoHeards: 2, unicornRampant: 1, pegasus: 1, serpent: 1 },
birds: { eagle: 9, raven: 2, cock: 3, parrot: 1, swan: 2, swanErased: 1, heron: 1 }, birds: { eagle: 9, raven: 1, cock: 3, parrot: 1, swan: 2, swanErased: 1, heron: 1 },
plants: { tree: 1, cinquefoil: 1, rose: 1 }, plants: { tree: 1, cinquefoil: 1, rose: 1 },
aquatic: { escallop: 5, pike: 1, cancer: 1, dolphin: 1 }, agriculture: { garb: 1, rake: 1 },
seafaring: { anchor: 6, boat: 2, lymphad: 2, armillarySphere: 1 },
agriculture: { garb: 2, rake: 1 },
arms: { sword: 5, sabre: 1, sabresCrossed: 1, hatchet: 2, lochaberAxe: 1, mallet: 1, bowWithArrow: 2, bow: 1, arrow: 1, arrowsSheaf: 1 }, arms: { sword: 5, sabre: 1, sabresCrossed: 1, hatchet: 2, lochaberAxe: 1, mallet: 1, bowWithArrow: 2, bow: 1, arrow: 1, arrowsSheaf: 1 },
bodyparts: { hand: 4, head: 1, headWreathed: 1 }, bodyparts: { hand: 4, head: 1, headWreathed: 1 },
people: { cavalier: 1 }, people: { cavalier: 1 },
architecture: { tower: 1, castle: 1 }, architecture: { tower: 1, castle: 1 },
miscellaneous: { miscellaneous: {
crown: 3, orb: 1, chalice: 1, key: 1, buckle: 1, bugleHorn: 1, bell: 2, pot: 1, horseshoe: 3, stagsAttires: 1, cowHorns: 2, wing: 1, wingSword: 1, crown: 3, orb: 1, chalice: 1, key: 1, buckle: 1, bugleHorn: 1, bell: 1, pot: 1, horseshoe: 3, stagsAttires: 1, cowHorns: 2, wing: 1, wingSword: 1,
lute: 1, harp: 1, wheel: 2, crosier: 1, log: 1}, lute: 1, harp: 1, wheel: 2, crosier: 1, log: 1},
// selection based on culture type: // selection based on culture type:
Naval: { anchor: 3, boat: 1, lymphad: 2, armillarySphere: 1, escallop: 1, dolphin: 1 }, Naval: { anchor: 3, boat: 1, lymphad: 2, armillarySphere: 1, escallop: 1, dolphin: 1 },
@ -195,10 +193,6 @@
if (parent === "custom") parent = null; if (parent === "custom") parent = null;
let usedPattern = null, usedTinctures = []; let usedPattern = null, usedTinctures = [];
// TO-DO
// test in FF
// stringify COA on save?
const t1 = P(kinship) ? parent.t1 : getTincture("field"); const t1 = P(kinship) ? parent.t1 : getTincture("field");
if (t1.includes("-")) usedPattern = t1; if (t1.includes("-")) usedPattern = t1;
const coa = {t1}; const coa = {t1};
@ -209,7 +203,10 @@
const rareDivided = ["chief", "terrace", "chevron", "quarter", "flaunches"].includes(ordinary); const rareDivided = ["chief", "terrace", "chevron", "quarter", "flaunches"].includes(ordinary);
const divisioned = rareDivided ? P(.03) : charge && ordinary ? P(.03) : charge ? P(.3) : ordinary ? P(.7) : P(.995); // 33% for division const divisioned = rareDivided ? P(.03) : charge && ordinary ? P(.03) : charge ? P(.3) : ordinary ? P(.7) : P(.995); // 33% for division
const division = divisioned ? parent?.division && P(kinship - .1) ? parent.division.division : rw(divisions.variants) : null; const division = divisioned ? parent?.division && P(kinship - .1) ? parent.division.division : rw(divisions.variants) : null;
if (charge) charge = parent?.charges && P(kinship - .1) ? parent.charges[0].charge : type && P(.3) ? rw(charges[type]) : selectCharge(); if (charge) charge =
parent?.charges && P(kinship - .1) ? parent.charges[0].charge :
type && type !== "Generic" && P(.3) ? rw(charges[type]) :
selectCharge();
if (division) { if (division) {
const t = getTincture("division", usedTinctures, P(.98) ? coa.t1 : null); const t = getTincture("division", usedTinctures, P(.98) ? coa.t1 : null);

View file

@ -968,18 +968,16 @@
} }
async function fetchCharge(charge, id) { async function fetchCharge(charge, id) {
const fetched = fetch("https://azgaar.github.io/Armoria/charges/" + charge + ".svg") const fetched = fetch("https://azgaar.github.io/Armoria/charges/" + charge + ".svg").then(res => {
.then(res => {
if (res.ok) return res.text(); if (res.ok) return res.text();
else throw new Error("Cannot fetch charge"); else throw new Error("Cannot fetch charge");
}) }).then(text => {
.then(text => {
const html = document.createElement("html"); const html = document.createElement("html");
html.innerHTML = text; html.innerHTML = text;
const g = html.querySelector("g"); const g = html.querySelector("g");
g.setAttribute("id", charge + "_" + id); g.setAttribute("id", charge + "_" + id);
return g.outerHTML; return g.outerHTML;
}); }).catch(err => console.error(err));
return fetched; return fetched;
} }

View file

@ -257,13 +257,13 @@ function editEmblem(type, id, el) {
const img = new Image(); const img = new Image();
img.src = url; img.src = url;
img.onload = async function() { img.onload = function() {
if (format === "jpeg") { if (format === "jpeg") {
ctx.fillStyle = "#fff"; ctx.fillStyle = "#fff";
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
} }
ctx.drawImage(img, 0, 0, canvas.width, canvas.height); ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
const URL = await canvas.toDataURL("image/" + format, .92); const URL = canvas.toDataURL("image/" + format, .92);
link.href = URL; link.href = URL;
link.click(); link.click();
window.setTimeout(() => window.URL.revokeObjectURL(URL), 5000); window.setTimeout(() => window.URL.revokeObjectURL(URL), 5000);
@ -277,12 +277,10 @@ function editEmblem(type, id, el) {
return url; return url;
} }
function getSVG(svg, coa, size) { function getSVG(svg, size) {
const clone = svg.cloneNode(true); // clone svg const clone = svg.cloneNode(true); // clone svg
clone.setAttribute("width", size); clone.setAttribute("width", size);
clone.setAttribute("height", size); clone.setAttribute("height", size);
return (new XMLSerializer()).serializeToString(clone); return (new XMLSerializer()).serializeToString(clone);
} }

View file

@ -709,7 +709,7 @@ function applyStyleOnLoad() {
stylePreset.value = preset; stylePreset.value = preset;
stylePreset.dataset.old = preset; stylePreset.dataset.old = preset;
} else { } else {
if (preset !== "styleDefault" && ERROR) console.error(`Style preset ${preset} is not available in localStorage, applying default style`); if (preset && preset !== "styleDefault" && ERROR) console.error(`Style preset ${preset} is not available in localStorage, applying default style`);
stylePreset.value = "styleDefault"; stylePreset.value = "styleDefault";
stylePreset.dataset.old = preset; stylePreset.dataset.old = preset;
applyDefaultStyle(); applyDefaultStyle();