diff --git a/modules/io/load.js b/modules/io/load.js index 6208b99b..61788af9 100644 --- a/modules/io/load.js +++ b/modules/io/load.js @@ -454,12 +454,20 @@ async function parseLoadedData(data) { })(); { - // dynamically import and run auto-udpdate script + // dynamically import and run auto-update script const versionNumber = parseFloat(params[0]); const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.93.00"); resolveVersionConflicts(versionNumber); } + { + // add custom heightmap color scheme if any + const scheme = terrs.attr("scheme"); + if (!(scheme in heightmapColorSchemes)) { + addCustomColorScheme(scheme); + } + } + void (function checkDataIntegrity() { const cells = pack.cells; diff --git a/modules/ui/layers.js b/modules/ui/layers.js index 09d7a66a..fc1943d6 100644 --- a/modules/ui/layers.js +++ b/modules/ui/layers.js @@ -297,11 +297,6 @@ function drawHeightmap() { TIME && console.timeEnd("drawHeightmap"); } -function getColorScheme(scheme = "bright") { - if (scheme in heightmapColorSchemes) return heightmapColorSchemes[scheme]; - throw new Error(`Unsupported color scheme: ${scheme}`); -} - function getColor(value, scheme = getColorScheme("bright")) { return scheme(1 - (value < 20 ? value - 5 : value) / 100); } diff --git a/modules/ui/style.js b/modules/ui/style.js index 77284913..90fa7bbd 100644 --- a/modules/ui/style.js +++ b/modules/ui/style.js @@ -37,20 +37,37 @@ function editStyle(element, group) { }, 1500); } +// Color schemes const heightmapColorSchemes = { bright: d3.scaleSequential(d3.interpolateSpectral), light: d3.scaleSequential(d3.interpolateRdYlGn), natural: d3.scaleSequential(d3.interpolateRgbBasis(["white", "#EEEECC", "tan", "green", "teal"])), green: d3.scaleSequential(d3.interpolateGreens), + olive: d3.scaleSequential(d3.interpolateRgbBasis(["#ffffff", "#cea48d", "#d5b085", "#0c2c19", "#151320"])), livid: d3.scaleSequential(d3.interpolateRgbBasis(["#BBBBDD", "#2A3440", "#17343B", "#0A1E24"])), monochrome: d3.scaleSequential(d3.interpolateGreys) }; -// add color schemes to the lists +// add default color schemes to the list of options byId("styleHeightmapScheme").innerHTML = Object.keys(heightmapColorSchemes) .map(scheme => ``) .join(""); +function addCustomColorScheme(scheme) { + const stops = scheme.split(","); + heightmapColorSchemes[scheme] = d3.scaleSequential(d3.interpolateRgbBasis(stops)); + byId("styleHeightmapScheme").options.add(new Option(scheme, scheme, false, true)); +} + +function getColorScheme(scheme = "bright") { + if (!(scheme in heightmapColorSchemes)) { + const colors = scheme.split(","); + heightmapColorSchemes[scheme] = d3.scaleSequential(d3.interpolateRgbBasis(colors)); + } + + return heightmapColorSchemes[scheme]; +} + // Toggle style sections on element select styleElementSelect.addEventListener("change", selectStyleElement); function selectStyleElement() { @@ -575,9 +592,7 @@ openCreateHeightmapSchemeButton.addEventListener("click", function () { const stops = openCreateHeightmapSchemeButton.dataset.stops; if (stops in heightmapColorSchemes) return tip("This scheme already exists", false, "error"); - heightmapColorSchemes[stops] = d3.scaleSequential(d3.interpolateRgbBasis(stops.split(","))); - byId("styleHeightmapScheme").options.add(new Option(stops, stops, false, true)); - + addCustomColorScheme(stops); terrs.attr("scheme", stops); drawHeightmap(); diff --git a/modules/ui/stylePresets.js b/modules/ui/stylePresets.js index 0ba995d4..c4a01dee 100644 --- a/modules/ui/stylePresets.js +++ b/modules/ui/stylePresets.js @@ -97,9 +97,7 @@ function applyStyle(style) { // add custom heightmap color scheme if (selector === "#terrs" && attribute === "scheme" && !(value in heightmapColorSchemes)) { - const colors = value.split(","); - heightmapColorSchemes[value] = d3.scaleSequential(d3.interpolateRgbBasis(colors)); - document.getElementById("styleHeightmapScheme").options.add(new Option(value, value)); + addCustomColorScheme(value); } } }