mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: split states and burgs generators
This commit is contained in:
parent
e53c3a7773
commit
d7d79ad740
18 changed files with 445 additions and 358 deletions
|
|
@ -24,6 +24,7 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
|
||||
// add listeners
|
||||
byId("burgsOverviewRefresh").addEventListener("click", refreshBurgsEditor);
|
||||
byId("burgsGroupsEditorButton").addEventListener("click", openBurgGroupsEditor);
|
||||
byId("burgsChart").addEventListener("click", showBurgsChart);
|
||||
byId("burgsFilterState").addEventListener("change", burgsOverviewAddLines);
|
||||
byId("burgsFilterCulture").addEventListener("change", burgsOverviewAddLines);
|
||||
|
|
@ -302,6 +303,30 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
if (addNewBurg.classList.contains("pressed")) addNewBurg.classList.remove("pressed");
|
||||
}
|
||||
|
||||
function openBurgGroupsEditor() {
|
||||
$("#burgGroupsEditor").dialog({
|
||||
title: "Edit Burgs Groups",
|
||||
resizable: false,
|
||||
position: {my: "center", at: "center", of: "svg"},
|
||||
buttons: {
|
||||
Apply: applyMilitaryOptions,
|
||||
Restore: restoreDefaultUnits,
|
||||
Cancel: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},
|
||||
open: function () {
|
||||
const buttons = $(this).dialog("widget").find(".ui-dialog-buttonset > button");
|
||||
buttons[0].addEventListener("mousemove", () =>
|
||||
tip("Apply military units settings. <span style='color:#cb5858'>All forces will be recalculated!</span>")
|
||||
);
|
||||
buttons[1].addEventListener("mousemove", () => tip("Add new military unit to the table"));
|
||||
buttons[2].addEventListener("mousemove", () => tip("Restore default military units and settings"));
|
||||
buttons[3].addEventListener("mousemove", () => tip("Close the window without saving the changes"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showBurgsChart() {
|
||||
// build hierarchy tree
|
||||
const states = pack.states.map(s => {
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ function editDiplomacy() {
|
|||
}
|
||||
|
||||
function regenerateRelations() {
|
||||
BurgsAndStates.generateDiplomacy();
|
||||
States.generateDiplomacy();
|
||||
refreshDiplomacyEditor();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ function addBurg(point) {
|
|||
const feature = cells.f[cellId];
|
||||
|
||||
const population = Math.max(cells.s[cellId] / 3 + i / 1000 + (cellId % 100) / 1000, 0.1);
|
||||
const type = BurgsAndStates.getType(cellId, false);
|
||||
const type = Burgs.getType(cellId, false);
|
||||
|
||||
// generate emblem
|
||||
const coa = COA.generate(states[state].coa, 0.25, null, type);
|
||||
|
|
@ -186,7 +186,7 @@ function addBurg(point) {
|
|||
.attr("dy", `${townSize * -1.5}px`)
|
||||
.text(name);
|
||||
|
||||
BurgsAndStates.defineBurgFeatures(burg);
|
||||
Burgs.defineBurgFeatures(burg);
|
||||
|
||||
const newRoute = Routes.connect(cellId);
|
||||
if (newRoute && layerIsOn("toggleRoutes")) {
|
||||
|
|
|
|||
|
|
@ -243,13 +243,14 @@ function editHeightmap(options) {
|
|||
Cultures.generate();
|
||||
Cultures.expand();
|
||||
|
||||
BurgsAndStates.generate();
|
||||
Burgs.generate();
|
||||
States.generate();
|
||||
Routes.generate();
|
||||
Religions.generate();
|
||||
BurgsAndStates.defineStateForms();
|
||||
States.defineStateForms();
|
||||
Provinces.generate();
|
||||
Provinces.getPoles();
|
||||
BurgsAndStates.defineBurgFeatures();
|
||||
Burgs.specifyBurgs();
|
||||
|
||||
Rivers.specify();
|
||||
Features.specify();
|
||||
|
|
|
|||
|
|
@ -371,8 +371,8 @@ function editProvinces() {
|
|||
layerIsOn("toggleStates") ? drawStates() : toggleStates();
|
||||
layerIsOn("toggleBorders") ? drawBorders() : toggleBorders();
|
||||
|
||||
BurgsAndStates.collectStatistics();
|
||||
BurgsAndStates.defineStateForms(newStates);
|
||||
States.collectStatistics();
|
||||
States.defineStateForms(newStates);
|
||||
drawStateLabels(allStates);
|
||||
|
||||
// redraw emblems
|
||||
|
|
@ -1030,7 +1030,7 @@ function editProvinces() {
|
|||
// generate emblem
|
||||
const kinship = burg ? 0.8 : 0.4;
|
||||
const parent = burg ? pack.burgs[burg].coa : pack.states[state].coa;
|
||||
const type = BurgsAndStates.getType(center, parent.port);
|
||||
const type = Burgs.getType(center, parent.port);
|
||||
const coa = COA.generate(parent, kinship, P(0.1), type);
|
||||
coa.shield = COA.getShield(c, state);
|
||||
COArenderer.add("province", province, coa, point[0], point[1]);
|
||||
|
|
|
|||
|
|
@ -280,16 +280,6 @@ function addStylePreset() {
|
|||
"font-size",
|
||||
"font-family"
|
||||
],
|
||||
"#burgIcons > #cities": [
|
||||
"opacity",
|
||||
"fill",
|
||||
"fill-opacity",
|
||||
"size",
|
||||
"stroke",
|
||||
"stroke-width",
|
||||
"stroke-dasharray",
|
||||
"stroke-linecap"
|
||||
],
|
||||
"#anchors > #cities": ["opacity", "fill", "size", "stroke", "stroke-width"],
|
||||
"#burgLabels > #towns": [
|
||||
"opacity",
|
||||
|
|
@ -300,16 +290,6 @@ function addStylePreset() {
|
|||
"font-size",
|
||||
"font-family"
|
||||
],
|
||||
"#burgIcons > #towns": [
|
||||
"opacity",
|
||||
"fill",
|
||||
"fill-opacity",
|
||||
"size",
|
||||
"stroke",
|
||||
"stroke-width",
|
||||
"stroke-dasharray",
|
||||
"stroke-linecap"
|
||||
],
|
||||
"#anchors > #towns": ["opacity", "fill", "size", "stroke", "stroke-width"],
|
||||
"#labels > #states": [
|
||||
"opacity",
|
||||
|
|
@ -352,6 +332,20 @@ function addStylePreset() {
|
|||
]
|
||||
};
|
||||
|
||||
const burgIconsAttributes = [
|
||||
"opacity",
|
||||
"fill",
|
||||
"fill-opacity",
|
||||
"size",
|
||||
"stroke",
|
||||
"stroke-width",
|
||||
"stroke-dasharray",
|
||||
"stroke-linecap"
|
||||
];
|
||||
options.burgs.groups.forEach(group => {
|
||||
attributes[`#burgIcons > g[data-name='${group}']`] = burgIconsAttributes;
|
||||
});
|
||||
|
||||
for (const selector in attributes) {
|
||||
const el = document.querySelector(selector);
|
||||
if (!el) continue;
|
||||
|
|
|
|||
|
|
@ -154,14 +154,14 @@ function regenerateStates() {
|
|||
if (!newStates) return;
|
||||
|
||||
pack.states = newStates;
|
||||
BurgsAndStates.expandStates();
|
||||
BurgsAndStates.normalizeStates();
|
||||
BurgsAndStates.getPoles();
|
||||
BurgsAndStates.collectStatistics();
|
||||
BurgsAndStates.assignColors();
|
||||
BurgsAndStates.generateCampaigns();
|
||||
BurgsAndStates.generateDiplomacy();
|
||||
BurgsAndStates.defineStateForms();
|
||||
States.expandStates();
|
||||
States.normalizeStates();
|
||||
States.getPoles();
|
||||
States.collectStatistics();
|
||||
States.assignColors();
|
||||
States.generateCampaigns();
|
||||
States.generateDiplomacy();
|
||||
States.defineStateForms();
|
||||
Provinces.generate(true);
|
||||
Provinces.getPoles();
|
||||
|
||||
|
|
@ -443,8 +443,7 @@ function regenerateBurgs() {
|
|||
if (f.port) f.port = 0; // reset features ports counter
|
||||
});
|
||||
|
||||
BurgsAndStates.specifyBurgs();
|
||||
BurgsAndStates.defineBurgFeatures();
|
||||
Burgs.specifyBurgs();
|
||||
regenerateRoutes();
|
||||
|
||||
drawBurgIcons();
|
||||
|
|
@ -503,7 +502,7 @@ function regenerateEmblems() {
|
|||
const nameByBurg = province.burg && province.name.slice(0, 3) === parent.name.slice(0, 3);
|
||||
const kinship = dominion ? 0 : nameByBurg ? 0.8 : 0.4;
|
||||
const culture = pack.cells.culture[province.center];
|
||||
const type = BurgsAndStates.getType(province.center, parent.port);
|
||||
const type = Burgs.getType(province.center, parent.port);
|
||||
province.coa = COA.generate(parent.coa, kinship, dominion, type);
|
||||
province.coa.shield = COA.getShield(culture, province.state);
|
||||
});
|
||||
|
|
@ -521,10 +520,26 @@ function regenerateReligions() {
|
|||
function regenerateCultures() {
|
||||
Cultures.generate();
|
||||
Cultures.expand();
|
||||
BurgsAndStates.updateCultures();
|
||||
Religions.updateCultures();
|
||||
if (!layerIsOn("toggleCultures")) toggleCultures();
|
||||
else drawCultures();
|
||||
|
||||
// update culture for states
|
||||
pack.states = pack.states.map(state => {
|
||||
if (!state.i || state.removed) return state;
|
||||
return {...state, culture: pack.cells.culture[state.center]};
|
||||
});
|
||||
|
||||
// update culture for burgs
|
||||
pack.burgs = pack.burgs.map(burg => {
|
||||
if (!burg.i || burg.removed) return burg;
|
||||
return {...burg, culture: pack.cells.culture[burg.cell]};
|
||||
});
|
||||
|
||||
// update culture for religions
|
||||
pack.religions = pack.religions.map(religion => {
|
||||
if (!religion.i || religion.removed) return religion;
|
||||
return {...religion, culture: pack.cells.culture[religion.center]};
|
||||
});
|
||||
|
||||
layerIsOn("toggleCultures") ? drawCultures() : toggleCultures();
|
||||
refreshAllEditors();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue