mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: regenerate burgs - remove burg notes, keep locked notes
This commit is contained in:
parent
9d83025db3
commit
d1c09935a9
4 changed files with 52 additions and 33 deletions
|
|
@ -8067,8 +8067,8 @@
|
||||||
|
|
||||||
<script defer src="modules/relief-icons.js"></script>
|
<script defer src="modules/relief-icons.js"></script>
|
||||||
<script defer src="modules/ui/style.js?v=1.96.00"></script>
|
<script defer src="modules/ui/style.js?v=1.96.00"></script>
|
||||||
<script defer src="modules/ui/editors.js?v=1.97.00"></script>
|
<script defer src="modules/ui/editors.js?v=1.97.12"></script>
|
||||||
<script defer src="modules/ui/tools.js?v=1.96.03"></script>
|
<script defer src="modules/ui/tools.js?v=1.97.12"></script>
|
||||||
<script defer src="modules/ui/world-configurator.js?v=1.98.00"></script>
|
<script defer src="modules/ui/world-configurator.js?v=1.98.00"></script>
|
||||||
<script defer src="modules/ui/heightmap-editor.js?v=1.96.00"></script>
|
<script defer src="modules/ui/heightmap-editor.js?v=1.96.00"></script>
|
||||||
<script defer src="modules/ui/provinces-editor.js?v=1.96.00"></script>
|
<script defer src="modules/ui/provinces-editor.js?v=1.96.00"></script>
|
||||||
|
|
|
||||||
|
|
@ -223,18 +223,19 @@ function addBurgsGroup(group) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeBurg(id) {
|
function removeBurg(id) {
|
||||||
const label = document.querySelector("#burgLabels [data-id='" + id + "']");
|
document.querySelector("#burgLabels [data-id='" + id + "']")?.remove();
|
||||||
const icon = document.querySelector("#burgIcons [data-id='" + id + "']");
|
document.querySelector("#burgIcons [data-id='" + id + "']")?.remove();
|
||||||
const anchor = document.querySelector("#anchors [data-id='" + id + "']");
|
document.querySelector("#anchors [data-id='" + id + "']")?.remove();
|
||||||
if (label) label.remove();
|
|
||||||
if (icon) icon.remove();
|
const cells = pack.cells;
|
||||||
if (anchor) anchor.remove();
|
const burg = pack.burgs[id];
|
||||||
|
|
||||||
const cells = pack.cells,
|
|
||||||
burg = pack.burgs[id];
|
|
||||||
burg.removed = true;
|
burg.removed = true;
|
||||||
cells.burg[burg.cell] = 0;
|
cells.burg[burg.cell] = 0;
|
||||||
|
|
||||||
|
const noteId = notes.findIndex(note => note.id === `burg${id}`);
|
||||||
|
if (noteId !== -1) notes.splice(noteId, 1);
|
||||||
|
|
||||||
if (burg.coa) {
|
if (burg.coa) {
|
||||||
const coaId = "burgCOA" + id;
|
const coaId = "burgCOA" + id;
|
||||||
if (byId(coaId)) byId(coaId).remove();
|
if (byId(coaId)) byId(coaId).remove();
|
||||||
|
|
|
||||||
|
|
@ -335,29 +335,44 @@ function regenerateProvinces() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function regenerateBurgs() {
|
function regenerateBurgs() {
|
||||||
const {cells, states} = pack;
|
const {cells, features, burgs, states, provinces} = pack;
|
||||||
const lockedburgs = pack.burgs.filter(b => b.i && !b.removed && b.lock);
|
|
||||||
rankCells();
|
rankCells();
|
||||||
|
|
||||||
cells.burg = new Uint16Array(cells.i.length);
|
// remove notes for unlocked burgs
|
||||||
const burgs = (pack.burgs = [0]); // clear burgs array
|
notes = notes.filter(note => {
|
||||||
states.filter(s => s.i).forEach(s => (s.capital = 0)); // clear state capitals
|
if (note.id.startsWith("burg")) {
|
||||||
pack.provinces.filter(p => p.i).forEach(p => (p.burg = 0)); // clear province capitals
|
const burgId = +note.id.slice(4);
|
||||||
|
return burgs[burgId]?.lock;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const newBurgs = [0]; // new burgs array
|
||||||
const burgsTree = d3.quadtree();
|
const burgsTree = d3.quadtree();
|
||||||
|
|
||||||
// add locked burgs
|
cells.burg = new Uint16Array(cells.i.length); // clear cells burg data
|
||||||
|
states.filter(s => s.i).forEach(s => (s.capital = 0)); // clear state capitals
|
||||||
|
provinces.filter(p => p.i).forEach(p => (p.burg = 0)); // clear province capitals
|
||||||
|
|
||||||
|
// readd locked burgs
|
||||||
|
const lockedburgs = burgs.filter(burg => burg.i && !burg.removed && burg.lock);
|
||||||
for (let j = 0; j < lockedburgs.length; j++) {
|
for (let j = 0; j < lockedburgs.length; j++) {
|
||||||
const id = burgs.length;
|
|
||||||
const lockedBurg = lockedburgs[j];
|
const lockedBurg = lockedburgs[j];
|
||||||
lockedBurg.i = id;
|
const newId = newBurgs.length;
|
||||||
burgs.push(lockedBurg);
|
|
||||||
|
const noteIndex = notes.findIndex(note => note.id === `burg${lockedBurg.i}`);
|
||||||
|
if (noteIndex !== -1) notes[noteIndex].id = `burg${newId}`;
|
||||||
|
|
||||||
|
lockedBurg.i = newId;
|
||||||
|
newBurgs.push(lockedBurg);
|
||||||
|
|
||||||
burgsTree.add([lockedBurg.x, lockedBurg.y]);
|
burgsTree.add([lockedBurg.x, lockedBurg.y]);
|
||||||
cells.burg[lockedBurg.cell] = id;
|
cells.burg[lockedBurg.cell] = newId;
|
||||||
|
|
||||||
if (lockedBurg.capital) {
|
if (lockedBurg.capital) {
|
||||||
const stateId = lockedBurg.state;
|
const stateId = lockedBurg.state;
|
||||||
states[stateId].capital = id;
|
states[stateId].capital = newId;
|
||||||
states[stateId].center = lockedBurg.cell;
|
states[stateId].center = lockedBurg.cell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -370,8 +385,8 @@ function regenerateBurgs() {
|
||||||
existingStatesCount;
|
existingStatesCount;
|
||||||
const spacing = (graphWidth + graphHeight) / 150 / (burgsCount ** 0.7 / 66); // base min distance between towns
|
const spacing = (graphWidth + graphHeight) / 150 / (burgsCount ** 0.7 / 66); // base min distance between towns
|
||||||
|
|
||||||
for (let i = 0; i < sorted.length && burgs.length < burgsCount; i++) {
|
for (let i = 0; i < sorted.length && newBurgs.length < burgsCount; i++) {
|
||||||
const id = burgs.length;
|
const id = newBurgs.length;
|
||||||
const cell = sorted[i];
|
const cell = sorted[i];
|
||||||
const [x, y] = cells.p[cell];
|
const [x, y] = cells.p[cell];
|
||||||
|
|
||||||
|
|
@ -387,24 +402,27 @@ function regenerateBurgs() {
|
||||||
|
|
||||||
const culture = cells.culture[cell];
|
const culture = cells.culture[cell];
|
||||||
const name = Names.getCulture(culture);
|
const name = Names.getCulture(culture);
|
||||||
burgs.push({cell, x, y, state: stateId, i: id, culture, name, capital, feature: cells.f[cell]});
|
newBurgs.push({cell, x, y, state: stateId, i: id, culture, name, capital, feature: cells.f[cell]});
|
||||||
burgsTree.add([x, y]);
|
burgsTree.add([x, y]);
|
||||||
cells.burg[cell] = id;
|
cells.burg[cell] = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pack.burgs = newBurgs; // assign new burgs array
|
||||||
|
|
||||||
// add a capital at former place for states without added capitals
|
// add a capital at former place for states without added capitals
|
||||||
states
|
states
|
||||||
.filter(s => s.i && !s.removed && !s.capital)
|
.filter(s => s.i && !s.removed && !s.capital)
|
||||||
.forEach(s => {
|
.forEach(s => {
|
||||||
const burg = addBurg([cells.p[s.center][0], cells.p[s.center][1]]); // add new burg
|
const [x, y] = cells.p[s.center];
|
||||||
s.capital = burg;
|
const burgId = addBurg([x, y]);
|
||||||
s.center = pack.burgs[burg].cell;
|
s.capital = burgId;
|
||||||
pack.burgs[burg].capital = 1;
|
s.center = pack.burgs[burgId].cell;
|
||||||
pack.burgs[burg].state = s.i;
|
pack.burgs[burgId].capital = 1;
|
||||||
moveBurgToGroup(burg, "cities");
|
pack.burgs[burgId].state = s.i;
|
||||||
|
moveBurgToGroup(burgId, "cities");
|
||||||
});
|
});
|
||||||
|
|
||||||
pack.features.forEach(f => {
|
features.forEach(f => {
|
||||||
if (f.port) f.port = 0; // reset features ports counter
|
if (f.port) f.port = 0; // reset features ports counter
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// version and caching control
|
// version and caching control
|
||||||
const version = "1.97.11"; // generator version, update each time
|
const version = "1.97.12"; // generator version, update each time
|
||||||
|
|
||||||
{
|
{
|
||||||
document.title += " v" + version;
|
document.title += " v" + version;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue