refactor: streamline ice generation process and clean up rendering functions

This commit is contained in:
StempunkDev 2026-01-14 21:23:03 +01:00
parent 89d27f8e4c
commit d1e40b6277
3 changed files with 10 additions and 31 deletions

View file

@ -632,7 +632,6 @@ async function generate(options) {
Biomes.define();
Features.defineGroups();
Ice.initialize();
Ice.generate();
rankCells();

View file

@ -12,9 +12,9 @@ window.Ice = (function () {
// Generate glaciers and icebergs based on temperature and height
function generate() {
clear();
const {cells, features} = grid;
const {temp, h} = cells;
initialize();
const { cells, features } = grid;
const { temp, h } = cells;
Math.random = aleaPRNG(seed);
const ICEBERG_MAX_TEMP = 0;
@ -26,7 +26,7 @@ window.Ice = (function () {
const type = "iceShield";
const getType = cellId =>
h[cellId] >= 20 && temp[cellId] <= GLACIER_MAX_TEMP ? type : null;
const isolines = getIsolines(grid, getType, {polygons: true});
const isolines = getIsolines(grid, getType, { polygons: true });
if (isolines[type]?.polygons) {
isolines[type].polygons.forEach(points => {
@ -148,10 +148,6 @@ window.Ice = (function () {
iceberg.size = newSize;
}
function getData() {
return pack.ice;
}
// Clear all ice
function clear() {
pack.ice.glaciers = [];
@ -166,7 +162,6 @@ window.Ice = (function () {
updateIceberg,
randomizeIcebergShape,
changeIcebergSize,
getData,
clear
};
})();

View file

@ -22,14 +22,6 @@ function drawIce() {
ice.html(html);
TIME && console.timeEnd("drawIce");
function getGlacierHtml(glacier, index) {
return `<polygon points="${glacier.points}" type="iceShield" data-index="${index}" ${glacier.offset ? `transform="translate(${glacier.offset[0]},${glacier.offset[1]})"` : ""} class="glacier"/>`;
}
function getIcebergHtml(iceberg, index) {
return `<polygon points="${iceberg.points}" cell="${iceberg.cellId}" size="${iceberg.size}" data-index="${index}" ${iceberg.offset ? `transform="translate(${iceberg.offset[0]},${iceberg.offset[1]})"` : ""} class="iceberg"/>`;
}
}
function redrawIceberg(index) {
@ -46,15 +38,9 @@ function redrawIceberg(index) {
el = ice.selectAll(`.iceberg[data-index="${index}"]`);
}
el.attr("points", iceberg.points);
el.attr("size", iceberg.size);
el.attr("cell", iceberg.cellId);
el.attr("transform", iceberg.offset ? `translate(${iceberg.offset[0]},${iceberg.offset[1]})` : null);
}
TIME && console.timeEnd("redrawIceberg");
function getIcebergHtml(iceberg, index) {
return `<polygon points="${iceberg.points}" cell="${iceberg.cellId}" size="${iceberg.size}" data-index="${index}" ${iceberg.offset ? `transform="translate(${iceberg.offset[0]},${iceberg.offset[1]})"` : ""} class="iceberg"/>`;
}
}
function redrawGlacier(index) {
@ -74,13 +60,12 @@ function redrawGlacier(index) {
el.attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null);
}
TIME && console.timeEnd("redrawGlacier");
function getGlacierHtml(glacier, index) {
return `<polygon points="${glacier.points}" type="iceShield" data-index="${index}" ${glacier.offset ? `transform="translate(${glacier.offset[0]},${glacier.offset[1]})"` : ""} class="glacier"/>`;
}
}
// Re-render ice layer from data model
function redrawIce() {
drawIce();
function getGlacierHtml(glacier, index) {
return `<polygon points="${glacier.points}" data-index="${index}" ${glacier.offset ? `transform="translate(${glacier.offset[0]},${glacier.offset[1]})"` : ""} class="glacier"/>`;
}
function getIcebergHtml(iceberg, index) {
return `<polygon points="${iceberg.points}" data-index="${index}" ${iceberg.offset ? `transform="translate(${iceberg.offset[0]},${iceberg.offset[1]})"` : ""} class="iceberg"/>`;
}