burgAssign code by deuzeksmckinna

Starting point for moving burgs to a 'burg group' in bulk when burgs meet certain specific criteria.
Ideal version will have several filters as written on: Discord/fmg-suggestions/Mass Burg assignation/
This commit is contained in:
Ángel Montero Lamas 2024-01-28 14:13:30 +01:00
parent 845dc893d2
commit 4e729c123b
2 changed files with 28 additions and 0 deletions

View file

@ -34,6 +34,7 @@ function overviewBurgs(options = {stateId: null, cultureId: null}) {
byId("burgsListToLoad").addEventListener("change", function () {
uploadFile(this, importBurgNames);
});
byId("burgGroupAssign").addEventListener("click", burgGroupAssignInBulk);
byId("burgsLockAll").addEventListener("click", toggleLockAll);
byId("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove);
byId("burgsInvertLock").addEventListener("click", invertLock);
@ -584,6 +585,32 @@ function overviewBurgs(options = {stateId: null, cultureId: null}) {
});
}
function burgGroupAssignInBulk() {
// Define the constants separately
let minpop = 1000 / populationRate;
let maxpop = null / populationRate;
// Define the function to filter and move burgs
const filterAndMoveBurgs = (burgs) => {
// Filter the burgs based on certain conditions using the previously defined constants
const filteredBurgs = burgs.filter(b =>
b.cell &&
b.port &&
!b.citadel &&
b.walls &&
b.plaza &&
b.temple &&
b.shanty &&
b.population >= minpop &&
b.population <= maxpop &&
!b.capital
);
// Move the filtered burgs to the 'towns' group
filteredBurgs.forEach(b => moveBurgToGroup(b.i, 'towns'));
}
}
function triggerAllBurgsRemove() {
const number = pack.burgs.filter(b => b.i && !b.removed && !b.capital && !b.lock).length;
confirmationDialog({