Add the ability to regenerate cultures (#495)

* Add the ability to regenerate cultures

- Added a button to the tools menu for regeneration.
- Regeneration button will handle initial generation of cultures and expansion afterwards.
- Pressing regenerate will warn the user.
- Small cleanup of trailing whitespace.

* Refreshing cultures editor updates culture centers

* Regenerating cultures refreshes the culture editor

* Added a function to refresh all open editors

* Reset burg and state cultures after regeneration

* Address the problem of potential data loss

Any errors while iterating the states or burgs could potentially lose the index 0 metadata stored in the arrays. This will instead track the index and ignore the 0th result.

* Religions update cultures on culture regeneration

Updated function names to be more similar and more descriptive
This commit is contained in:
mdirienzo 2020-07-18 04:31:09 -04:00 committed by Azgaar
parent cf0a446b6a
commit fb28576f7c
6 changed files with 69 additions and 7 deletions

View file

@ -353,6 +353,32 @@
console.timeEnd("normalizeStates");
}
// Resets the cultures of all burgs and states to their
// cell or center cell's (respectively) culture.
const updateCultures = function () {
console.time('updateCulturesForBurgsAndStates');
// Assign the culture associated with the burgs cell.
pack.burgs = pack.burgs.map( (burg, index) => {
// Ignore metadata burg
if(index === 0) {
return burg;
}
return {...burg, culture: pack.cells.culture[burg.cell]};
});
// Assign the culture associated with the states' center cell.
pack.states = pack.states.map( (state, index) => {
// Ignore neutrals state
if(index === 0) {
return state;
}
return {...state, culture: pack.cells.culture[state.center]};
});
console.timeEnd('updateCulturesForBurgsAndStates');
}
// calculate and draw curved state labels for a list of states
const drawStateLabels = function(list) {
console.time("drawStateLabels");
@ -1029,6 +1055,6 @@
return {generate, expandStates, normalizeStates, assignColors,
drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics,
generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces};
generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces, updateCultures};
})));