mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
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:
parent
0e5388c7f5
commit
43b3c8b807
6 changed files with 69 additions and 7 deletions
|
|
@ -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="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="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="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="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="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>
|
<button id="regenerateMarkers" data-tip="Click to regenerate markers. Hold Ctrl and click to set markers number multiplier">Markers</button>
|
||||||
|
|
@ -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 </div>
|
<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 </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 </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 </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="militaryBody" data-type="absolute"></div>
|
<div id="militaryBody" data-type="absolute"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -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 </div>
|
<div data-tip="Regiment emblem and name. Click to sort by name" style="width: 12em" class="sortable alphabetically" data-sortby="name">Name </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 </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 </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="regimentsBody" data-type="absolute"></div>
|
<div id="regimentsBody" data-type="absolute"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,32 @@
|
||||||
console.timeEnd("normalizeStates");
|
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
|
// 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 +1055,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, updateCultures};
|
||||||
|
|
||||||
})));
|
})));
|
||||||
|
|
|
||||||
|
|
@ -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)
|
// assign a unique two-letters code (abbreviation)
|
||||||
function getCode(rawName) {
|
function getCode(rawName) {
|
||||||
const name = rawName.replace("Old ", ""); // remove Old prefix
|
const name = rawName.replace("Old ", ""); // remove Old prefix
|
||||||
|
|
@ -350,6 +361,6 @@
|
||||||
return type() + " of the " + generateMeaning();
|
return type() + " of the " + generateMeaning();
|
||||||
};
|
};
|
||||||
|
|
||||||
return {generate, add, getDeityName, expandReligions};
|
return {generate, add, getDeityName, expandReligions, updateCultures};
|
||||||
|
|
||||||
})));
|
})));
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ function editCultures() {
|
||||||
function refreshCulturesEditor() {
|
function refreshCulturesEditor() {
|
||||||
culturesCollectStatistics();
|
culturesCollectStatistics();
|
||||||
culturesEditorAddLines();
|
culturesEditorAddLines();
|
||||||
|
drawCultureCenters();
|
||||||
}
|
}
|
||||||
|
|
||||||
function culturesCollectStatistics() {
|
function culturesCollectStatistics() {
|
||||||
|
|
|
||||||
|
|
@ -630,4 +630,17 @@ function selectIcon(initial, callback) {
|
||||||
Apply: function() {callback(input.value||"⠀"); $(this).dialog("close")},
|
Apply: function() {callback(input.value||"⠀"); $(this).dialog("close")},
|
||||||
Close: function() {callback(initial); $(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');
|
||||||
}
|
}
|
||||||
|
|
@ -55,15 +55,16 @@ toolsContent.addEventListener("click", function(event) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function processFeatureRegeneration(event, button) {
|
function processFeatureRegeneration(event, button) {
|
||||||
if (button === "regenerateStateLabels") {BurgsAndStates.drawStateLabels(); if (!layerIsOn("toggleLabels")) toggleLabels();} else
|
if (button === "regenerateStateLabels") {BurgsAndStates.drawStateLabels(); if (!layerIsOn("toggleLabels")) toggleLabels();} else
|
||||||
if (button === "regenerateReliefIcons") {ReliefIcons(); if (!layerIsOn("toggleRelief")) toggleRelief();} else
|
if (button === "regenerateReliefIcons") {ReliefIcons(); if (!layerIsOn("toggleRelief")) toggleRelief();} else
|
||||||
if (button === "regenerateRoutes") {Routes.regenerate(); if (!layerIsOn("toggleRoutes")) toggleRoutes();} else
|
if (button === "regenerateRoutes") {Routes.regenerate(); if (!layerIsOn("toggleRoutes")) toggleRoutes();} else
|
||||||
if (button === "regenerateRivers") regenerateRivers(); else
|
if (button === "regenerateRivers") regenerateRivers(); else
|
||||||
if (button === "regeneratePopulation") recalculatePopulation(); else
|
if (button === "regeneratePopulation") recalculatePopulation(); else
|
||||||
if (button === "regenerateBurgs") regenerateBurgs(); else
|
if (button === "regenerateBurgs") regenerateBurgs(); else
|
||||||
if (button === "regenerateStates") regenerateStates(); else
|
if (button === "regenerateStates") regenerateStates(); else
|
||||||
if (button === "regenerateProvinces") regenerateProvinces(); else
|
if (button === "regenerateProvinces") regenerateProvinces(); else
|
||||||
if (button === "regenerateReligions") regenerateReligions(); else
|
if (button === "regenerateReligions") regenerateReligions(); else
|
||||||
|
if (button === "regenerateCultures") regenerateCultures(); else
|
||||||
if (button === "regenerateMilitary") regenerateMilitary(); else
|
if (button === "regenerateMilitary") regenerateMilitary(); else
|
||||||
if (button === "regenerateIce") regenerateIce(); else
|
if (button === "regenerateIce") regenerateIce(); else
|
||||||
if (button === "regenerateMarkers") regenerateMarkers(event); else
|
if (button === "regenerateMarkers") regenerateMarkers(event); else
|
||||||
|
|
@ -244,6 +245,15 @@ function regenerateReligions() {
|
||||||
if (!layerIsOn("toggleReligions")) toggleReligions(); else drawReligions();
|
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() {
|
function regenerateMilitary() {
|
||||||
Military.generate();
|
Military.generate();
|
||||||
if (!layerIsOn("toggleMilitary")) toggleMilitary();
|
if (!layerIsOn("toggleMilitary")) toggleMilitary();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue