This commit is contained in:
Azgaar 2019-08-31 12:16:36 +03:00
parent 5f9cab4f84
commit cab429a346
58 changed files with 6413 additions and 1489 deletions

View file

@ -36,7 +36,7 @@
let h = rn((4 + Math.random()) * size, 2);
const icon = getBiomeIcon(i, biomesData.icons[b]);
if (icon === "#relief-grass-1") h *= 1.3;
relief.push({t: icon, c: i, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});
relief.push({i: icon, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});
}
}
@ -46,7 +46,7 @@
for (const [cx, cy] of poissonDiscSampler(e[0], e[1], e[2], e[3], radius)) {
if (!d3.polygonContains(polygon, [cx, cy])) continue;
relief.push({t: icon, c: i, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});
relief.push({i: icon, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});
}
}
@ -54,9 +54,8 @@
const temp = grid.cells.temp[pack.cells.g[i]];
const type = h > 70 && temp < 0 ? "mountSnow" : h > 70 ? "mount" : "hill";
const size = h > 70 ? (h - 45) * mod : Math.min(Math.max((h - 40) * mod, 3), 6);
return ["#relief-" + type + "-" + getIcon(type), size];
return [getIcon(type), size];
}
}
// sort relief icons by y+size
@ -65,22 +64,24 @@
// append relief icons at once using pure js
void function renderRelief() {
let reliefHTML = "";
for (const r of relief) {reliefHTML += `<use xlink:href="${r.t}" data-type="${r.t}" x=${r.x} y=${r.y} data-size=${r.s} width=${r.s} height=${r.s}></use>`;}
for (const r of relief) {
reliefHTML += `<use xlink:href="${r.i}" data-type="${r.i}" x=${r.x} y=${r.y} data-size=${r.s} width=${r.s} height=${r.s}></use>`;
}
terrain.html(reliefHTML);
}()
console.timeEnd('drawRelief');
}
function getBiomeIcon(i, b) {
let type = b[Math.floor(Math.random() * b.length)];
const temp = grid.cells.temp[pack.cells.g[i]];
if (type === "conifer" && temp < 0) type = "coniferSnow";
return "#relief-" + type + "-" + getIcon(type);
return getIcon(type);
}
function getIcon(type) {
switch (type) {
function getVariant(type) {
switch(type) {
case "mount": return rand(2,7);
case "mountSnow": return rand(1,6);
case "hill": return rand(2,5);
@ -92,7 +93,25 @@
default: return 2;
}
}
function getOldIcon(type) {
switch(type) {
case "mountSnow": return "mount";
case "vulcan": return "mount";
case "coniferSnow": return "conifer";
case "cactus": return "dune";
case "deadTree": return "dune";
default: return type;
}
}
function getIcon(type) {
if (styleReliefSet.value === "simple") return "#relief-" + getOldIcon(type) + "-1";
if (styleReliefSet.value === "colored") return "#relief-" + type + "-" + getVariant(type);
if (styleReliefSet.value === "gray") return "#relief-" + type + "-" + getVariant(type) + "-bw";
return "#relief-" + getOldIcon(type) + "-1"; // simple
}
return ReliefIcons;
})));