mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
fix: burg groups - apply default new groups on load if source has default groups
This commit is contained in:
parent
f03cade309
commit
bb1e913929
1 changed files with 39 additions and 32 deletions
|
|
@ -975,43 +975,50 @@ export function resolveVersionConflicts(mapVersion) {
|
||||||
|
|
||||||
if (isOlderThan("1.109.0")) {
|
if (isOlderThan("1.109.0")) {
|
||||||
// v1.109.0 added customizable burg groups and icons
|
// v1.109.0 added customizable burg groups and icons
|
||||||
burgIcons.selectAll("circle, use").each(function () {
|
|
||||||
const group = this.parentNode.id;
|
|
||||||
const id = this.id.replace(/^burg/, "");
|
|
||||||
const burg = pack.burgs[id];
|
|
||||||
if (burg) burg.group = group;
|
|
||||||
});
|
|
||||||
|
|
||||||
options.burgs = {groups: []};
|
options.burgs = {groups: []};
|
||||||
|
|
||||||
burgIcons.selectAll("g").each(function (_el, index) {
|
// default groups were 'cities' and 'towns'
|
||||||
const name = this.id;
|
const iconGroups = burgIcons.selectAll("g");
|
||||||
const isDefault = name === "towns";
|
const citiesGroup = burgIcons.select("#cities");
|
||||||
options.burgs.groups.push({name, active: true, order: index + 1, isDefault, preview: "watabou-city"});
|
const townsGroup = burgIcons.select("#towns");
|
||||||
|
if (!iconGroups.size() || (iconGroups.size() === 2 && citiesGroup.size() && townsGroup.size())) {
|
||||||
const size = Number(this.getAttribute("size") || 2) * 2;
|
// it looks the loaded map has old default groups
|
||||||
this.removeAttribute("size");
|
|
||||||
this.setAttribute("font-size", size);
|
|
||||||
|
|
||||||
this.setAttribute("stroke-width", 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!options.burgs.groups.length) {
|
|
||||||
options.burgs.groups = Burgs.getDefaultGroups();
|
options.burgs.groups = Burgs.getDefaultGroups();
|
||||||
|
} else {
|
||||||
|
burgIcons.selectAll("circle, use").each(function () {
|
||||||
|
const group = this.parentNode.id;
|
||||||
|
const id = this.id.replace(/^burg/, "");
|
||||||
|
const burg = pack.burgs[id];
|
||||||
|
if (group && burg) burg.group = group;
|
||||||
|
});
|
||||||
|
|
||||||
|
burgIcons.selectAll("g").each(function (_el, index) {
|
||||||
|
const name = this.id;
|
||||||
|
const isDefault = name === "towns";
|
||||||
|
options.burgs.groups.push({name, active: true, order: index + 1, isDefault, preview: "watabou-city"});
|
||||||
|
|
||||||
|
const size = Number(this.getAttribute("size") || 2) * 2;
|
||||||
|
this.removeAttribute("size");
|
||||||
|
this.setAttribute("font-size", size);
|
||||||
|
|
||||||
|
this.setAttribute("stroke-width", 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (options.burgs.groups.filter(g => g.isDefault).length === 0) {
|
||||||
|
options.burgs.groups[0].isDefault = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
anchors.selectAll("g").each(function () {
|
||||||
|
const size = Number(this.getAttribute("size") || 1);
|
||||||
|
this.removeAttribute("size");
|
||||||
|
this.setAttribute("font-size", size);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.burgs.groups.filter(g => g.isDefault).length === 0) {
|
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
||||||
options.burgs.groups[0].isDefault = true;
|
const populations = validBurgs.map(b => b.population).sort((a, b) => a - b);
|
||||||
}
|
validBurgs.forEach(burg => {
|
||||||
|
if (!burg.group) Burgs.defineGroup(burg, populations);
|
||||||
anchors.selectAll("g").each(function () {
|
|
||||||
const size = Number(this.getAttribute("size") || 1);
|
|
||||||
this.removeAttribute("size");
|
|
||||||
this.setAttribute("font-size", size);
|
|
||||||
});
|
|
||||||
|
|
||||||
pack.burgs.forEach(burg => {
|
|
||||||
if (!burg.i || burg.removed) return;
|
|
||||||
|
|
||||||
if (burg.MFCG) {
|
if (burg.MFCG) {
|
||||||
burg.link = getBurgLink(burg);
|
burg.link = getBurgLink(burg);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue