mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: states regeneration when some states are locked
This commit is contained in:
parent
04b6d479b2
commit
3f25484367
3 changed files with 28 additions and 16 deletions
|
|
@ -7871,7 +7871,7 @@
|
|||
<script defer src="modules/relief-icons.js"></script>
|
||||
<script defer src="modules/ui/style.js"></script>
|
||||
<script defer src="modules/ui/editors.js?v=1.89.12"></script>
|
||||
<script defer src="modules/ui/tools.js?v=1.89.24"></script>
|
||||
<script defer src="modules/ui/tools.js?v=1.89.27"></script>
|
||||
<script defer src="modules/ui/world-configurator.js"></script>
|
||||
<script defer src="modules/ui/heightmap-editor.js?v=1.89.06"></script>
|
||||
<script defer src="modules/ui/provinces-editor.js?v=1.89.00"></script>
|
||||
|
|
|
|||
|
|
@ -137,7 +137,10 @@ function recalculatePopulation() {
|
|||
}
|
||||
|
||||
function regenerateStates() {
|
||||
recreateStates();
|
||||
const newStates = recreateStates();
|
||||
if (!newStates) return;
|
||||
|
||||
pack.states = newStates;
|
||||
BurgsAndStates.expandStates();
|
||||
BurgsAndStates.normalizeStates();
|
||||
BurgsAndStates.collectStatistics();
|
||||
|
|
@ -165,21 +168,32 @@ function recreateStates() {
|
|||
Math.random = aleaPRNG(localSeed);
|
||||
|
||||
const statesCount = +regionsOutput.value;
|
||||
if (!statesCount) {
|
||||
tip(`<i>States Number</i> option value is zero. No counties are generated`, false, "error");
|
||||
return null;
|
||||
}
|
||||
|
||||
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
||||
if (!validBurgs.length) {
|
||||
tip("There are no any burgs to generate states. Please create burgs first", false, "error");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!validBurgs.length)
|
||||
return tip("There are no any burgs to generate states. Please create burgs first", false, "error");
|
||||
if (validBurgs.length < statesCount)
|
||||
tip(
|
||||
`Not enough burgs to generate ${statesCount} states. Will generate only ${validBurgs.length} states`,
|
||||
false,
|
||||
"warn"
|
||||
);
|
||||
if (validBurgs.length < statesCount) {
|
||||
const message = `Not enough burgs to generate ${statesCount} states. Will generate only ${validBurgs.length} states`;
|
||||
tip(message, false, "warn");
|
||||
}
|
||||
|
||||
const lockedStates = pack.states.filter(s => s.i && !s.removed && s.lock);
|
||||
const validStates = pack.states.filter(s => s.i && !s.removed);
|
||||
const lockedStates = validStates.filter(s => s.lock);
|
||||
const lockedStatesIds = lockedStates.map(s => s.i);
|
||||
const lockedStatesCapitals = lockedStates.map(s => s.capital);
|
||||
|
||||
if (lockedStates.length === validStates.length) {
|
||||
tip("Unable to regenerate as all states are locked", false, "error");
|
||||
return null;
|
||||
}
|
||||
|
||||
// turn all old capitals into towns, except for the capitals of locked states
|
||||
for (const burg of validBurgs) {
|
||||
if (!burg.capital) continue;
|
||||
|
|
@ -229,7 +243,7 @@ function recreateStates() {
|
|||
// restore locked states
|
||||
lockedStates.forEach(state => {
|
||||
const newId = newStates.length;
|
||||
const {x, y} = validBurgs[state.capital];
|
||||
const {x, y} = pack.burgs[state.capital];
|
||||
capitalsTree.add([x, y]);
|
||||
|
||||
// update label id reference
|
||||
|
|
@ -300,9 +314,7 @@ function recreateStates() {
|
|||
newStates.push({i, name, type, capital: capital.i, center: capital.cell, culture, expansionism, coa});
|
||||
}
|
||||
|
||||
if (!statesCount) tip(`<i>States Number</i> option is set to zero. No counties are generated`, false, "warn");
|
||||
|
||||
pack.states = newStates;
|
||||
return newStates;
|
||||
}
|
||||
|
||||
function regenerateProvinces() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
// version and caching control
|
||||
const version = "1.89.26"; // generator version, update each time
|
||||
const version = "1.89.27"; // generator version, update each time
|
||||
|
||||
{
|
||||
document.title += " v" + version;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue