mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
fix: migrate ice data to new data model structure
This commit is contained in:
parent
cc4a7cab30
commit
89d27f8e4c
1 changed files with 63 additions and 56 deletions
|
|
@ -1040,66 +1040,73 @@ 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");
|
||||||
|
if (iceLayer) {
|
||||||
|
// Migrate glaciers (type="iceShield")
|
||||||
|
iceLayer.querySelectorAll("polygon[type='iceShield']").forEach(polygon => {
|
||||||
|
// Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...]
|
||||||
|
const points = [...polygon.points].map(svgPoint => [svgPoint.x, svgPoint.y]);
|
||||||
|
|
||||||
|
const transform = polygon.getAttribute("transform");
|
||||||
|
|
||||||
const iceLayer = document.getElementById("ice");
|
if (transform) {
|
||||||
if (iceLayer) {
|
pack.ice.glaciers.push({
|
||||||
// Migrate glaciers (type="iceShield")
|
points,
|
||||||
iceLayer.querySelectorAll("polygon[type='iceShield']").forEach(polygon => {
|
offset: parseTransform(transform)
|
||||||
const pointsStr = polygon.getAttribute("points");
|
});
|
||||||
if (!pointsStr) return;
|
} else {
|
||||||
|
pack.ice.glaciers.push({ points });
|
||||||
// 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 cellId = +polygon.getAttribute("cell");
|
||||||
|
const size = +polygon.getAttribute("size");
|
||||||
|
|
||||||
|
// points string must exist, cell attribute must be present, and size must be non-zero
|
||||||
|
if (polygon.getAttribute("cell") === null || !size) return;
|
||||||
|
|
||||||
|
// Parse points string "x1,y1 x2,y2 x3,y3 ..." into array [[x1,y1], [x2,y2], ...]
|
||||||
|
const points = [...polygon.points].map(svgPoint => [svgPoint.x, svgPoint.y]);
|
||||||
|
|
||||||
|
const transform = polygon.getAttribute("transform");
|
||||||
|
if (transform) {
|
||||||
|
pack.ice.icebergs.push({
|
||||||
|
cellId,
|
||||||
|
size,
|
||||||
|
points,
|
||||||
|
offset: parseTransform(transform)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
pack.ice.icebergs.push({
|
||||||
|
cellId,
|
||||||
|
size,
|
||||||
|
points
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate icebergs
|
|
||||||
iceLayer.querySelectorAll("polygon:not([type])").forEach(polygon => {
|
|
||||||
const pointsStr = polygon.getAttribute("points");
|
|
||||||
const cellId = +polygon.getAttribute("cell");
|
|
||||||
const size = +polygon.getAttribute("size");
|
|
||||||
|
|
||||||
// points string must exist, cell attribute must be present, and size must be non-zero
|
|
||||||
if (!pointsStr || polygon.getAttribute("cell") === null || !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
|
||||||
// Clear old SVG elements - use d3 selection
|
iceLayer.querySelectorAll("*").forEach(el => el.remove());
|
||||||
d3.select(iceLayer).selectAll("*").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");
|
ice
|
||||||
ice
|
.attr("opacity", null)
|
||||||
.attr("opacity", null)
|
.attr("fill", "#e8f0f6")
|
||||||
.attr("fill", "#e8f0f6")
|
.attr("stroke", "#e8f0f6")
|
||||||
.attr("stroke", "#e8f0f6")
|
.attr("stroke-width", 1)
|
||||||
.attr("stroke-width", 1)
|
.attr("filter", "url(#dropShadow05)");
|
||||||
.attr("filter", "url(#dropShadow05)");
|
}
|
||||||
|
|
||||||
|
// Re-render ice from migrated data
|
||||||
|
if (layerIsOn("toggleIce")) drawIce();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-render ice from migrated data
|
|
||||||
if (layerIsOn("toggleIce")) drawIce();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue