From a16e609696deb3c172f43bb98814be642a9f8b06 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 21 May 2022 19:46:42 +0300 Subject: [PATCH] Fractious template --- index.css | 2 +- index.html | 33 ++++---- modules/heightmap-generator.js | 19 +++-- modules/heightmap-templates.js | 141 ++++++++++++++------------------- modules/ui/heightmap-editor.js | 58 ++++++++------ 5 files changed, 124 insertions(+), 129 deletions(-) diff --git a/index.css b/index.css index f070c939..1b7a983b 100644 --- a/index.css +++ b/index.css @@ -922,7 +922,7 @@ fieldset { display: inline-block; } -body button.noicon { +#templateTools > button { width: 1.8em; height: 1.6em; margin: 1px; diff --git a/index.html b/index.html index 214bfa9e..32c30825 100644 --- a/index.html +++ b/index.html @@ -1292,7 +1292,7 @@ - + @@ -1302,6 +1302,7 @@ + @@ -2932,13 +2933,13 @@ `; - if (type === "Insulate") - return /* html */ `${common}f:`; + if (type === "Mask") + return /* html */ `${common}f:`; if (type === "Add") return /* html */ `${common}to:`; + return /* html */ `${common}f:`; } function setRange(event) { @@ -870,34 +878,36 @@ function editHeightmap() { } function executeTemplate() { - const body = byId("templateBody"); - const steps = body.querySelectorAll("#templateBody > div"); + const steps = byId("templateBody").querySelectorAll("#templateBody > div"); if (!steps.length) return; - const {addHill, addPit, addRange, addTrough, addStrait, modify, smooth, insulate} = HeightmapGenerator; grid.cells.h = new Uint8Array(grid.cells.i.length); // clean all heights + const seed = byId("templateSeed").value; + if (seed) Math.random = aleaPRNG(seed); + restartHistory(); + for (const step of steps) { if (step.style.opacity === "0.5") continue; - const type = step.dataset.type; const count = step.querySelector(".templateCount")?.value || ""; const height = step.querySelector(".templateHeight")?.value || ""; const dist = step.querySelector(".templateDist")?.value || null; const x = step.querySelector(".templateX")?.value || null; const y = step.querySelector(".templateY")?.value || null; + const type = step.dataset.type; - if (type === "Hill") addHill(count, height, x, y); - else if (type === "Pit") addPit(count, height, x, y); - else if (type === "Range") addRange(count, height, x, y); - else if (type === "Trough") addTrough(count, height, x, y); - else if (type === "Strait") addStrait(count, dist); - else if (type === "Insulate") insulate(+count); - else if (type === "Add") modify(dist, +count, 1); - else if (type === "Multiply") modify(dist, 0, +count); - else if (type === "Smooth") smooth(+count); + if (type === "Hill") HeightmapGenerator.addHill(count, height, x, y); + else if (type === "Pit") HeightmapGenerator.addPit(count, height, x, y); + else if (type === "Range") HeightmapGenerator.addRange(count, height, x, y); + else if (type === "Trough") HeightmapGenerator.addTrough(count, height, x, y); + else if (type === "Strait") HeightmapGenerator.addStrait(count, dist); + else if (type === "Mask") HeightmapGenerator.mask(+count); + else if (type === "Add") HeightmapGenerator.modify(dist, +count, 1); + else if (type === "Multiply") HeightmapGenerator.modify(dist, 0, +count); + else if (type === "Smooth") HeightmapGenerator.smooth(+count); - updateHistory("noStat"); // update history every step + updateHistory("noStat"); // update history on every step } updateStatistics();