From b1a8c042e641210b8f46e55b1cd51fec2b7f74da Mon Sep 17 00:00:00 2001 From: StempunkDev Date: Mon, 12 Jan 2026 21:52:01 +0100 Subject: [PATCH] feat: migrate ice data to new data model and update version to 1.110.0 --- public/modules/dynamic/auto-update.js | 65 +++++++++++++++++++++++++++ public/modules/renderers/draw-ice.js | 2 + src/index.html | 16 +++---- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/public/modules/dynamic/auto-update.js b/public/modules/dynamic/auto-update.js index a3190e3b..393cd746 100644 --- a/public/modules/dynamic/auto-update.js +++ b/public/modules/dynamic/auto-update.js @@ -1036,4 +1036,69 @@ export function resolveVersionConflicts(mapVersion) { delete options.showMFCGMap; delete options.villageMaxPopulation; } + + if (isOlderThan("1.110.0")) { + // v1.110.0 moved ice data from SVG to data model + // Migrate old ice SVG elements to new pack.ice structure + if (!pack.ice) pack.ice = { glaciers: [], icebergs: [] }; + + const iceLayer = document.getElementById("ice"); + if (iceLayer) { + // Migrate glaciers (type="iceShield") + iceLayer.querySelectorAll("polygon[type='iceShield']").forEach(polygon => { + const pointsStr = polygon.getAttribute("points"); + if (!pointsStr) return; + + // Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...] + const points = pointsStr + .split(" ") + .map(pair => pair.split(",").map(Number)); + + const transform = polygon.getAttribute("transform"); + const offset = transform ? parseTransform(transform) : null; + pack.ice.glaciers.push({ + points, + offset + }); + }); + + // Migrate icebergs + iceLayer.querySelectorAll("polygon:not([type])").forEach(polygon => { + const pointsStr = polygon.getAttribute("points"); + const cellId = +polygon.getAttribute("cell"); + const size = +polygon.getAttribute("size"); + + if (!pointsStr || !cellId || !size) return; + + // Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...] + const points = pointsStr + .split(" ") + .map(pair => pair.split(",").map(Number)); + + const transform = polygon.getAttribute("transform"); + const offset = transform ? parseTransform(transform) : null; + pack.ice.icebergs.push({ + cellId, + size, + points, + offset + }); + }); + + // Clear old SVG elements - use d3 selection + d3.select(iceLayer).selectAll("*").remove(); + } else { + // If ice layer element doesn't exist, create it + ice = viewbox.insert("g", "#coastline").attr("id", "ice"); + ice + .attr("opacity", null) + .attr("fill", "#e8f0f6") + .attr("stroke", "#e8f0f6") + .attr("stroke-width", 1) + .attr("filter", "url(#dropShadow05)"); + } + + // Re-render ice from migrated data + if (layerIsOn("toggleIce")) drawIce(); + } } diff --git a/public/modules/renderers/draw-ice.js b/public/modules/renderers/draw-ice.js index 37075275..9e93efe7 100644 --- a/public/modules/renderers/draw-ice.js +++ b/public/modules/renderers/draw-ice.js @@ -14,6 +14,7 @@ function drawIce() { .attr("points", glacier.points) .attr("type", "iceShield") .attr("data-index", index) + .attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null) .attr("class", "glacier"); }); @@ -25,6 +26,7 @@ function drawIce() { .attr("cell", iceberg.cellId) .attr("size", iceberg.size) .attr("data-index", index) + .attr("transform", iceberg.offset ? `translate(${iceberg.offset[0]},${iceberg.offset[1]})` : null) .attr("class", "iceberg"); }); diff --git a/src/index.html b/src/index.html index 8a5c4e6b..7b6a2076 100644 --- a/src/index.html +++ b/src/index.html @@ -8500,7 +8500,7 @@ - + @@ -8518,16 +8518,16 @@ - + - + - + @@ -8538,7 +8538,7 @@ - + @@ -8569,8 +8569,8 @@ - - + + @@ -8586,6 +8586,6 @@ - +