burgs overview - intert lock state

This commit is contained in:
Azgaar 2021-11-12 23:00:21 +03:00
parent 9325d54386
commit e65370d9c4
2 changed files with 64 additions and 90 deletions

View file

@ -3260,6 +3260,7 @@
<div style="left:20.1em" data-tip="Click to sort by culture name" class="sortable alphabetically" data-sortby="culture">Culture&nbsp;</div> <div style="left:20.1em" data-tip="Click to sort by culture name" class="sortable alphabetically" data-sortby="culture">Culture&nbsp;</div>
<div style="left:24.7em" data-tip="Click to sort by burg population" class="sortable" data-sortby="population">Population&nbsp;</div> <div style="left:24.7em" data-tip="Click to sort by burg population" class="sortable" data-sortby="population">Population&nbsp;</div>
<div style="left:31.2em" data-tip="Click to sort by burg type" class="sortable alphabetically" data-sortby="type">Type&nbsp;</div> <div style="left:31.2em" data-tip="Click to sort by burg type" class="sortable alphabetically" data-sortby="type">Type&nbsp;</div>
<div id="burgsInvertLock" style="left:35.5em; color: #6e5e66" data-tip="Click to invert lock for all burgs" class="icon-lock pointer"></div>
</div> </div>
<div id="burgsBody" class="table"></div> <div id="burgsBody" class="table"></div>

View file

@ -34,6 +34,7 @@ function overviewBurgs() {
uploadFile(this, importBurgNames); uploadFile(this, importBurgNames);
}); });
document.getElementById("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove); document.getElementById("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove);
document.getElementById("burgsInvertLock").addEventListener("click", invertLock);
function refreshBurgsEditor() { function refreshBurgsEditor() {
updateFilter(); updateFilter();
@ -152,8 +153,8 @@ function overviewBurgs() {
function zoomIntoBurg() { function zoomIntoBurg() {
const burg = +this.parentNode.dataset.id; const burg = +this.parentNode.dataset.id;
const label = document.querySelector("#burgLabels [data-id='" + burg + "']"); const label = document.querySelector("#burgLabels [data-id='" + burg + "']");
const x = +label.getAttribute("x"), const x = +label.getAttribute("x");
y = +label.getAttribute("y"); const y = +label.getAttribute("y");
zoomTo(x, y, 8, 2000); zoomTo(x, y, 8, 2000);
} }
@ -214,24 +215,15 @@ function overviewBurgs() {
function triggerBurgRemove() { function triggerBurgRemove() {
const burg = +this.parentNode.dataset.id; const burg = +this.parentNode.dataset.id;
if (pack.burgs[burg].capital) { if (pack.burgs[burg].capital) return tip("You cannot remove the capital. Please change the capital first", false, "error");
tip("You cannot remove the capital. Please change the capital first", false, "error");
return;
}
alertMessage.innerHTML = "Are you sure you want to remove the burg?"; confirmationDialog({
$("#alert").dialog({
resizable: false,
title: "Remove burg", title: "Remove burg",
buttons: { message: "Are you sure you want to remove the burg? This actiove cannot be reverted",
Remove: function () { confirm: "Remove",
$(this).dialog("close"); onConfirm: () => {
removeBurg(burg); removeBurg(burg);
burgsOverviewAddLines(); burgsOverviewAddLines();
},
Cancel: function () {
$(this).dialog("close");
}
} }
}); });
} }
@ -239,22 +231,19 @@ 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; 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);
}
}); });
} }
function enterAddBurgMode() { function enterAddBurgMode() {
if (this.classList.contains("pressed")) { if (this.classList.contains("pressed")) return exitAddBurgMode();
exitAddBurgMode();
return;
}
customization = 3; customization = 3;
this.classList.add("pressed"); this.classList.add("pressed");
tip("Click on the map to create a new burg. Hold Shift to add multiple", true, "warn"); tip("Click on the map to create a new burg. Hold Shift to add multiple", true, "warn");
@ -264,14 +253,9 @@ function overviewBurgs() {
function addBurgOnClick() { function addBurgOnClick() {
const point = d3.mouse(this); const point = d3.mouse(this);
const cell = findCell(point[0], point[1]); const cell = findCell(point[0], point[1]);
if (pack.cells.h[cell] < 20) { if (pack.cells.h[cell] < 20) return tip("You cannot place state into the water. Please click on a land cell", false, "error");
tip("You cannot place state into the water. Please click on a land cell", false, "error"); if (pack.cells.burg[cell]) return tip("There is already a burg in this cell. Please select a free cell", false, "error");
return;
}
if (pack.cells.burg[cell]) {
tip("There is already a burg in this cell. Please select a free cell", false, "error");
return;
}
addBurg(point); // add new burg addBurg(point); // add new burg
if (d3.event.shiftKey === false) { if (d3.event.shiftKey === false) {
@ -315,8 +299,8 @@ function overviewBurgs() {
.sum(d => d.population) .sum(d => d.population)
.sort((a, b) => b.value - a.value); .sort((a, b) => b.value - a.value);
const width = 150 + 200 * uiSizeOutput.value, const width = 150 + 200 * uiSizeOutput.value;
height = 150 + 200 * uiSizeOutput.value; const height = 150 + 200 * uiSizeOutput.value;
const margin = {top: 0, right: -50, bottom: -10, left: -50}; const margin = {top: 0, right: -50, bottom: -10, left: -50};
const w = width - margin.left - margin.right; const w = width - margin.left - margin.right;
const h = height - margin.top - margin.bottom; const h = height - margin.top - margin.bottom;
@ -415,14 +399,14 @@ function overviewBurgs() {
if (this.value === "provinces") return d.province; if (this.value === "provinces") return d.province;
}; };
const base = const mapping = {
this.value === "states" states: getStatesData,
? getStatesData() cultures: getCulturesData,
: this.value === "cultures" parent: getParentData,
? getCulturesData() provinces: getProvincesData
: this.value === "parent" };
? getParentData()
: getProvincesData(); const base = mapping[this.value]();
burgs.forEach(b => (b.id = b.i + base.length - 1)); burgs.forEach(b => (b.id = b.i + base.length - 1));
const data = base.concat(burgs); const data = base.concat(burgs);
@ -449,9 +433,7 @@ function overviewBurgs() {
width: fitContent(), width: fitContent(),
position: {my: "left bottom", at: "left+10 bottom-10", of: "svg"}, position: {my: "left bottom", at: "left+10 bottom-10", of: "svg"},
buttons: {}, buttons: {},
close: () => { close: () => (alertMessage.innerHTML = "")
alertMessage.innerHTML = "";
}
}); });
} }
@ -522,19 +504,14 @@ function overviewBurgs() {
} }
function importBurgNames(dataLoaded) { function importBurgNames(dataLoaded) {
if (!dataLoaded) { if (!dataLoaded) return tip("Cannot load the file, please check the format", false, "error");
tip("Cannot load the file, please check the format", false, "error");
return;
}
const data = dataLoaded.split("\r\n"); const data = dataLoaded.split("\r\n");
if (!data.length) { if (!data.length) return tip("Cannot parse the list, please check the file format", false, "error");
tip("Cannot parse the list, please check the file format", false, "error");
return;
}
let change = [], let change = [];
message = `Burgs will be renamed as below. Please confirm`; let message = `Burgs to be renamed as below:`;
message += `<table class="overflow-table"><tr><th>Id</th><th>Current name</th><th>New Name</th></tr>`; message += `<table class="overflow-table"><tr><th>Id</th><th>Current name</th><th>New Name</th></tr>`;
const burgs = pack.burgs.filter(b => b.i && !b.removed); const burgs = pack.burgs.filter(b => b.i && !b.removed);
for (let i = 0; i < data.length && i <= burgs.length; i++) { for (let i = 0; i < data.length && i <= burgs.length; i++) {
const v = data[i]; const v = data[i];
@ -543,45 +520,36 @@ function overviewBurgs() {
message += `<tr><td style="width:20%">${burgs[i].i}</td><td style="width:40%">${burgs[i].name}</td><td style="width:40%">${v}</td></tr>`; message += `<tr><td style="width:20%">${burgs[i].i}</td><td style="width:40%">${burgs[i].name}</td><td style="width:40%">${v}</td></tr>`;
} }
message += `</tr></table>`; message += `</tr></table>`;
if (!change.length) message = "No changes found in the file. Please change some names to get a result"; if (!change.length) message = "No changes found in the file. Please change some names to get a result";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ const onConfirm = () => {
title: "Burgs bulk renaming",
width: "22em",
position: {my: "center", at: "center", of: "svg"},
buttons: {
Cancel: function () {
$(this).dialog("close");
},
Confirm: function () {
for (let i = 0; i < change.length; i++) { for (let i = 0; i < change.length; i++) {
const id = change[i].id; const id = change[i].id;
pack.burgs[id].name = change[i].name; pack.burgs[id].name = change[i].name;
burgLabels.select("[data-id='" + id + "']").text(change[i].name); burgLabels.select("[data-id='" + id + "']").text(change[i].name);
} }
$(this).dialog("close");
burgsOverviewAddLines(); burgsOverviewAddLines();
} };
}
confirmationDialog({
title: "Burgs bulk renaming",
message,
confirm: "Rename",
onConfirm
}); });
} }
function triggerAllBurgsRemove() { function triggerAllBurgsRemove() {
alertMessage.innerHTML = `Are you sure you want to remove all unlocked burgs except for capitals? const number = pack.burgs.filter(b => b.i && !b.removed && !b.capital && !b.lock).length;
<br><i>To remove a capital you have to remove a state first</i>`; confirmationDialog({
$("#alert").dialog({ title: `Remove ${number} burgs`,
resizable: false, message: `
title: "Remove all burgs", Are you sure you want to remove all <i>unlocked</i> burgs except for capitals?
buttons: { <br><i>To remove a capital you have to remove a state first</i>`,
Remove: function () { confirm: "Remove",
$(this).dialog("close"); onConfirm: removeAllBurgs
removeAllBurgs();
},
Cancel: function () {
$(this).dialog("close");
}
}
}); });
} }
@ -589,4 +557,9 @@ function overviewBurgs() {
pack.burgs.filter(b => b.i && !(b.capital || b.lock)).forEach(b => removeBurg(b.i)); pack.burgs.filter(b => b.i && !(b.capital || b.lock)).forEach(b => removeBurg(b.i));
burgsOverviewAddLines(); burgsOverviewAddLines();
} }
function invertLock() {
pack.burgs = pack.burgs.map(burg => ({...burg, lock: !burg.lock}));
burgsOverviewAddLines();
}
} }