Added a lock function to burgs that will prevent them from being regenerated

This commit is contained in:
Legogizmo 2021-03-25 23:08:34 -05:00
parent c9b34866f9
commit cb3890a68c
6 changed files with 57 additions and 9 deletions

View file

@ -1972,6 +1972,7 @@
<button id="burgEditEmblem" data-tip="Edit emblem" class="icon-shield-alt"></button> <button id="burgEditEmblem" data-tip="Edit emblem" class="icon-shield-alt"></button>
<button id="burgRelocate" data-tip="Relocate burg" class="icon-target"></button> <button id="burgRelocate" data-tip="Relocate burg" class="icon-target"></button>
<button id="burglLegend" data-tip="Edit free text notes (legend) for this burg" class="icon-edit"></button> <button id="burglLegend" data-tip="Edit free text notes (legend) for this burg" class="icon-edit"></button>
<button id="burgLock" data-tip="Lock or Unlock this burg" class="icon-lock-open"></button>
<button id="burgRemove" data-tip="Remove non-capital burg. Shortcut: Delete" class="icon-trash fastDelete"></button> <button id="burgRemove" data-tip="Remove non-capital burg. Shortcut: Delete" class="icon-trash fastDelete"></button>
</div> </div>
</div> </div>
@ -4133,4 +4134,3 @@
<script defer src="libs/pell.min.js"></script> <script defer src="libs/pell.min.js"></script>
</body> </body>
</html> </html>

View file

@ -145,7 +145,7 @@
const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp; const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp;
for (const b of pack.burgs) { for (const b of pack.burgs) {
if (!b.i) continue; if (!b.i || b.lock) continue;
const i = b.cell; const i = b.cell;
// asign port status to some coastline burgs with temp > 0 °C // asign port status to some coastline burgs with temp > 0 °C

View file

@ -48,6 +48,7 @@ function editBurg(id) {
document.getElementById("burgEditEmblem").addEventListener("click", openEmblemEdit); document.getElementById("burgEditEmblem").addEventListener("click", openEmblemEdit);
document.getElementById("burgRelocate").addEventListener("click", toggleRelocateBurg); document.getElementById("burgRelocate").addEventListener("click", toggleRelocateBurg);
document.getElementById("burglLegend").addEventListener("click", editBurgLegend); document.getElementById("burglLegend").addEventListener("click", editBurgLegend);
document.getElementById("burgLock").addEventListener("click", toggleBurgLockButton);
document.getElementById("burgRemove").addEventListener("click", removeSelectedBurg); document.getElementById("burgRemove").addEventListener("click", removeSelectedBurg);
function updateBurgValues() { function updateBurgValues() {
@ -90,6 +91,9 @@ function editBurg(id) {
if (b.shanty) document.getElementById("burgShanty").classList.remove("inactive"); if (b.shanty) document.getElementById("burgShanty").classList.remove("inactive");
else document.getElementById("burgShanty").classList.add("inactive"); else document.getElementById("burgShanty").classList.add("inactive");
//toggle lock
updateBurgLockIcon();
// select group // select group
const group = elSelected.node().parentNode.id; const group = elSelected.node().parentNode.id;
const select = document.getElementById("burgSelectGroup"); const select = document.getElementById("burgSelectGroup");
@ -299,6 +303,20 @@ function editBurg(id) {
else document.getElementById("burgEditAnchorStyle").style.display = "none"; else document.getElementById("burgEditAnchorStyle").style.display = "none";
} }
function toggleBurgLockButton() {
const id = +elSelected.attr("data-id");
toggleBurgLock(id);
updateBurgLockIcon();
}
function updateBurgLockIcon() {
const id = +elSelected.attr("data-id");
const b = pack.burgs[id];
if (b.lock) {document.getElementById("burgLock").classList.remove("icon-lock-open"); document.getElementById("burgLock").classList.add("icon-lock");}
else {document.getElementById("burgLock").classList.remove("icon-lock"); document.getElementById("burgLock").classList.add("icon-lock-open");}
}
function showStyleSection() { function showStyleSection() {
document.querySelectorAll("#burgBottom > button").forEach(el => el.style.display = "none"); document.querySelectorAll("#burgBottom > button").forEach(el => el.style.display = "none");
document.getElementById("burgStyleSection").style.display = "inline-block"; document.getElementById("burgStyleSection").style.display = "inline-block";

View file

@ -86,6 +86,7 @@ function overviewBurgs() {
<span data-tip="Click to toggle port status" class="icon-anchor pointer${b.port ? '' : ' inactive'}" style="font-size:.9em"></span> <span data-tip="Click to toggle port status" class="icon-anchor pointer${b.port ? '' : ' inactive'}" style="font-size:.9em"></span>
</div> </div>
<span data-tip="Edit burg" class="icon-pencil"></span> <span data-tip="Edit burg" class="icon-pencil"></span>
<span data-tip="Lock Burg" class="locks ${b.lock ? 'icon-lock' : 'icon-lock-open inactive'}"></span>
<span data-tip="Remove burg" class="icon-trash-empty"></span> <span data-tip="Remove burg" class="icon-trash-empty"></span>
</div>`; </div>`;
} }
@ -104,6 +105,7 @@ function overviewBurgs() {
body.querySelectorAll("div > input.burgPopulation").forEach(el => el.addEventListener("change", changeBurgPopulation)); body.querySelectorAll("div > input.burgPopulation").forEach(el => el.addEventListener("change", changeBurgPopulation));
body.querySelectorAll("div > span.icon-star-empty").forEach(el => el.addEventListener("click", toggleCapitalStatus)); body.querySelectorAll("div > span.icon-star-empty").forEach(el => el.addEventListener("click", toggleCapitalStatus));
body.querySelectorAll("div > span.icon-anchor").forEach(el => el.addEventListener("click", togglePortStatus)); body.querySelectorAll("div > span.icon-anchor").forEach(el => el.addEventListener("click", togglePortStatus));
body.querySelectorAll("div > span.locks").forEach(el => el.addEventListener("click", toggleBurgLockStatus));
body.querySelectorAll("div > span.icon-pencil").forEach(el => el.addEventListener("click", openBurgEditor)); body.querySelectorAll("div > span.icon-pencil").forEach(el => el.addEventListener("click", openBurgEditor));
body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.addEventListener("click", triggerBurgRemove)); body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.addEventListener("click", triggerBurgRemove));
@ -178,6 +180,13 @@ function overviewBurgs() {
else this.classList.add("inactive"); else this.classList.add("inactive");
} }
function toggleBurgLockStatus() {
const burg = +this.parentNode.dataset.id;
toggleBurgLock(burg);
if (this.classList.contains("icon-lock")) {this.classList.remove("icon-lock"); this.classList.add("icon-lock-open"); this.classList.add("inactive");}
else {this.classList.remove("icon-lock-open"); this.classList.add("icon-lock"); this.classList.remove("inactive");}
}
function openBurgEditor() { function openBurgEditor() {
const burg = +this.parentNode.dataset.id; const burg = +this.parentNode.dataset.id;
editBurg(burg); editBurg(burg);
@ -203,11 +212,14 @@ function overviewBurgs() {
function regenerateNames() { function regenerateNames() {
body.querySelectorAll(":scope > div").forEach(function(el) { body.querySelectorAll(":scope > div").forEach(function(el) {
const burg = +el.dataset.id; const burg = +el.dataset.id;
//if (pack.burgs[burg].lock) return;
const culture = pack.burgs[burg].culture; const culture = pack.burgs[burg].culture;
const name = Names.getCulture(culture); const name = Names.getCulture(culture);
if (!pack.burgs[burg].lock) {
el.querySelector(".burgName").value = name; el.querySelector(".burgName").value = name;
pack.burgs[burg].name = el.dataset.name = name; pack.burgs[burg].name = el.dataset.name = name;
burgLabels.select("[data-id='" + burg + "']").text(name); burgLabels.select("[data-id='" + burg + "']").text(name);
}
}); });
} }
@ -469,7 +481,7 @@ function overviewBurgs() {
} }
function removeAllBurgs() { function removeAllBurgs() {
pack.burgs.filter(b => b.i && !b.capital).forEach(b => removeBurg(b.i)); pack.burgs.filter(b => b.i && !(b.capital || b.lock)).forEach(b => removeBurg(b.i));
burgsOverviewAddLines(); burgsOverviewAddLines();
} }
} }

View file

@ -221,6 +221,11 @@ function togglePort(burg) {
.attr("width", size).attr("height", size); .attr("width", size).attr("height", size);
} }
function toggleBurgLock(burg) {
const b = pack.burgs[burg];
b.lock = b.lock ? 0 : 1;
}
// draw legend box // draw legend box
function drawLegend(name, data) { function drawLegend(name, data) {
legend.selectAll("*").remove(); // fully redraw every time legend.selectAll("*").remove(); // fully redraw every time

View file

@ -103,7 +103,7 @@ function regenerateRivers() {
function recalculatePopulation() { function recalculatePopulation() {
rankCells(); rankCells();
pack.burgs.forEach(b => { pack.burgs.forEach(b => {
if (!b.i || b.removed) return; if (!b.i || b.removed || b.lock) return;
const i = b.cell; const i = b.cell;
b.population = rn(Math.max((pack.cells.s[i] + pack.cells.road[i] / 2) / 8 + b.i / 1000 + i % 100 / 1000, .1), 3); b.population = rn(Math.max((pack.cells.s[i] + pack.cells.road[i] / 2) / 8 + b.i / 1000 + i % 100 / 1000, .1), 3);
@ -224,7 +224,7 @@ function regenerateProvinces() {
} }
function regenerateBurgs() { function regenerateBurgs() {
const cells = pack.cells, states = pack.states; const cells = pack.cells, states = pack.states, Lockedburgs = pack.burgs.filter(b =>b.lock);
rankCells(); rankCells();
cells.burg = new Uint16Array(cells.i.length); cells.burg = new Uint16Array(cells.i.length);
const burgs = pack.burgs = [0]; // clear burgs array const burgs = pack.burgs = [0]; // clear burgs array
@ -237,6 +237,19 @@ function regenerateBurgs() {
const burgsCount = manorsInput.value == 1000 ? rn(sorted.length / 5 / (grid.points.length / 10000) ** .8) + states.length : +manorsInput.value + states.length; const burgsCount = manorsInput.value == 1000 ? rn(sorted.length / 5 / (grid.points.length / 10000) ** .8) + states.length : +manorsInput.value + states.length;
const spacing = (graphWidth + graphHeight) / 150 / (burgsCount ** .7 / 66); // base min distance between towns const spacing = (graphWidth + graphHeight) / 150 / (burgsCount ** .7 / 66); // base min distance between towns
//clear locked list since ids will change
//burglock.selectAll("text").remove();
for (let j=0; j < Lockedburgs.length; j++) {
const id = burgs.length;
const oldBurg = Lockedburgs[j];
oldBurg.i = id;
burgs.push(oldBurg);
burgsTree.add([oldBurg.x, oldBurg.y]);
cells.burg[oldBurg.cell] = id;
if (oldBurg.capital) {states[oldBurg.state].capital = id; states[oldBurg.state].center = oldBurg.cell;}
//burglock.append("text").attr("data-id", id);
}
for (let i=0; i < sorted.length && burgs.length < burgsCount; i++) { for (let i=0; i < sorted.length && burgs.length < burgsCount; i++) {
const id = burgs.length; const id = burgs.length;
const cell = sorted[i]; const cell = sorted[i];