mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
refactor: update ice data handling and rendering for improved performance
This commit is contained in:
parent
b1a8c042e6
commit
a2139f1aee
3 changed files with 9 additions and 52 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Ice layer data model - separates ice data from SVG rendering
|
// Ice layer data model - separates ice data from SVG rendering
|
||||||
const Ice = (() => {
|
window.Ice = (function () {
|
||||||
// Initialize ice data structure
|
// Initialize ice data structure
|
||||||
function initialize() {
|
function initialize() {
|
||||||
pack.ice = {
|
pack.ice = {
|
||||||
|
|
@ -60,8 +60,7 @@ const Ice = (() => {
|
||||||
pack.ice.icebergs.push({
|
pack.ice.icebergs.push({
|
||||||
cellId,
|
cellId,
|
||||||
size,
|
size,
|
||||||
points,
|
points
|
||||||
offset: null
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,8 +76,7 @@ const Ice = (() => {
|
||||||
pack.ice.icebergs.push({
|
pack.ice.icebergs.push({
|
||||||
cellId,
|
cellId,
|
||||||
size,
|
size,
|
||||||
points,
|
points
|
||||||
offset: null
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return pack.ice.icebergs.length - 1; // return index
|
return pack.ice.icebergs.length - 1; // return index
|
||||||
|
|
|
||||||
|
|
@ -7,29 +7,20 @@ function drawIce() {
|
||||||
// Clear existing ice SVG
|
// Clear existing ice SVG
|
||||||
ice.selectAll("*").remove();
|
ice.selectAll("*").remove();
|
||||||
|
|
||||||
|
let html = "";
|
||||||
|
|
||||||
// Draw glaciers
|
// Draw glaciers
|
||||||
pack.ice.glaciers.forEach((glacier, index) => {
|
pack.ice.glaciers.forEach((glacier, index) => {
|
||||||
ice
|
html += `<polygon points="${glacier.points}" type="iceShield" data-index="${index}" ${glacier.offset ? `transform="translate(${glacier.offset[0]},${glacier.offset[1]})"` : ""} class="glacier"/>`;
|
||||||
.append("polygon")
|
|
||||||
.attr("points", glacier.points)
|
|
||||||
.attr("type", "iceShield")
|
|
||||||
.attr("data-index", index)
|
|
||||||
.attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null)
|
|
||||||
.attr("class", "glacier");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Draw icebergs
|
// Draw icebergs
|
||||||
pack.ice.icebergs.forEach((iceberg, index) => {
|
pack.ice.icebergs.forEach((iceberg, index) => {
|
||||||
ice
|
html += `<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"/>`;
|
||||||
.append("polygon")
|
|
||||||
.attr("points", iceberg.points)
|
|
||||||
.attr("cell", iceberg.cellId)
|
|
||||||
.attr("size", iceberg.size)
|
|
||||||
.attr("data-index", index)
|
|
||||||
.attr("transform", iceberg.offset ? `translate(${iceberg.offset[0]},${iceberg.offset[1]})` : null)
|
|
||||||
.attr("class", "iceberg");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ice.html(html);
|
||||||
|
|
||||||
TIME && console.timeEnd("drawIce");
|
TIME && console.timeEnd("drawIce");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -417,38 +417,6 @@ function toggleIce(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawIce() {
|
|
||||||
TIME && console.time("drawIce");
|
|
||||||
|
|
||||||
// Clear existing ice SVG
|
|
||||||
ice.selectAll("*").remove();
|
|
||||||
|
|
||||||
// Draw glaciers
|
|
||||||
pack.ice.glaciers.forEach((glacier, index) => {
|
|
||||||
ice
|
|
||||||
.append("polygon")
|
|
||||||
.attr("points", glacier.points)
|
|
||||||
.attr("type", "iceShield")
|
|
||||||
.attr("data-index", index)
|
|
||||||
.attr("class", "glacier")
|
|
||||||
.attr("transform", glacier.offset ? `translate(${glacier.offset[0]},${glacier.offset[1]})` : null);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Draw icebergs
|
|
||||||
pack.ice.icebergs.forEach((iceberg, index) => {
|
|
||||||
ice
|
|
||||||
.append("polygon")
|
|
||||||
.attr("points", iceberg.points)
|
|
||||||
.attr("cell", iceberg.cellId)
|
|
||||||
.attr("size", iceberg.size)
|
|
||||||
.attr("data-index", index)
|
|
||||||
.attr("class", "iceberg")
|
|
||||||
.attr("transform", iceberg.offset ? `translate(${iceberg.offset[0]},${iceberg.offset[1]})` : null);
|
|
||||||
});
|
|
||||||
|
|
||||||
TIME && console.timeEnd("drawIce");
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCultures(event) {
|
function toggleCultures(event) {
|
||||||
const cultures = pack.cultures.filter(c => c.i && !c.removed);
|
const cultures = pack.cultures.filter(c => c.i && !c.removed);
|
||||||
const empty = !cults.selectAll("path").size();
|
const empty = !cults.selectAll("path").size();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue