mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
changed biome to use pack instead of its own variable
This commit is contained in:
parent
23c9538b79
commit
fe51098b16
10 changed files with 39 additions and 41 deletions
|
|
@ -55,19 +55,19 @@ function editBiomes() {
|
|||
function biomesCollectStatistics() {
|
||||
const cells = pack.cells;
|
||||
|
||||
biomesData.biomeList.forEach((biome) => {
|
||||
pack.biomes.forEach((biome) => {
|
||||
biome.resetStatistics();
|
||||
});
|
||||
|
||||
for (const i of cells.i) {
|
||||
if (cells.h[i] < 20) continue;
|
||||
biomesData.biomeList[cells.biome[i]].addCell(i, cells);
|
||||
pack.biomes[cells.biome[i]].addCell(i, cells);
|
||||
}
|
||||
}
|
||||
|
||||
function biomesEditorAddLines() {
|
||||
const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value;
|
||||
const l = biomesData.biomeList;
|
||||
const l = pack.biomes;
|
||||
let lines = "", totalArea = 0, totalPopulation = 0;;
|
||||
|
||||
for (const b of l) {
|
||||
|
|
@ -117,19 +117,19 @@ function editBiomes() {
|
|||
|
||||
function biomeHighlightOn(event) {
|
||||
if (customization === 6) return;
|
||||
const biome = biomesData.biomeList[+event.target.dataset.id];
|
||||
const biome = pack.biomes[+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 = biomesData.biomeList[+event.target.dataset.id];
|
||||
const biome = pack.biomes[+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 = biomesData.biomeList[+el.parentNode.parentNode.dataset.id];
|
||||
const biome = pack.biomes[+el.parentNode.parentNode.dataset.id];
|
||||
|
||||
const callback = function(fill) {
|
||||
el.setAttribute("fill", fill);
|
||||
|
|
@ -141,13 +141,13 @@ function editBiomes() {
|
|||
}
|
||||
|
||||
function biomeChangeName(el) {
|
||||
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
|
||||
const biome = pack.biomes[+el.parentNode.dataset.id];
|
||||
el.parentNode.dataset.name = el.value;
|
||||
biome.name = el.value;
|
||||
}
|
||||
|
||||
function biomeChangeHabitability(el) {
|
||||
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
|
||||
const biome = pack.biomes[+el.parentNode.dataset.id];
|
||||
const failed = isNaN(+el.value) || +el.value < 0 || +el.value > 9999;
|
||||
if (failed) {
|
||||
el.value = biome.habitability;
|
||||
|
|
@ -184,8 +184,7 @@ function editBiomes() {
|
|||
|
||||
function toggleLegend() {
|
||||
if (legend.selectAll("*").size()) {clearLegend(); return;}; // hide legend
|
||||
const d = biomesData;
|
||||
const data = Array.from(d.biomeList) //shallow copy existing array
|
||||
const data = pack.biomes //shallow copy existing array
|
||||
.filter(i => i.cells) //remove biomes with 0 cells
|
||||
.sort((a, b) => b.area - a.area) //sort by size
|
||||
.map(i => [i.id, i.color, i.name]); //return index, color, and name
|
||||
|
|
@ -211,7 +210,7 @@ function editBiomes() {
|
|||
}
|
||||
|
||||
function addCustomBiome() {
|
||||
const b = biomesData.biomeList, i = b.length;
|
||||
const b = pack.biomes, i = b.length;
|
||||
b.push(new Biome("Custom", getRandomColor(), 50))
|
||||
b[i].id = i; //don't forget the ID!
|
||||
|
||||
|
|
@ -236,7 +235,7 @@ function editBiomes() {
|
|||
}
|
||||
|
||||
function removeCustomBiome(el) {
|
||||
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
|
||||
const biome = pack.biomes[+el.parentNode.dataset.id];
|
||||
el.parentNode.remove();
|
||||
biome.name = "removed";
|
||||
biomesFooterBiomes.innerHTML = +biomesFooterBiomes.innerHTML - 1;
|
||||
|
|
@ -323,7 +322,7 @@ function editBiomes() {
|
|||
const temp = biomes.select("#temp");
|
||||
const selected = body.querySelector("div.selected");
|
||||
|
||||
const biomeNew = biomesData.biomeList[+selected.dataset.id];
|
||||
const biomeNew = pack.biomes[+selected.dataset.id];
|
||||
const color = biomeNew.color;
|
||||
|
||||
selection.forEach(function(i) {
|
||||
|
|
@ -379,7 +378,7 @@ function editBiomes() {
|
|||
}
|
||||
|
||||
function restoreInitialBiomes() {
|
||||
biomesData = applyDefaultBiomesSystem();
|
||||
applyDefaultBiomesSystem();
|
||||
defineBiomes();
|
||||
drawBiomes();
|
||||
recalculatePopulation();
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ function showMapTooltip(point, e, i, g) {
|
|||
if (layerIsOn("togglePrec") && land) tip("Annual Precipitation: "+ getFriendlyPrecipitation(i)); else
|
||||
if (layerIsOn("togglePopulation")) tip(getPopulationTip(i)); else
|
||||
if (layerIsOn("toggleTemp")) tip("Temperature: " + convertTemperature(grid.cells.temp[g])); else
|
||||
if (layerIsOn("toggleBiomes") && pack.cells.biome[i]) tip("Biome: " + biomesData.biomeList[pack.cells.biome[i]].name); else
|
||||
if (layerIsOn("toggleBiomes") && pack.cells.biome[i]) tip("Biome: " + pack.biomes[pack.cells.biome[i]].name); else
|
||||
if (layerIsOn("toggleReligions") && pack.cells.religion[i]) {
|
||||
const religion = pack.religions[pack.cells.religion[i]];
|
||||
const type = religion.type === "Cult" || religion.type == "Heresy" ? religion.type : religion.type + " religion";
|
||||
|
|
@ -146,7 +146,7 @@ function updateCellInfo(point, i, g) {
|
|||
infoBurg.innerHTML = cells.burg[i] ? pack.burgs[cells.burg[i]].name + " (" + cells.burg[i] + ")" : "no";
|
||||
const f = cells.f[i];
|
||||
infoFeature.innerHTML = f ? pack.features[f].group + " (" + f + ")" : "n/a";
|
||||
infoBiome.innerHTML = biomesData.biomeList[cells.biome[i]].name;
|
||||
infoBiome.innerHTML = pack.biomes[cells.biome[i]].name;
|
||||
}
|
||||
|
||||
// get user-friendly (real-world) height value from map data
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ function drawBiomes() {
|
|||
biomes.selectAll("path").remove();
|
||||
const cells = pack.cells, vertices = pack.vertices, n = cells.i.length;
|
||||
const used = new Uint8Array(cells.i.length);
|
||||
const paths = new Array(biomesData.biomeList.length).fill("");
|
||||
const paths = new Array(pack.biomes.length).fill("");
|
||||
|
||||
for (const i of cells.i) {
|
||||
if (!cells.biome[i]) continue; // no need to mark water
|
||||
|
|
@ -350,7 +350,7 @@ function drawBiomes() {
|
|||
|
||||
paths.forEach(function(d, i) {
|
||||
if (d.length < 10) return;
|
||||
biomes.append("path").attr("d", d).attr("fill", biomesData.biomeList[i].color).attr("stroke", biomesData.biomeList[i].color).attr("id", "biome"+i);
|
||||
biomes.append("path").attr("d", d).attr("fill", pack.biomes[i].color).attr("stroke", pack.biomes[i].color).attr("id", "biome"+i);
|
||||
});
|
||||
|
||||
// connect vertices to chain
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue