mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 10:01:23 +01:00
feat: burg groups - image icons
This commit is contained in:
parent
c29f3b73e8
commit
2f53a635c8
27 changed files with 225 additions and 211 deletions
|
|
@ -86,7 +86,7 @@ window.Burgs = (() => {
|
|||
const sorted = populatedCells.sort((a, b) => score[b] - score[a]);
|
||||
|
||||
const burgsNumber = getTownsNumber();
|
||||
let spacing = (graphWidth + graphHeight) / 150 / (burgsNumber ** 0.7 / 66); // min distance between towns
|
||||
let spacing = (graphWidth + graphHeight) / 150 / (burgsNumber ** 0.7 / 66); // min distance between town
|
||||
|
||||
for (let added = 0; added < burgsNumber && spacing > 1; ) {
|
||||
for (let i = 0; added < burgsNumber && i < sorted.length; i++) {
|
||||
|
|
@ -261,24 +261,24 @@ window.Burgs = (() => {
|
|||
}
|
||||
|
||||
const getDefaultGroups = () => [
|
||||
{name: "capitals", active: true, order: 9, features: {capital: true}, preview: "watabou-city"},
|
||||
{name: "cities", active: true, order: 8, percentile: 90, min: 5, preview: "watabou-city"},
|
||||
{name: "capital", active: true, order: 9, features: {capital: true}, preview: "watabou-city"},
|
||||
{name: "city", active: true, order: 8, percentile: 90, min: 5, preview: "watabou-city"},
|
||||
{
|
||||
name: "forts",
|
||||
name: "fort",
|
||||
active: true,
|
||||
features: {citadel: true, walls: false, plaza: false, port: false},
|
||||
order: 6,
|
||||
max: 1
|
||||
},
|
||||
{
|
||||
name: "monasteries",
|
||||
name: "monastery",
|
||||
active: true,
|
||||
features: {temple: true, walls: false, plaza: false, port: false},
|
||||
order: 5,
|
||||
max: 0.8
|
||||
},
|
||||
{
|
||||
name: "caravanserais",
|
||||
name: "caravanserai",
|
||||
active: true,
|
||||
features: {port: false, plaza: true},
|
||||
order: 4,
|
||||
|
|
@ -286,16 +286,15 @@ window.Burgs = (() => {
|
|||
biomes: [1, 2, 3]
|
||||
},
|
||||
{
|
||||
name: "trading_posts",
|
||||
name: "trading_post",
|
||||
active: true,
|
||||
order: 3,
|
||||
features: {plaza: true},
|
||||
max: 0.8,
|
||||
biomes: [5, 6, 7, 8, 9, 10, 11, 12],
|
||||
preview: "watabou-dwelling"
|
||||
biomes: [5, 6, 7, 8, 9, 10, 11, 12]
|
||||
},
|
||||
{
|
||||
name: "villages",
|
||||
name: "village",
|
||||
active: true,
|
||||
order: 2,
|
||||
min: 0.1,
|
||||
|
|
@ -304,14 +303,14 @@ window.Burgs = (() => {
|
|||
preview: "watabou-village"
|
||||
},
|
||||
{
|
||||
name: "hamlets",
|
||||
name: "hamlet",
|
||||
active: true,
|
||||
order: 1,
|
||||
features: {walls: false, plaza: false},
|
||||
max: 0.1,
|
||||
preview: "watabou-village"
|
||||
},
|
||||
{name: "towns", active: true, order: 7, isDefault: true, preview: "watabou-city"}
|
||||
{name: "town", active: true, order: 7, isDefault: true, preview: "watabou-city"}
|
||||
];
|
||||
|
||||
function defineGroup(burg, populations) {
|
||||
|
|
|
|||
|
|
@ -603,7 +603,7 @@ function stateRemove(stateId) {
|
|||
burg.state = 0;
|
||||
if (burg.capital) {
|
||||
burg.capital = 0;
|
||||
moveBurgToGroup(burg.i, "towns");
|
||||
moveBurgToGroup(burg.i, "town");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1192,7 +1192,7 @@ function addState() {
|
|||
// turn burg into a capital
|
||||
burgs[burg].capital = 1;
|
||||
burgs[burg].state = newState;
|
||||
moveBurgToGroup(burg, "cities");
|
||||
moveBurgToGroup(burg, "city");
|
||||
|
||||
if (d3.event.shiftKey === false) exitAddStateMode();
|
||||
|
||||
|
|
@ -1382,7 +1382,7 @@ function openStateMergeDialog() {
|
|||
pack.burgs.forEach(b => {
|
||||
if (statesToMerge.includes(b.state)) {
|
||||
if (b.capital) {
|
||||
moveBurgToGroup(b.i, "towns");
|
||||
moveBurgToGroup(b.i, "town");
|
||||
b.capital = 0;
|
||||
}
|
||||
b.state = rulingStateId;
|
||||
|
|
|
|||
|
|
@ -615,12 +615,12 @@ async function parseLoadedData(data, mapVersion) {
|
|||
console.error(
|
||||
`[Data integrity] Neutral burgs (${capitalBurgs
|
||||
.map(b => b.i)
|
||||
.join(", ")}) marked as capitals. Moving them to towns`
|
||||
.join(", ")}) marked as capitals. Moving them to town`
|
||||
);
|
||||
|
||||
capitalBurgs.forEach(burg => {
|
||||
burg.capital = 0;
|
||||
moveBurgToGroup(burg.i, "towns");
|
||||
moveBurgToGroup(burg.i, "town");
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
@ -629,13 +629,13 @@ async function parseLoadedData(data, mapVersion) {
|
|||
if (capitalBurgs.length > 1) {
|
||||
const message = `[Data integrity] State ${state.i} has multiple capitals (${capitalBurgs
|
||||
.map(b => b.i)
|
||||
.join(", ")}) assigned. Keeping the first as capital and moving others to towns`;
|
||||
.join(", ")}) assigned. Keeping the first as capital and moving others to town`;
|
||||
ERROR && console.error(message);
|
||||
|
||||
capitalBurgs.forEach((burg, i) => {
|
||||
if (!i) return;
|
||||
burg.capital = 0;
|
||||
moveBurgToGroup(burg.i, "towns");
|
||||
moveBurgToGroup(burg.i, "town");
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
@ -645,7 +645,7 @@ async function parseLoadedData(data, mapVersion) {
|
|||
ERROR &&
|
||||
console.error(`[Data integrity] State ${state.i} has no capital. Assigning the first burg as capital`);
|
||||
stateBurgs[0].capital = 1;
|
||||
moveBurgToGroup(stateBurgs[0].i, "cities");
|
||||
moveBurgToGroup(stateBurgs[0].i, "city");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1203,7 +1203,7 @@ window.Markers = (function () {
|
|||
const burgName = burgs[cells.burg[cell]].name;
|
||||
|
||||
const name = `${burgName} Portal`;
|
||||
const legend = `An element of the magic portal system connecting major cities. The portals were installed centuries ago, but still work fine.`;
|
||||
const legend = `An element of the magic portal system connecting major city. The portals were installed centuries ago, but still work fine.`;
|
||||
notes.push({id, name, legend});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function drawBurgIcons() {
|
|||
|
||||
// capitalAnchors
|
||||
// .selectAll("use")
|
||||
// .data(capitals.filter(c => c.port))
|
||||
// .data(capital.filter(c => c.port))
|
||||
// .enter()
|
||||
// .append("use")
|
||||
// .attr("xlink:href", "#icon-anchor")
|
||||
|
|
@ -62,7 +62,7 @@ function drawBurgIcon(burg) {
|
|||
}
|
||||
|
||||
function createIconGroups() {
|
||||
const defaultStyle = style.burgIcons.towns || Object.values(style.burgIcons)[0];
|
||||
const defaultStyle = style.burgIcons.town || Object.values(style.burgIcons)[0];
|
||||
|
||||
// save existing styles and remove all groups
|
||||
document.querySelectorAll("g#burgIcons > g").forEach(group => {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ function drawBurgLabels() {
|
|||
const labelGroup = burgLabels.select("#" + name);
|
||||
if (labelGroup.empty()) continue;
|
||||
|
||||
const dx = labelGroup.attr("data-dx");
|
||||
const dy = labelGroup.attr("data-dy");
|
||||
const dx = labelGroup.attr("data-dx") || 0;
|
||||
const dy = labelGroup.attr("data-dy") || 0;
|
||||
|
||||
labelGroup
|
||||
.selectAll("text")
|
||||
|
|
@ -33,8 +33,8 @@ function drawBurgLabels() {
|
|||
|
||||
function drawBurgLabel(burg) {
|
||||
const group = burgLabels.select("#" + burg.group);
|
||||
const dx = labelGroup.attr("data-dx");
|
||||
const dy = labelGroup.attr("data-dy");
|
||||
const dx = labelGroup.attr("data-dx") || 0;
|
||||
const dy = labelGroup.attr("data-dy") || 0;
|
||||
|
||||
group
|
||||
.append("text")
|
||||
|
|
@ -48,7 +48,7 @@ function drawBurgLabel(burg) {
|
|||
}
|
||||
|
||||
function createLabelGroups() {
|
||||
const defaultStyle = style.burgLabels.towns || Object.values(style.burgLabels)[0];
|
||||
const defaultStyle = style.burgLabels.town || Object.values(style.burgLabels)[0];
|
||||
|
||||
// save existing styles and remove all groups
|
||||
document.querySelectorAll("g#burgLabels > g").forEach(group => {
|
||||
|
|
|
|||
|
|
@ -298,10 +298,10 @@ window.ThreeD = (function () {
|
|||
raycaster.set(new THREE.Vector3(0, 1000, 0), new THREE.Vector3(0, -1, 0));
|
||||
|
||||
const states = viewbox.select("#labels #states");
|
||||
const cities = burgLabels.select("#cities");
|
||||
const towns = burgLabels.select("#towns");
|
||||
const city_icons = burgIcons.select("#cities");
|
||||
const town_icons = burgIcons.select("#towns");
|
||||
const city = burgLabels.select("#city");
|
||||
const town = burgLabels.select("#town");
|
||||
const city_icons = burgIcons.select("#city");
|
||||
const town_icons = burgIcons.select("#town");
|
||||
|
||||
const stateOptions = {
|
||||
font: states.attr("font-family"),
|
||||
|
|
@ -312,25 +312,25 @@ window.ThreeD = (function () {
|
|||
};
|
||||
|
||||
const cityOptions = {
|
||||
font: cities.attr("font-family"),
|
||||
size: +cities.attr("data-size"),
|
||||
color: cities.attr("fill"),
|
||||
font: city.attr("font-family"),
|
||||
size: +city.attr("data-size"),
|
||||
color: city.attr("fill"),
|
||||
elevation: 10,
|
||||
quality: 20,
|
||||
iconSize: 1,
|
||||
iconColor: "#666",
|
||||
line: 10 - cities.attr("data-size") / 2
|
||||
line: 10 - city.attr("data-size") / 2
|
||||
};
|
||||
|
||||
const townOptions = {
|
||||
font: towns.attr("font-family"),
|
||||
size: +towns.attr("data-size"),
|
||||
color: towns.attr("fill"),
|
||||
font: townttr("font-family"),
|
||||
size: +town.attr("data-size"),
|
||||
color: town.attr("fill"),
|
||||
elevation: 5,
|
||||
quality: 30,
|
||||
iconSize: 0.5,
|
||||
iconColor: "#666",
|
||||
line: 5 - towns.attr("data-size") / 2
|
||||
line: 5 - town.attr("data-size") / 2
|
||||
};
|
||||
|
||||
const city_icon_material = new THREE.MeshPhongMaterial({color: cityOptions.iconColor});
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ function editBurg(id) {
|
|||
}
|
||||
}
|
||||
|
||||
// in °C, array from -1 °C; source: https://en.wikipedia.org/wiki/List_of_cities_by_average_temperature
|
||||
// in °C, array from -1 °C; source: https://en.wikipedia.org/wiki/List_of_city_by_average_temperature
|
||||
const meanTempCityMap = {
|
||||
"-5": "Snag (Yukon)",
|
||||
"-4": "Yellowknife (Canada)",
|
||||
|
|
|
|||
|
|
@ -163,9 +163,9 @@ function moveAllBurgsToGroup(fromGroup, toGroup) {
|
|||
|
||||
function addBurgsGroup(group) {
|
||||
if (document.querySelector(`#burgLabels > #${group}`)) return;
|
||||
const labelCopy = document.querySelector("#burgLabels > #towns").cloneNode(false);
|
||||
const iconCopy = document.querySelector("#burgIcons > #towns").cloneNode(false);
|
||||
const anchorCopy = document.querySelector("#anchors > #towns").cloneNode(false);
|
||||
const labelCopy = document.querySelector("#burgLabels > #town").cloneNode(false);
|
||||
const iconCopy = document.querySelector("#burgIcons > #town").cloneNode(false);
|
||||
const anchorCopy = document.querySelector("#anchors > #town").cloneNode(false);
|
||||
|
||||
// FIXME: using the same id is against the spec!
|
||||
document.querySelector("#burgLabels").appendChild(labelCopy).id = group;
|
||||
|
|
@ -209,8 +209,8 @@ function toggleCapital(burgId) {
|
|||
burgs[burgId].capital = 1;
|
||||
burgs[prevCapitalId].capital = 0;
|
||||
|
||||
moveBurgToGroup(burgId, "cities");
|
||||
moveBurgToGroup(prevCapitalId, "towns");
|
||||
moveBurgToGroup(burgId, "city");
|
||||
moveBurgToGroup(prevCapitalId, "town");
|
||||
}
|
||||
|
||||
function togglePort(burg) {
|
||||
|
|
@ -227,7 +227,7 @@ function togglePort(burg) {
|
|||
if (!haven) tip("Port haven is not found, system won't be able to make a searoute", false, "warn");
|
||||
b.port = port;
|
||||
|
||||
const g = b.capital ? "cities" : "towns";
|
||||
const g = b.capital ? "city" : "town";
|
||||
const group = anchors.select("g#" + g);
|
||||
const size = +group.attr("size");
|
||||
group
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ function showMapTooltip(point, e, i, g) {
|
|||
if (burgId) {
|
||||
const burg = pack.burgs[burgId];
|
||||
const population = si(burg.population * populationRate * urbanization);
|
||||
tip(`${burg.name}. Population: ${population}. Group: ${burg.group}. Click to edit`);
|
||||
tip(`${burg.name} ${burg.group}. Population: ${population}. Click to edit`);
|
||||
if (burgsOverview?.offsetParent) highlightEditorLine(burgsOverview, burgId, 5000);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -392,7 +392,7 @@ function changeEmblemShape(emblemShape) {
|
|||
|
||||
function changeStatesNumber(value) {
|
||||
byId("statesNumber").style.color = +value ? null : "#b12117";
|
||||
burgLabels.select("#capitals").attr("data-size", Math.max(rn(6 - value / 20), 3));
|
||||
burgLabels.select("#capital").attr("data-size", Math.max(rn(6 - value / 20), 3));
|
||||
labels.select("#countries").attr("data-size", Math.max(rn(18 - value / 6), 4));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ function editProvinces() {
|
|||
|
||||
// turn province burg into a capital
|
||||
burgs[burgId].capital = 1;
|
||||
moveBurgToGroup(burgId, "cities");
|
||||
moveBurgToGroup(burgId, "city");
|
||||
|
||||
// move all burgs to a new state
|
||||
province.burgs.forEach(b => (burgs[b].state = newStateId));
|
||||
|
|
|
|||
|
|
@ -211,12 +211,12 @@ function recreateStates() {
|
|||
return null;
|
||||
}
|
||||
|
||||
// turn all old capitals into towns, except for the capitals of locked states
|
||||
// turn all old capitals into town, except for the capitals of locked states
|
||||
for (const burg of validBurgs) {
|
||||
if (!burg.capital) continue;
|
||||
if (lockedStatesCapitals.includes(burg.i)) continue;
|
||||
|
||||
moveBurgToGroup(burg.i, "towns");
|
||||
moveBurgToGroup(burg.i, "town");
|
||||
burg.capital = 0;
|
||||
}
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ function recreateStates() {
|
|||
burg.capital = 1;
|
||||
capital = burg;
|
||||
capitalsTree.add([x, y]);
|
||||
moveBurgToGroup(burg.i, "cities");
|
||||
moveBurgToGroup(burg.i, "city");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ function regenerateBurgs() {
|
|||
const burgsCount =
|
||||
(manorsInput.value === "1000" ? rn(sorted.length / 5 / (grid.points.length / 10000) ** 0.8) : +manorsInput.value) +
|
||||
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 town
|
||||
|
||||
for (let i = 0; i < sorted.length && newBurgs.length < burgsCount; i++) {
|
||||
const id = newBurgs.length;
|
||||
|
|
@ -438,7 +438,7 @@ function regenerateBurgs() {
|
|||
s.center = pack.burgs[burgId].cell;
|
||||
pack.burgs[burgId].capital = 1;
|
||||
pack.burgs[burgId].state = s.i;
|
||||
moveBurgToGroup(burgId, "cities");
|
||||
moveBurgToGroup(burgId, "city");
|
||||
});
|
||||
|
||||
features.forEach(f => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue