Reset burg and state cultures after regeneration

This commit is contained in:
Michael DiRienzo 2020-07-09 01:02:21 -04:00
parent dff0f35de6
commit f1141d6baf
2 changed files with 28 additions and 2 deletions

View file

@ -353,6 +353,31 @@
console.timeEnd("normalizeStates"); console.timeEnd("normalizeStates");
} }
// Resets the cultures of all burgs and states to their
// cell or center cell's (respectively) culture.
const resetCultures = function () {
console.time('resetCulturesForBurgsAndStates');
// Pull out index 0 nodes so iterators don't touch them.
const burgTreeNode = pack.burgs.shift();
const neutralsStateNode = pack.states.shift();
// Assign the culture associated with the burgs cell.
pack.burgs = pack.burgs.map( (burg) => {
return {...burg, culture: pack.cells.culture[burg.cell]};
});
// Assign the culture associated with the states' center cell.
pack.states = pack.states.map( (state) => {
return {...state, culture: pack.cells.culture[state.center]};
});
// Prepend the index 0 nodes back onto the packgroups.
pack.burgs.unshift(burgTreeNode);
pack.states.unshift(neutralsStateNode);
console.timeEnd('resetCulturesForBurgsAndStates');
}
// calculate and draw curved state labels for a list of states // calculate and draw curved state labels for a list of states
const drawStateLabels = function(list) { const drawStateLabels = function(list) {
console.time("drawStateLabels"); console.time("drawStateLabels");
@ -1029,6 +1054,6 @@
return {generate, expandStates, normalizeStates, assignColors, return {generate, expandStates, normalizeStates, assignColors,
drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics, drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics,
generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces}; generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces, resetCultures};
}))); })));

View file

@ -248,8 +248,9 @@ function regenerateReligions() {
function regenerateCultures() { function regenerateCultures() {
Cultures.generate(); Cultures.generate();
Cultures.expand(); Cultures.expand();
BurgsAndStates.resetCultures();
if (!layerIsOn("toggleCultures")) toggleCultures(); else drawCultures(); if (!layerIsOn("toggleCultures")) toggleCultures(); else drawCultures();
if (document.getElementById("culturesEditorRefresh").offsetParent) culturesEditorRefresh.click(); refreshAllEditors();
} }
function regenerateMilitary() { function regenerateMilitary() {