mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
hightmap edit - fix mod function
This commit is contained in:
parent
da0e788020
commit
46838a1702
2 changed files with 32 additions and 38 deletions
|
|
@ -379,14 +379,16 @@ window.HeightmapGenerator = (function () {
|
|||
const modify = function (range, add, mult, power) {
|
||||
const min = range === "land" ? 20 : range === "all" ? 0 : +range.split("-")[0];
|
||||
const max = range === "land" || range === "all" ? 100 : +range.split("-")[1];
|
||||
grid.cells.h = grid.cells.h.map(h => (h >= min && h <= max ? mod(h) : h));
|
||||
const isLand = min === 20;
|
||||
|
||||
function mod(v) {
|
||||
if (add) v = min === 20 ? Math.max(v + add, 20) : v + add;
|
||||
if (mult !== 1) v = min === 20 ? (v - 20) * mult + 20 : v * mult;
|
||||
if (power) v = min === 20 ? (v - 20) ** power + 20 : v ** power;
|
||||
return lim(v);
|
||||
}
|
||||
grid.cells.h = grid.cells.h.map(h => {
|
||||
if (h < min || h > max) return h;
|
||||
|
||||
if (add) h = isLand ? Math.max(h + add, 20) : h + add;
|
||||
if (mult !== 1) h = isLand ? (h - 20) * mult + 20 : h * mult;
|
||||
if (power) h = isLand ? (h - 20) ** power + 20 : h ** power;
|
||||
return lim(h);
|
||||
});
|
||||
};
|
||||
|
||||
const smooth = function (fr = 2, add = 0) {
|
||||
|
|
|
|||
|
|
@ -837,31 +837,27 @@ function editHeightmap() {
|
|||
const steps = body.querySelectorAll("#templateBody > div");
|
||||
if (!steps.length) return;
|
||||
|
||||
const {addHill, addPit, addRange, addTrough, addStrait, modify, smooth} = HeightmapGenerator;
|
||||
grid.cells.h = new Uint8Array(grid.cells.i.length); // clean all heights
|
||||
|
||||
for (const s of steps) {
|
||||
if (s.style.opacity == 0.5) continue;
|
||||
const type = s.dataset.type;
|
||||
for (const step of steps) {
|
||||
if (step.style.opacity === "0.5") continue;
|
||||
const type = step.dataset.type;
|
||||
|
||||
const elCount = s.querySelector(".templateCount") || "";
|
||||
const elHeight = s.querySelector(".templateHeight") || "";
|
||||
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 elDist = s.querySelector(".templateDist");
|
||||
const dist = elDist ? elDist.value : null;
|
||||
|
||||
const templateX = s.querySelector(".templateX");
|
||||
const x = templateX ? templateX.value : null;
|
||||
const templateY = s.querySelector(".templateY");
|
||||
const y = templateY ? templateY.value : null;
|
||||
|
||||
if (type === "Hill") HeightmapGenerator.addHill(elCount.value, elHeight.value, x, y);
|
||||
else if (type === "Pit") HeightmapGenerator.addPit(elCount.value, elHeight.value, x, y);
|
||||
else if (type === "Range") HeightmapGenerator.addRange(elCount.value, elHeight.value, x, y);
|
||||
else if (type === "Trough") HeightmapGenerator.addTrough(elCount.value, elHeight.value, x, y);
|
||||
else if (type === "Strait") HeightmapGenerator.addStrait(elCount.value, dist);
|
||||
else if (type === "Add") HeightmapGenerator.modify(dist, +elCount.value, 1);
|
||||
else if (type === "Multiply") HeightmapGenerator.modify(dist, 0, +elCount.value);
|
||||
else if (type === "Smooth") HeightmapGenerator.smooth(+elCount.value);
|
||||
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 === "Add") modify(dist, +count, 1);
|
||||
else if (type === "Multiply") modify(dist, 0, +count);
|
||||
else if (type === "Smooth") smooth(+count);
|
||||
|
||||
updateHistory("noStat"); // update history every step
|
||||
}
|
||||
|
|
@ -880,17 +876,13 @@ function editHeightmap() {
|
|||
|
||||
let data = "";
|
||||
for (const s of steps) {
|
||||
if (s.style.opacity == 0.5) continue;
|
||||
if (s.style.opacity === "0.5") continue;
|
||||
|
||||
const type = s.getAttribute("data-type");
|
||||
const elCount = s.querySelector(".templateCount");
|
||||
const count = elCount ? elCount.value : "0";
|
||||
const elHeight = s.querySelector(".templateHeight");
|
||||
const elDist = s.querySelector(".templateDist");
|
||||
const arg3 = elHeight ? elHeight.value : elDist ? elDist.value : "0";
|
||||
const templateX = s.querySelector(".templateX");
|
||||
const x = templateX ? templateX.value : "0";
|
||||
const templateY = s.querySelector(".templateY");
|
||||
const y = templateY ? templateY.value : "0";
|
||||
const count = s.querySelector(".templateCount")?.value || "0";
|
||||
const arg3 = s.querySelector(".templateHeight")?.value || s.querySelector(".templateDist")?.value || "0";
|
||||
const x = s.querySelector(".templateX")?.value || "0";
|
||||
const y = s.querySelector(".templateY")?.value || "0";
|
||||
data += `${type} ${count} ${arg3} ${x} ${y}\r\n`;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue