mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-05 10:01:24 +01:00
refactor: streamline ice generation process and clean up rendering functions
This commit is contained in:
parent
89d27f8e4c
commit
d1e40b6277
3 changed files with 10 additions and 31 deletions
|
|
@ -632,7 +632,6 @@ async function generate(options) {
|
||||||
Biomes.define();
|
Biomes.define();
|
||||||
Features.defineGroups();
|
Features.defineGroups();
|
||||||
|
|
||||||
Ice.initialize();
|
|
||||||
Ice.generate();
|
Ice.generate();
|
||||||
|
|
||||||
rankCells();
|
rankCells();
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ window.Ice = (function () {
|
||||||
|
|
||||||
// Generate glaciers and icebergs based on temperature and height
|
// Generate glaciers and icebergs based on temperature and height
|
||||||
function generate() {
|
function generate() {
|
||||||
clear();
|
initialize();
|
||||||
const { cells, features } = grid;
|
const { cells, features } = grid;
|
||||||
const { temp, h } = cells;
|
const { temp, h } = cells;
|
||||||
Math.random = aleaPRNG(seed);
|
Math.random = aleaPRNG(seed);
|
||||||
|
|
@ -148,10 +148,6 @@ window.Ice = (function () {
|
||||||
iceberg.size = newSize;
|
iceberg.size = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getData() {
|
|
||||||
return pack.ice;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear all ice
|
// Clear all ice
|
||||||
function clear() {
|
function clear() {
|
||||||
pack.ice.glaciers = [];
|
pack.ice.glaciers = [];
|
||||||
|
|
@ -166,7 +162,6 @@ window.Ice = (function () {
|
||||||
updateIceberg,
|
updateIceberg,
|
||||||
randomizeIcebergShape,
|
randomizeIcebergShape,
|
||||||
changeIcebergSize,
|
changeIcebergSize,
|
||||||
getData,
|
|
||||||
clear
|
clear
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,6 @@ function drawIce() {
|
||||||
ice.html(html);
|
ice.html(html);
|
||||||
|
|
||||||
TIME && console.timeEnd("drawIce");
|
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) {
|
function redrawIceberg(index) {
|
||||||
|
|
@ -46,15 +38,9 @@ function redrawIceberg(index) {
|
||||||
el = ice.selectAll(`.iceberg[data-index="${index}"]`);
|
el = ice.selectAll(`.iceberg[data-index="${index}"]`);
|
||||||
}
|
}
|
||||||
el.attr("points", iceberg.points);
|
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);
|
el.attr("transform", iceberg.offset ? `translate(${iceberg.offset[0]},${iceberg.offset[1]})` : null);
|
||||||
}
|
}
|
||||||
TIME && console.timeEnd("redrawIceberg");
|
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) {
|
function redrawGlacier(index) {
|
||||||
|
|
@ -74,13 +60,12 @@ function redrawGlacier(index) {
|
||||||
el.attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null);
|
el.attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null);
|
||||||
}
|
}
|
||||||
TIME && console.timeEnd("redrawGlacier");
|
TIME && console.timeEnd("redrawGlacier");
|
||||||
|
}
|
||||||
|
|
||||||
function getGlacierHtml(glacier, index) {
|
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"/>`;
|
return `<polygon points="${glacier.points}" data-index="${index}" ${glacier.offset ? `transform="translate(${glacier.offset[0]},${glacier.offset[1]})"` : ""} class="glacier"/>`;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-render ice layer from data model
|
function getIcebergHtml(iceberg, index) {
|
||||||
function redrawIce() {
|
return `<polygon points="${iceberg.points}" data-index="${index}" ${iceberg.offset ? `transform="translate(${iceberg.offset[0]},${iceberg.offset[1]})"` : ""} class="iceberg"/>`;
|
||||||
drawIce();
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue