mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
feat: burg group editor - apply changes
This commit is contained in:
parent
b6708bf698
commit
b700bf0630
8 changed files with 102 additions and 29 deletions
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
function drawBurgLabels() {
|
||||
TIME && console.time("drawBurgLabels");
|
||||
|
||||
burgLabels.selectAll("text").remove(); // cleanup
|
||||
createLabelGroups();
|
||||
|
||||
for (const {name} of options.burgs.groups) {
|
||||
const burgsInGroup = pack.burgs.filter(b => b.group === name && !b.removed);
|
||||
|
|
@ -39,3 +38,27 @@ function drawBurgLabel(burg) {
|
|||
.attr("dy", "-0.4em")
|
||||
.text(burg.name);
|
||||
}
|
||||
|
||||
function createLabelGroups() {
|
||||
const defaultStyle = style.burgLabels.towns || Object.values(style.burgLabels)[0];
|
||||
|
||||
// save existing styles and remove all groups
|
||||
document.querySelectorAll("g#burgLabels > g").forEach(group => {
|
||||
const groupStyle = Object.keys(defaultStyle).reduce((acc, key) => {
|
||||
acc[key] = group.getAttribute(key);
|
||||
return acc;
|
||||
}, {});
|
||||
style.burgLabels[group.id] = groupStyle;
|
||||
group.remove();
|
||||
});
|
||||
|
||||
// create groups for each burg group and apply stored or default style
|
||||
const sortedGroups = [...options.burgs.groups].sort((a, b) => a.order - b.order);
|
||||
for (const {name} of sortedGroups) {
|
||||
const group = burgLabels.append("g").attr("id", name);
|
||||
const styles = style.burgLabels[name] || defaultStyle;
|
||||
Object.entries(styles).forEach(([key, value]) => {
|
||||
group.attr(key, value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue