diff --git a/index.html b/index.html index 091d55b3..d8d3caf8 100644 --- a/index.html +++ b/index.html @@ -7940,7 +7940,7 @@ - + @@ -7950,7 +7950,7 @@ - + @@ -7961,12 +7961,12 @@ - + - + @@ -7995,17 +7995,17 @@ - + - + - + diff --git a/modules/coa-generator.js b/modules/coa-generator.js index 24b27cfa..669233eb 100644 --- a/modules/coa-generator.js +++ b/modules/coa-generator.js @@ -1126,7 +1126,7 @@ window.COA = (function () { }; const generate = function (parent, kinship, dominion, type) { - if (!parent || parent === "custom") { + if (!parent || parent.custom) { parent = null; kinship = 0; dominion = 0; diff --git a/modules/coa-renderer.js b/modules/coa-renderer.js index 732aa92e..047862c4 100644 --- a/modules/coa-renderer.js +++ b/modules/coa-renderer.js @@ -2023,14 +2023,8 @@ window.COArenderer = (function () { // render coa if does not exist const trigger = async function (id, coa) { - if (coa === "custom") { - console.warn("Cannot render custom emblem", coa); - return; - } - if (!coa) { - console.warn(`Emblem ${id} is undefined`); - return; - } + if (!coa) return console.warn(`Emblem ${id} is undefined`); + if (coa.custom) return console.warn("Cannot render custom emblem", coa); if (!document.getElementById(id)) return draw(id, coa); }; diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js index 0fa604a5..787cabee 100644 --- a/modules/dynamic/auto-update.js +++ b/modules/dynamic/auto-update.js @@ -650,4 +650,53 @@ export function resolveVersionConflicts(version) { .attr("src", "https://i2.wp.com/azgaar.files.wordpress.com/2021/10/marble-big.jpg"); } } + + if (version < 1.91) { + // from 1.91.00 custom coa is moved to coa object + pack.states.forEach(state => { + if (state.coa === "custom") state.coa = {custom: true}; + }); + pack.provinces.forEach(province => { + if (province.coa === "custom") province.coa = {custom: true}; + }); + pack.burgs.forEach(burg => { + if (burg.coa === "custom") burg.coa = {custom: true}; + }); + + // from 1.91.00 emblems don't have transform attribute + emblems.selectAll("use").each(function () { + const transform = this.getAttribute("transform"); + if (!transform) return; + + const [dx, dy] = parseTransform(transform); + const x = Number(this.getAttribute("x")) + Number(dx); + const y = Number(this.getAttribute("y")) + Number(dy); + + this.setAttribute("x", x); + this.setAttribute("y", y); + this.removeAttribute("transform"); + }); + + // from 1.91.00 coaSize is moved to coa object + pack.states.forEach(state => { + if (state.coaSize) { + state.coa.size = state.coaSize; + delete state.coaSize; + } + }); + + pack.provinces.forEach(province => { + if (province.coaSize) { + province.coa.size = province.coaSize; + delete province.coaSize; + } + }); + + pack.burgs.forEach(burg => { + if (burg.coaSize) { + burg.coa.size = burg.coaSize; + delete burg.coaSize; + } + }); + } } diff --git a/modules/dynamic/editors/cultures-editor.js b/modules/dynamic/editors/cultures-editor.js index fe44db45..053a177e 100644 --- a/modules/dynamic/editors/cultures-editor.js +++ b/modules/dynamic/editors/cultures-editor.js @@ -401,7 +401,7 @@ function cultureChangeEmblemsShape() { }; pack.states.forEach(state => { - if (state.culture !== culture || !state.i || state.removed || !state.coa || state.coa === "custom") return; + if (state.culture !== culture || !state.i || state.removed || !state.coa || state.coa.custom) return; if (shape === state.coa.shield) return; state.coa.shield = shape; rerenderCOA("stateCOA" + state.i, state.coa); @@ -413,7 +413,7 @@ function cultureChangeEmblemsShape() { !province.i || province.removed || !province.coa || - province.coa === "custom" + province.coa.custom ) return; if (shape === province.coa.shield) return; @@ -422,7 +422,7 @@ function cultureChangeEmblemsShape() { }); pack.burgs.forEach(burg => { - if (burg.culture !== culture || !burg.i || burg.removed || !burg.coa || burg.coa === "custom") return; + if (burg.culture !== culture || !burg.i || burg.removed || !burg.coa || burg.coa.custom) return; if (shape === burg.coa.shield) return; burg.coa.shield = shape; rerenderCOA("burgCOA" + burg.i, burg.coa); diff --git a/modules/io/load.js b/modules/io/load.js index 13b2b6e7..037675d7 100644 --- a/modules/io/load.js +++ b/modules/io/load.js @@ -435,7 +435,7 @@ async function parseLoadedData(data) { { // dynamically import and run auto-udpdate script const versionNumber = parseFloat(params[0]); - const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.87.08"); + const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.91.00"); resolveVersionConflicts(versionNumber); } diff --git a/modules/ui/editors.js b/modules/ui/editors.js index c3e72b35..ab1bcc66 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -1182,7 +1182,7 @@ async function editStates() { async function editCultures() { if (customization) return; - const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.89.09"); + const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.91.00"); Editor.open(); } diff --git a/modules/ui/emblems-editor.js b/modules/ui/emblems-editor.js index c02ee305..2f36454c 100644 --- a/modules/ui/emblems-editor.js +++ b/modules/ui/emblems-editor.js @@ -112,13 +112,13 @@ function editEmblem(type, id, el) { if (type === "burg") name = "Burg of " + name; document.getElementById("emblemArmiger").innerText = name; - if (el.coa === "custom") emblemShapeSelector.disabled = true; + if (el.coa.custom) emblemShapeSelector.disabled = true; else { emblemShapeSelector.disabled = false; emblemShapeSelector.value = el.coa.shield; } - const size = el.coaSize || 1; + const size = el.coa.size || 1; document.getElementById("emblemSizeSlider").value = size; document.getElementById("emblemSizeNumber").value = size; } @@ -178,7 +178,9 @@ function editEmblem(type, id, el) { } function changeSize() { - const size = (el.coaSize = +this.value); + const size = +this.value; + el.coa.size = size; + document.getElementById("emblemSizeSlider").value = size; document.getElementById("emblemSizeNumber").value = size; @@ -189,8 +191,9 @@ function editEmblem(type, id, el) { // re-append use element const categotySize = +g.attr("font-size"); const shift = (categotySize * size) / 2; - const x = el.x || el.pole[0]; - const y = el.y || el.pole[1]; + const x = el.coa.x || el.x || el.pole[0]; + const y = el.coa.y || el.y || el.pole[1]; + g.append("use") .attr("data-i", el.i) .attr("x", rn(x - shift), 2) @@ -220,7 +223,7 @@ function editEmblem(type, id, el) { } function openInArmoria() { - const coa = el.coa && el.coa !== "custom" ? el.coa : {t1: "sable"}; + const coa = el.coa && !el.coa.custom ? el.coa : {t1: "sable"}; const json = JSON.stringify(coa).replaceAll("#", "%23"); const url = `https://azgaar.github.io/Armoria/?coa=${json}&from=FMG`; openURL(url); @@ -281,7 +284,13 @@ function editEmblem(type, id, el) { defs.insertAdjacentHTML("beforeend", svg); if (oldEmblem) oldEmblem.remove(); - el.coa = "custom"; + + const customCoa = {custom: true}; + if (el.coa.size) customCoa.size = el.coa.size; + if (el.coa.x) customCoa.x = el.coa.x; + if (el.coa.y) customCoa.y = el.coa.y; + el.coa = customCoa; + emblemShapeSelector.disabled = true; }; @@ -509,13 +518,21 @@ function editEmblem(type, id, el) { } function dragEmblem() { - const tr = parseTransform(this.getAttribute("transform")); - const x = +tr[0] - d3.event.x, - y = +tr[1] - d3.event.y; + const x = Number(this.getAttribute("x")) - d3.event.x; + const y = Number(this.getAttribute("y")) - d3.event.y; d3.event.on("drag", function () { - const transform = `translate(${x + d3.event.x},${y + d3.event.y})`; - this.setAttribute("transform", transform); + this.setAttribute("x", x + d3.event.x); + this.setAttribute("y", y + d3.event.y); + }); + + d3.event.on("end", function () { + const categotySize = Number(this.parentNode.getAttribute("font-size")); + const size = el.coa.size || 1; + const shift = (categotySize * size) / 2; + + el.coa.x = rn(x + d3.event.x + shift, 2); + el.coa.y = rn(y + d3.event.y + shift, 2); }); } diff --git a/modules/ui/layers.js b/modules/ui/layers.js index 286e05aa..0020b1f4 100644 --- a/modules/ui/layers.js +++ b/modules/ui/layers.js @@ -1749,9 +1749,9 @@ function drawEmblems() { TIME && console.time("drawEmblems"); const {states, provinces, burgs} = pack; - const validStates = states.filter(s => s.i && !s.removed && s.coa && s.coaSize != 0); - const validProvinces = provinces.filter(p => p.i && !p.removed && p.coa && p.coaSize != 0); - const validBurgs = burgs.filter(b => b.i && !b.removed && b.coa && b.coaSize != 0); + const validStates = states.filter(s => s.i && !s.removed && s.coa && s.coa.size !== 0); + const validProvinces = provinces.filter(p => p.i && !p.removed && p.coa && p.coa.size !== 0); + const validBurgs = burgs.filter(b => b.i && !b.removed && b.coa && b.coa.size !== 0); const getStateEmblemsSize = () => { const startSize = minmax((graphHeight + graphWidth) / 40, 10, 100); @@ -1777,26 +1777,26 @@ function drawEmblems() { const sizeBurgs = getBurgEmblemSize(); const burgCOAs = validBurgs.map(burg => { const {x, y} = burg; - const size = burg.coaSize || 1; + const size = burg.coa.size || 1; const shift = (sizeBurgs * size) / 2; - return {type: "burg", i: burg.i, x, y, size, shift}; + return {type: "burg", i: burg.i, x: burg.coa.x || x, y: burg.coa.y || y, size, shift}; }); const sizeProvinces = getProvinceEmblemsSize(); const provinceCOAs = validProvinces.map(province => { if (!province.pole) getProvincesVertices(); const [x, y] = province.pole || pack.cells.p[province.center]; - const size = province.coaSize || 1; + const size = province.coa.size || 1; const shift = (sizeProvinces * size) / 2; - return {type: "province", i: province.i, x, y, size, shift}; + return {type: "province", i: province.i, x: province.coa.x || x, y: province.coa.y || y, size, shift}; }); const sizeStates = getStateEmblemsSize(); const stateCOAs = validStates.map(state => { const [x, y] = state.pole || pack.cells.p[state.center]; - const size = state.coaSize || 1; + const size = state.coa.size || 1; const shift = (sizeStates * size) / 2; - return {type: "state", i: state.i, x, y, size, shift}; + return {type: "state", i: state.i, x: state.coa.x || x, y: state.coa.y || y, size, shift}; }); const nodes = burgCOAs.concat(provinceCOAs).concat(stateCOAs); diff --git a/modules/ui/options.js b/modules/ui/options.js index 04d65494..ce3b3561 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -381,7 +381,7 @@ function changeEmblemShape(emblemShape) { }; pack.states.forEach(state => { - if (!state.i || state.removed || !state.coa || state.coa === "custom") return; + if (!state.i || state.removed || !state.coa || state.coa.custom) return; const newShield = specificShape || COA.getShield(state.culture, null); if (newShield === state.coa.shield) return; state.coa.shield = newShield; @@ -389,7 +389,7 @@ function changeEmblemShape(emblemShape) { }); pack.provinces.forEach(province => { - if (!province.i || province.removed || !province.coa || province.coa === "custom") return; + if (!province.i || province.removed || !province.coa || province.coa.custom) return; const culture = pack.cells.culture[province.center]; const newShield = specificShape || COA.getShield(culture, province.state); if (newShield === province.coa.shield) return; @@ -398,7 +398,7 @@ function changeEmblemShape(emblemShape) { }); pack.burgs.forEach(burg => { - if (!burg.i || burg.removed || !burg.coa || burg.coa === "custom") return; + if (!burg.i || burg.removed || !burg.coa || burg.coa.custom) return; const newShield = specificShape || COA.getShield(burg.culture, burg.state); if (newShield === burg.coa.shield) return; burg.coa.shield = newShield; diff --git a/versioning.js b/versioning.js index bdbd43cb..ac42605d 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.90.04"; // generator version, update each time +const version = "1.91.00"; // generator version, update each time { document.title += " v" + version;