From f6f49fd86bdf8825196d03d1daa9b2592525845d Mon Sep 17 00:00:00 2001 From: ZoltanTheDM Date: Sun, 10 Nov 2019 15:29:50 -0800 Subject: [PATCH] based on suggestions simplified usage of biome usage --- modules/burgs-and-states.js | 7 ++++--- modules/cultures-generator.js | 7 ++++--- modules/relief-icons.js | 10 ++++----- modules/ui/biomes-editor.js | 39 +++++++++++++++++------------------ 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index 8e136b4c..79997ea5 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -292,10 +292,11 @@ burgs.filter(b => b.i && !b.removed).forEach(b => b.state = cells.state[b.cell]); // assign state to burgs function getBiomeCost(b, biome, type) { + const bio = biomesData.biomeList[biome]; if (b === biome) return 10; // tiny penalty for native biome - if (type === "Hunting") return biomesData.biomeList[biome].cost * 2; // non-native biome penalty for hunters - if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.biomeList[biome].cost * 3; // forest biome penalty for nomads - return biomesData.biomeList[biome].cost; // general non-native biome penalty + if (type === "Hunting") return bio.cost * 2; // non-native biome penalty for hunters + if (type === "Nomadic" && biome > 4 && biome < 10) return bio.cost * 3; // forest biome penalty for nomads + return bio.cost; // general non-native biome penalty } function getHeightCost(f, h, type) { diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js index 5caf11c7..fe6c43f1 100644 --- a/modules/cultures-generator.js +++ b/modules/cultures-generator.js @@ -391,10 +391,11 @@ } function getBiomeCost(c, biome, type) { + const b = biomesData.biomeList[biome]; if (cells.biome[pack.cultures[c].center] === biome) return 10; // tiny penalty for native biome - if (type === "Hunting") return biomesData.biomeList[biome].cost * 5; // non-native biome penalty for hunters - if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.biomeList[biome].cost * 10; // forest biome penalty for nomads - return biomesData.biomeList[biome].cost * 2; // general non-native biome penalty + if (type === "Hunting") return b.cost * 5; // non-native biome penalty for hunters + if (type === "Nomadic" && biome > 4 && biome < 10) return b.cost * 10; // forest biome penalty for nomads + return b.cost * 2; // general non-native biome penalty } function getHeightCost(i, h, type) { diff --git a/modules/relief-icons.js b/modules/relief-icons.js index 238eff6d..50e4fc62 100644 --- a/modules/relief-icons.js +++ b/modules/relief-icons.js @@ -17,23 +17,23 @@ const height = cells.h[i]; if (height < 20) continue; // no icons on water if (cells.r[i]) continue; // no icons on rivers - const b = cells.biome[i]; - if (height < 50 && biomesData.biomeList[b].icons.density === 0) continue; // no icons for this biome + const b = biomesData.biomeList[cells.biome[i]]; + if (height < 50 && b.icons.density === 0) continue; // no icons for this biome const polygon = getPackPolygon(i); const x = d3.extent(polygon, p => p[0]), y = d3.extent(polygon, p => p[1]); const e = [Math.ceil(x[0]), Math.ceil(y[0]), Math.floor(x[1]), Math.floor(y[1])]; // polygon box - if (height < 50) placeBiomeIcons(i, b); else placeReliefIcons(i); + if (height < 50) placeBiomeIcons(); else placeReliefIcons(i); function placeBiomeIcons() { - const iconsDensity = biomesData.biomeList[b].icons.density / 100; + const iconsDensity = b.icons.density / 100; const radius = 2 / iconsDensity / density; if (Math.random() > iconsDensity * 10) return; for (const [cx, cy] of poissonDiscSampler(e[0], e[1], e[2], e[3], radius)) { if (!d3.polygonContains(polygon, [cx, cy])) continue; let h = rn((4 + Math.random()) * size, 2); - const icon = getBiomeIcon(i, biomesData.biomeList[b].icons.probability); + const icon = getBiomeIcon(i, b.icons.probability); if (icon === "#relief-grass-1") h *= 1.3; relief.push({i: icon, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2}); } diff --git a/modules/ui/biomes-editor.js b/modules/ui/biomes-editor.js index 0d75c0c2..3a484ecd 100644 --- a/modules/ui/biomes-editor.js +++ b/modules/ui/biomes-editor.js @@ -117,45 +117,44 @@ function editBiomes() { function biomeHighlightOn(event) { if (customization === 6) return; - const biome = +event.target.dataset.id; - biomes.select("#biome"+biome).raise().transition(animate).attr("stroke-width", 2).attr("stroke", "#cd4c11"); + const biome = biomesData.biomeList[+event.target.dataset.id]; + biomes.select("#biome"+biome.id).raise().transition(animate).attr("stroke-width", 2).attr("stroke", "#cd4c11"); } function biomeHighlightOff(event) { if (customization === 6) return; - const biome = +event.target.dataset.id; - const color = biomesData.biomeList[biome].color; - biomes.select("#biome"+biome).transition().attr("stroke-width", .7).attr("stroke", color); + const biome = biomesData.biomeList[+event.target.dataset.id]; + biomes.select("#biome"+biome.id).transition().attr("stroke-width", .7).attr("stroke", biome.color); } function biomeChangeColor(el) { const currentFill = el.getAttribute("fill"); - const biome = +el.parentNode.parentNode.dataset.id; + const biome = biomesData.biomeList[+el.parentNode.parentNode.dataset.id]; const callback = function(fill) { el.setAttribute("fill", fill); - biomesData.biomeList[biome].color = fill; - biomes.select("#biome"+biome).attr("fill", fill).attr("stroke", fill); + biome.color = fill; + biomes.select("#biome"+biome.id).attr("fill", biome.color).attr("stroke", fill); } openPicker(currentFill, callback); } function biomeChangeName(el) { - const biome = +el.parentNode.dataset.id; + const biome = biomesData.biomeList[+el.parentNode.dataset.id]; el.parentNode.dataset.name = el.value; - biomesData.biomeList[biome].name = el.value; + biome.name = el.value; } function biomeChangeHabitability(el) { - const biome = +el.parentNode.dataset.id; + const biome = biomesData.biomeList[+el.parentNode.dataset.id]; const failed = isNaN(+el.value) || +el.value < 0 || +el.value > 9999; if (failed) { - el.value = biomesData.biomeList[biome].habitability; + el.value = biome.habitability; tip("Please provide a valid number in range 0-9999", false, "error"); return; } - biomesData.biomeList[biome].habitability = +el.value; + biome.habitability = +el.value; el.parentNode.dataset.habitability = el.value; recalculatePopulation(); refreshBiomesEditor(); @@ -237,9 +236,9 @@ function editBiomes() { } function removeCustomBiome(el) { - const biome = +el.parentNode.dataset.id; + const biome = biomesData.biomeList[+el.parentNode.dataset.id]; el.parentNode.remove(); - biomesData.biomeList[biome].name = "removed"; + biome.name = "removed"; biomesFooterBiomes.innerHTML = +biomesFooterBiomes.innerHTML - 1; } @@ -324,17 +323,17 @@ function editBiomes() { const temp = biomes.select("#temp"); const selected = body.querySelector("div.selected"); - const biomeNew = selected.dataset.id; - const color = biomesData.biomeList[biomeNew].color; + const biomeNew = biomesData.biomeList[+selected.dataset.id]; + const color = biomeNew.color; selection.forEach(function(i) { const exists = temp.select("polygon[data-cell='"+i+"']"); const biomeOld = exists.size() ? +exists.attr("data-biome") : pack.cells.biome[i]; - if (biomeNew === biomeOld) return; + if (biomeNew.id === biomeOld) return; // change of append new element - if (exists.size()) exists.attr("data-biome", biomeNew).attr("fill", color).attr("stroke", color); - else temp.append("polygon").attr("data-cell", i).attr("data-biome", biomeNew).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color); + if (exists.size()) exists.attr("data-biome", biomeNew.id).attr("fill", color).attr("stroke", color); + else temp.append("polygon").attr("data-cell", i).attr("data-biome", biomeNew.id).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color); }); }