From d24f92efab4289450f13321735a570cf124edf89 Mon Sep 17 00:00:00 2001 From: Michael DiRienzo Date: Thu, 9 Jul 2020 01:02:21 -0400 Subject: [PATCH] Reset burg and state cultures after regeneration --- modules/burgs-and-states.js | 27 ++++++++++++++++++++++++++- modules/ui/tools.js | 3 ++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index b3083ac6..87cad104 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -353,6 +353,31 @@ 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 const drawStateLabels = function(list) { console.time("drawStateLabels"); @@ -1027,6 +1052,6 @@ return {generate, expandStates, normalizeStates, assignColors, drawBurgs, specifyBurgs, defineBurgFeatures, drawStateLabels, collectStatistics, - generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces}; + generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces, resetCultures}; }))); diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 26b2932a..89d46103 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -248,8 +248,9 @@ function regenerateReligions() { function regenerateCultures() { Cultures.generate(); Cultures.expand(); + BurgsAndStates.resetCultures(); if (!layerIsOn("toggleCultures")) toggleCultures(); else drawCultures(); - if (document.getElementById("culturesEditorRefresh").offsetParent) culturesEditorRefresh.click(); + refreshAllEditors(); } function regenerateMilitary() {