refactor(burgs): centralize burg management logic in Burgs module

Moved burg-related functions like `removeBurg`, `changeGroup`, and `toggleCapital` into the Burgs module to improve code organization and maintainability. Updated all references to these functions across the codebase. This change reduces duplication and ensures consistent behavior for burg management operations.
This commit is contained in:
Azgaar 2025-04-17 01:03:14 +02:00
parent a5939be6e2
commit fd9e010153
12 changed files with 213 additions and 215 deletions

View file

@ -182,16 +182,16 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
}
function triggerBurgRemove() {
const burg = +this.parentNode.dataset.id;
if (pack.burgs[burg].capital)
return tip("You cannot remove the capital. Please change the capital first", false, "error");
const burgId = +this.parentNode.dataset.id;
if (pack.burgs[burgId].capital)
return tip("You cannot remove the capital. Please change the state capital first", false, "error");
confirmationDialog({
title: "Remove burg",
message: "Are you sure you want to remove the burg? <br>This action cannot be reverted",
confirm: "Remove",
onConfirm: () => {
removeBurg(burg);
Burgs.remove(burgId);
burgsOverviewAddLines();
}
});
@ -536,17 +536,15 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
title: `Remove ${number} burgs`,
message: `
Are you sure you want to remove all <i>unlocked</i> burgs except for capitals?
<br><i>To remove a capital you have to remove a state first</i>`,
<br><i>To remove a capital you have to remove its state first</i>`,
confirm: "Remove",
onConfirm: removeAllBurgs
onConfirm: () => {
pack.burgs.filter(b => b.i && !(b.capital || b.lock)).forEach(b => Burgs.remove(b.i));
burgsOverviewAddLines();
}
});
}
function removeAllBurgs() {
pack.burgs.filter(b => b.i && !(b.capital || b.lock)).forEach(b => removeBurg(b.i));
burgsOverviewAddLines();
}
function toggleLockAll() {
const activeBurgs = pack.burgs.filter(b => b.i && !b.removed);
const allLocked = activeBurgs.every(burg => burg.lock);