mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 02:01:22 +01:00
feat: split burgs to groups
This commit is contained in:
parent
f51f78a7a6
commit
63898d8fd8
15 changed files with 543 additions and 383 deletions
|
|
@ -287,7 +287,7 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
if (pack.cells.burg[cell])
|
||||
return tip("There is already a burg in this cell. Please select a free cell", false, "error");
|
||||
|
||||
addBurg(point); // add new burg
|
||||
Burgs.add(point); // add new burg
|
||||
|
||||
if (d3.event.shiftKey === false) {
|
||||
exitAddBurgMode();
|
||||
|
|
|
|||
|
|
@ -128,78 +128,6 @@ function applySorting(headers) {
|
|||
.forEach(line => list.appendChild(line));
|
||||
}
|
||||
|
||||
function addBurg(point) {
|
||||
const {cells, states} = pack;
|
||||
const x = rn(point[0], 2);
|
||||
const y = rn(point[1], 2);
|
||||
|
||||
const cellId = findCell(x, y);
|
||||
const i = pack.burgs.length;
|
||||
const culture = cells.culture[cellId];
|
||||
const name = Names.getCulture(culture);
|
||||
const state = cells.state[cellId];
|
||||
const feature = cells.f[cellId];
|
||||
|
||||
const population = Math.max(cells.s[cellId] / 3 + i / 1000 + (cellId % 100) / 1000, 0.1);
|
||||
const type = Burgs.getType(cellId, false);
|
||||
|
||||
// generate emblem
|
||||
const coa = COA.generate(states[state].coa, 0.25, null, type);
|
||||
coa.shield = COA.getShield(culture, state);
|
||||
COArenderer.add("burg", i, coa, x, y);
|
||||
|
||||
const burg = {
|
||||
name,
|
||||
cell: cellId,
|
||||
x,
|
||||
y,
|
||||
state,
|
||||
i,
|
||||
culture,
|
||||
feature,
|
||||
capital: 0,
|
||||
port: 0,
|
||||
temple: 0,
|
||||
population,
|
||||
coa,
|
||||
type
|
||||
};
|
||||
pack.burgs.push(burg);
|
||||
cells.burg[cellId] = i;
|
||||
|
||||
const townSize = burgIcons.select("#towns").attr("size") || 0.5;
|
||||
burgIcons
|
||||
.select("#towns")
|
||||
.append("circle")
|
||||
.attr("id", "burg" + i)
|
||||
.attr("data-id", i)
|
||||
.attr("cx", x)
|
||||
.attr("cy", y)
|
||||
.attr("r", townSize);
|
||||
burgLabels
|
||||
.select("#towns")
|
||||
.append("text")
|
||||
.attr("id", "burgLabel" + i)
|
||||
.attr("data-id", i)
|
||||
.attr("x", x)
|
||||
.attr("y", y)
|
||||
.attr("dy", `${townSize * -1.5}px`)
|
||||
.text(name);
|
||||
|
||||
Burgs.defineBurgFeatures(burg);
|
||||
|
||||
const newRoute = Routes.connect(cellId);
|
||||
if (newRoute && layerIsOn("toggleRoutes")) {
|
||||
routes
|
||||
.select("#" + newRoute.group)
|
||||
.append("path")
|
||||
.attr("d", Routes.getPath(newRoute))
|
||||
.attr("id", "route" + newRoute.i);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function moveBurgToGroup(id, g) {
|
||||
const label = document.querySelector("#burgLabels [data-id='" + id + "']");
|
||||
const icon = document.querySelector("#burgIcons [data-id='" + id + "']");
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ function editHeightmap(options) {
|
|||
States.defineStateForms();
|
||||
Provinces.generate();
|
||||
Provinces.getPoles();
|
||||
Burgs.specifyBurgs();
|
||||
Burgs.specify();
|
||||
|
||||
Rivers.specify();
|
||||
Features.specify();
|
||||
|
|
|
|||
|
|
@ -342,8 +342,8 @@ function addStylePreset() {
|
|||
"stroke-dasharray",
|
||||
"stroke-linecap"
|
||||
];
|
||||
options.burgs.groups.forEach(group => {
|
||||
attributes[`#burgIcons > g[data-name='${group}']`] = burgIconsAttributes;
|
||||
options.burgs.groups.forEach(({name}) => {
|
||||
attributes[`#burgIcons > g.${name}`] = burgIconsAttributes;
|
||||
});
|
||||
|
||||
for (const selector in attributes) {
|
||||
|
|
|
|||
|
|
@ -1125,39 +1125,6 @@ styleScaleBar.on("input", function (event) {
|
|||
});
|
||||
|
||||
function updateElements() {
|
||||
// burgIcons to desired size
|
||||
burgIcons.selectAll("g").each(function () {
|
||||
const size = +this.getAttribute("size");
|
||||
d3.select(this)
|
||||
.selectAll("circle")
|
||||
.each(function () {
|
||||
this.setAttribute("r", size);
|
||||
});
|
||||
burgLabels
|
||||
.select("g#" + this.id)
|
||||
.selectAll("text")
|
||||
.each(function () {
|
||||
this.setAttribute("dy", `${size * -1.5}px`);
|
||||
});
|
||||
});
|
||||
|
||||
// anchor icons to desired size
|
||||
anchors.selectAll("g").each(function (d) {
|
||||
const size = +this.getAttribute("size");
|
||||
d3.select(this)
|
||||
.selectAll("use")
|
||||
.each(function () {
|
||||
const id = +this.dataset.id;
|
||||
const x = pack.burgs[id].x,
|
||||
y = pack.burgs[id].y;
|
||||
this.setAttribute("x", rn(x - size * 0.47, 2));
|
||||
this.setAttribute("y", rn(y - size * 0.47, 2));
|
||||
this.setAttribute("width", size);
|
||||
this.setAttribute("height", size);
|
||||
});
|
||||
});
|
||||
|
||||
// redraw elements
|
||||
if (layerIsOn("toggleHeight")) drawHeightmap();
|
||||
if (legend.selectAll("*").size() && window.redrawLegend) redrawLegend();
|
||||
oceanLayers.selectAll("path").remove();
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ function regenerateBurgs() {
|
|||
.filter(s => s.i && !s.removed && !s.capital)
|
||||
.forEach(s => {
|
||||
const [x, y] = cells.p[s.center];
|
||||
const burgId = addBurg([x, y]);
|
||||
const burgId = Burgs.add([x, y]);
|
||||
s.capital = burgId;
|
||||
s.center = pack.burgs[burgId].cell;
|
||||
pack.burgs[burgId].capital = 1;
|
||||
|
|
@ -443,7 +443,7 @@ function regenerateBurgs() {
|
|||
if (f.port) f.port = 0; // reset features ports counter
|
||||
});
|
||||
|
||||
Burgs.specifyBurgs();
|
||||
Burgs.specify();
|
||||
regenerateRoutes();
|
||||
|
||||
drawBurgIcons();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue