From b267e832b5333095fdbdb57b93e7907b3b4d9092 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Tue, 30 Jul 2024 17:54:17 +0200 Subject: [PATCH] fix: support migration of v0.9 maps --- index.html | 4 ++-- modules/dynamic/auto-update.js | 10 ++++++---- modules/io/load.js | 6 +++++- modules/lakes.js | 6 +++++- versioning.js | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index e9977dd0..02436228 100644 --- a/index.html +++ b/index.html @@ -8095,7 +8095,7 @@ - + @@ -8159,7 +8159,7 @@ - + diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js index 38ae4403..7e74f463 100644 --- a/modules/dynamic/auto-update.js +++ b/modules/dynamic/auto-update.js @@ -243,10 +243,12 @@ export function resolveVersionConflicts(version) { rivers.selectAll("path").each(function () { const i = +this.id.slice(5); const length = this.getTotalLength() / 2; - const s = this.getPointAtLength(length), - e = this.getPointAtLength(0); - const source = findCell(s.x, s.y), - mouth = findCell(e.x, e.y); + if (!length) return; + + const s = this.getPointAtLength(length); + const e = this.getPointAtLength(0); + const source = findCell(s.x, s.y); + const mouth = findCell(e.x, e.y); const name = Rivers.getName(mouth); const type = length < 25 ? rw({Creek: 9, River: 3, Brook: 3, Stream: 1}) : "River"; pack.rivers.push({i, parent: 0, length, source, mouth, basin: i, name, type}); diff --git a/modules/io/load.js b/modules/io/load.js index 1b782686..9b0a67f5 100644 --- a/modules/io/load.js +++ b/modules/io/load.js @@ -348,6 +348,10 @@ async function parseLoadedData(data, mapVersion) { .attr("id", "texture") .attr("data-href", "./images/textures/plaster.jpg"); } + + if (!emblems.size()) { + emblems = viewbox.insert("g", "#labels").attr("id", "emblems").style("display", "none"); + } })(); void (function parseGridData() { @@ -457,7 +461,7 @@ async function parseLoadedData(data, mapVersion) { { // dynamically import and run auto-update script const versionNumber = parseFloat(params[0]); - const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.98.00"); + const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.98.06"); resolveVersionConflicts(versionNumber); } diff --git a/modules/lakes.js b/modules/lakes.js index 093ff84f..ba6adb80 100644 --- a/modules/lakes.js +++ b/modules/lakes.js @@ -12,7 +12,10 @@ window.Lakes = (function () { f.flux = f.shoreline.reduce((acc, c) => acc + grid.cells.prec[cells.g[c]], 0); // temperature and evaporation to detect closed lakes - f.temp = f.cells < 6 ? grid.cells.temp[cells.g[f.firstCell]] : rn(d3.mean(f.shoreline.map(c => grid.cells.temp[cells.g[c]])), 1); + f.temp = + f.cells < 6 + ? grid.cells.temp[cells.g[f.firstCell]] + : rn(d3.mean(f.shoreline.map(c => grid.cells.temp[cells.g[c]])), 1); const height = (f.height - 18) ** heightExponentInput.value; // height in meters const evaporation = ((700 * (f.temp + 0.006 * height)) / 50 + 75) / (80 - f.temp); // based on Penman formula, [1-11] f.evaporation = rn(evaporation * f.cells); @@ -31,6 +34,7 @@ window.Lakes = (function () { // get array of land cells aroound lake const getShoreline = function (lake) { const uniqueCells = new Set(); + if (!lake.vertices) lake.vertices = []; lake.vertices.forEach(v => pack.vertices.c[v].forEach(c => pack.cells.h[c] >= 20 && uniqueCells.add(c))); lake.shoreline = [...uniqueCells]; }; diff --git a/versioning.js b/versioning.js index cb38478d..88bcbd93 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.98.05"; // generator version, update each time +const version = "1.98.06"; // generator version, update each time { document.title += " v" + version;