Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to regenerate cultures #495

Merged
merged 7 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,7 @@
<button id="regenerateStates" data-tip="Click to select new capitals and regenerate states. Military forces will be regenerated as well, burgs will remain as they are">States</button>
<button id="regenerateProvinces" data-tip="Click to regenerate provinces. States will remain as they are">Provinces</button>
<button id="regenerateReligions" data-tip="Click to regenerate religions">Religions</button>
<button id="regenerateCultures" data-tip="Click to regenerate cultures">Cultures</button>
<button id="regenerateMilitary" data-tip="Click to recalculate military forces based on current military options">Military</button>
<button id="regenerateIce" data-tip="Click to icebergs and glaciers">Ice</button>
<button id="regenerateMarkers" data-tip="Click to regenerate markers. Hold Ctrl and click to set markers number multiplier">Markers</button>
Expand Down Expand Up @@ -3456,7 +3457,7 @@
<div data-tip="Military personnel rate (% of state population). Depends on war alert. Click to sort" style="width: 3.7em" class="sortable" data-sortby="rate">Rate&nbsp;</div>
<div data-tip="War Alert. Modifier to military forces number, depends of political situation. Click to sort" class="sortable" data-sortby="alert">War Alert&nbsp;</div>
</div>

<div id="militaryBody" data-type="absolute"></div>
</div>

Expand Down Expand Up @@ -3486,7 +3487,7 @@
<div data-tip="Regiment emblem and name. Click to sort by name" style="width: 12em" class="sortable alphabetically" data-sortby="name">Name&nbsp;</div>
<div data-tip="Total military personnel (not considering crew). Click to sort" style="margin-left: .8em" id="regimentsTotal" class="sortable icon-sort-number-down" data-sortby="total">Total&nbsp;</div>
</div>

<div id="regimentsBody" data-type="absolute"></div>
</div>

Expand Down
28 changes: 27 additions & 1 deletion modules/burgs-and-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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};

})));
13 changes: 12 additions & 1 deletion modules/religions-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@
});
}

function updateCultures() {
console.time('updateCulturesForReligions');
pack.religions = pack.religions.map( (religion, index) => {
if(index === 0) {
return religion;
}
return {...religion, culture: pack.cells.culture[religion.center]};
});
console.timeEnd('updateCulturesForReligions');
}

// assign a unique two-letters code (abbreviation)
function getCode(rawName) {
const name = rawName.replace("Old ", ""); // remove Old prefix
Expand Down Expand Up @@ -350,6 +361,6 @@
return type() + " of the " + generateMeaning();
};

return {generate, add, getDeityName, expandReligions};
return {generate, add, getDeityName, expandReligions, updateCultures};

})));
1 change: 1 addition & 0 deletions modules/ui/cultures-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function editCultures() {
function refreshCulturesEditor() {
culturesCollectStatistics();
culturesEditorAddLines();
drawCultureCenters();
}

function culturesCollectStatistics() {
Expand Down
13 changes: 13 additions & 0 deletions modules/ui/editors.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,17 @@ function selectIcon(initial, callback) {
Apply: function() {callback(input.value||"⠀"); $(this).dialog("close")},
Close: function() {callback(initial); $(this).dialog("close")}}
});
}

// Calls the refresh functionality on all editors currently open.
function refreshAllEditors() {
console.time('refreshAllEditors');
if (document.getElementById('culturesEditorRefresh').offsetParent) culturesEditorRefresh.click();
if (document.getElementById('biomesEditorRefresh').offsetParent) biomesEditorRefresh.click();
if (document.getElementById('diplomacyEditorRefresh').offsetParent) diplomacyEditorRefresh.click();
if (document.getElementById('provincesEditorRefresh').offsetParent) provincesEditorRefresh.click();
if (document.getElementById('religionsEditorRefresh').offsetParent) religionsEditorRefresh.click();
if (document.getElementById('statesEditorRefresh').offsetParent) statesEditorRefresh.click();
if (document.getElementById('zonesEditorRefresh').offsetParent) zonesEditorRefresh.click();
console.timeEnd('refreshAllEditors');
}
16 changes: 13 additions & 3 deletions modules/ui/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ toolsContent.addEventListener("click", function(event) {
});

function processFeatureRegeneration(event, button) {
if (button === "regenerateStateLabels") {BurgsAndStates.drawStateLabels(); if (!layerIsOn("toggleLabels")) toggleLabels();} else
if (button === "regenerateReliefIcons") {ReliefIcons(); if (!layerIsOn("toggleRelief")) toggleRelief();} else
if (button === "regenerateRoutes") {Routes.regenerate(); if (!layerIsOn("toggleRoutes")) toggleRoutes();} else
if (button === "regenerateStateLabels") {BurgsAndStates.drawStateLabels(); if (!layerIsOn("toggleLabels")) toggleLabels();} else
if (button === "regenerateReliefIcons") {ReliefIcons(); if (!layerIsOn("toggleRelief")) toggleRelief();} else
if (button === "regenerateRoutes") {Routes.regenerate(); if (!layerIsOn("toggleRoutes")) toggleRoutes();} else
if (button === "regenerateRivers") regenerateRivers(); else
if (button === "regeneratePopulation") recalculatePopulation(); else
if (button === "regenerateBurgs") regenerateBurgs(); else
if (button === "regenerateStates") regenerateStates(); else
if (button === "regenerateProvinces") regenerateProvinces(); else
if (button === "regenerateReligions") regenerateReligions(); else
if (button === "regenerateCultures") regenerateCultures(); else
if (button === "regenerateMilitary") regenerateMilitary(); else
if (button === "regenerateIce") regenerateIce(); else
if (button === "regenerateMarkers") regenerateMarkers(event); else
Expand Down Expand Up @@ -244,6 +245,15 @@ function regenerateReligions() {
if (!layerIsOn("toggleReligions")) toggleReligions(); else drawReligions();
}

function regenerateCultures() {
Cultures.generate();
Cultures.expand();
BurgsAndStates.updateCultures();
Religions.updateCultures();
if (!layerIsOn("toggleCultures")) toggleCultures(); else drawCultures();
refreshAllEditors();
}

function regenerateMilitary() {
Military.generate();
if (!layerIsOn("toggleMilitary")) toggleMilitary();
Expand Down