fix: migrate ice data to new data model structure

This commit is contained in:
StempunkDev 2026-01-14 21:18:42 +01:00
parent cc4a7cab30
commit 89d27f8e4c

View file

@ -1040,54 +1040,59 @@ export function resolveVersionConflicts(mapVersion) {
if (isOlderThan("1.110.0")) { if (isOlderThan("1.110.0")) {
// v1.110.0 moved ice data from SVG to data model // v1.110.0 moved ice data from SVG to data model
// Migrate old ice SVG elements to new pack.ice structure // Migrate old ice SVG elements to new pack.ice structure
if (!pack.ice) pack.ice = { glaciers: [], icebergs: [] }; if (!pack.ice) {
pack.ice = { glaciers: [], icebergs: [] };
const iceLayer = document.getElementById("ice"); const iceLayer = document.getElementById("ice");
if (iceLayer) { if (iceLayer) {
// Migrate glaciers (type="iceShield") // Migrate glaciers (type="iceShield")
iceLayer.querySelectorAll("polygon[type='iceShield']").forEach(polygon => { 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], ...] // Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...]
const points = pointsStr const points = [...polygon.points].map(svgPoint => [svgPoint.x, svgPoint.y]);
.split(" ")
.map(pair => pair.split(",").map(Number));
const transform = polygon.getAttribute("transform"); const transform = polygon.getAttribute("transform");
const offset = transform ? parseTransform(transform) : null;
if (transform) {
pack.ice.glaciers.push({ pack.ice.glaciers.push({
points, points,
offset offset: parseTransform(transform)
}); });
} else {
pack.ice.glaciers.push({ points });
}
}); });
// Migrate icebergs // Migrate icebergs
iceLayer.querySelectorAll("polygon:not([type])").forEach(polygon => { iceLayer.querySelectorAll("polygon:not([type])").forEach(polygon => {
const pointsStr = polygon.getAttribute("points");
const cellId = +polygon.getAttribute("cell"); const cellId = +polygon.getAttribute("cell");
const size = +polygon.getAttribute("size"); const size = +polygon.getAttribute("size");
// points string must exist, cell attribute must be present, and size must be non-zero // points string must exist, cell attribute must be present, and size must be non-zero
if (!pointsStr || polygon.getAttribute("cell") === null || !size) return; if (polygon.getAttribute("cell") === null || !size) return;
// Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...] // Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...]
const points = pointsStr const points = [...polygon.points].map(svgPoint => [svgPoint.x, svgPoint.y]);
.split(" ")
.map(pair => pair.split(",").map(Number));
const transform = polygon.getAttribute("transform"); const transform = polygon.getAttribute("transform");
const offset = transform ? parseTransform(transform) : null; if (transform) {
pack.ice.icebergs.push({ pack.ice.icebergs.push({
cellId, cellId,
size, size,
points, points,
offset offset: parseTransform(transform)
}); });
} else {
pack.ice.icebergs.push({
cellId,
size,
points
});
}
}); });
// Clear old SVG elements - use d3 selection // Clear old SVG elements
d3.select(iceLayer).selectAll("*").remove(); iceLayer.querySelectorAll("*").forEach(el => el.remove());
} else { } else {
// If ice layer element doesn't exist, create it // If ice layer element doesn't exist, create it
ice = viewbox.insert("g", "#coastline").attr("id", "ice"); ice = viewbox.insert("g", "#coastline").attr("id", "ice");
@ -1102,4 +1107,6 @@ export function resolveVersionConflicts(mapVersion) {
// Re-render ice from migrated data // Re-render ice from migrated data
if (layerIsOn("toggleIce")) drawIce(); if (layerIsOn("toggleIce")) drawIce();
} }
}
} }