mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: add poles to state data
This commit is contained in:
parent
b2ab699843
commit
ff5ef1ca4b
3 changed files with 15 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import {WARN} from "config/logging";
|
import {WARN} from "config/logging";
|
||||||
|
import {getPolesOfInaccessibility} from "scripts/getPolesOfInaccessibility";
|
||||||
import {pick} from "utils/functionUtils";
|
import {pick} from "utils/functionUtils";
|
||||||
import {getInputNumber} from "utils/nodeUtils";
|
import {getInputNumber} from "utils/nodeUtils";
|
||||||
import {collectStatistics} from "./collectStatistics";
|
import {collectStatistics} from "./collectStatistics";
|
||||||
|
|
@ -70,7 +71,13 @@ export function generateBurgsAndStates(
|
||||||
|
|
||||||
const statistics = collectStatistics({...cells, state: stateIds, burg: burgIds}, burgs);
|
const statistics = collectStatistics({...cells, state: stateIds, burg: burgIds}, burgs);
|
||||||
const diplomacy = generateRelations(statesData, statistics, pick(cells, "f"));
|
const diplomacy = generateRelations(statesData, statistics, pick(cells, "f"));
|
||||||
const {states, conflicts} = specifyStates(statesData, statistics, diplomacy, cultures, burgs);
|
const poles = getPolesOfInaccessibility({
|
||||||
|
vertices,
|
||||||
|
getType: (cellId: number) => stateIds[cellId],
|
||||||
|
cellNeighbors: cells.c,
|
||||||
|
cellVertices: cells.v
|
||||||
|
});
|
||||||
|
const {states, conflicts} = specifyStates(statesData, statistics, diplomacy, poles, cultures, burgs);
|
||||||
|
|
||||||
return {burgIds, stateIds, burgs, states, conflicts};
|
return {burgIds, stateIds, burgs, states, conflicts};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export function specifyStates(
|
||||||
statesData: TStateData[],
|
statesData: TStateData[],
|
||||||
statistics: TStateStatistics,
|
statistics: TStateStatistics,
|
||||||
diplomacy: TDiplomacy,
|
diplomacy: TDiplomacy,
|
||||||
|
poles: Dict<TPoint>,
|
||||||
cultures: TCultures,
|
cultures: TCultures,
|
||||||
burgs: TBurgs
|
burgs: TBurgs
|
||||||
): {states: TStates; conflicts: IConflict[]} {
|
): {states: TStates; conflicts: IConflict[]} {
|
||||||
|
|
@ -41,6 +42,8 @@ export function specifyStates(
|
||||||
const name = defineStateName(center, capitalName, nameBase, formName);
|
const name = defineStateName(center, capitalName, nameBase, formName);
|
||||||
const fullName = defineFullStateName(name, formName);
|
const fullName = defineFullStateName(name, formName);
|
||||||
|
|
||||||
|
const pole = poles[i];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
...stateData,
|
...stateData,
|
||||||
|
|
@ -52,7 +55,8 @@ export function specifyStates(
|
||||||
burgs: burgsNumber,
|
burgs: burgsNumber,
|
||||||
...stats,
|
...stats,
|
||||||
neighbors,
|
neighbors,
|
||||||
relations
|
relations,
|
||||||
|
pole
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import polylabel from "polylabel";
|
||||||
|
|
||||||
import {TIME} from "config/logging";
|
import {TIME} from "config/logging";
|
||||||
import {connectVertices} from "./connectVertices";
|
import {connectVertices} from "./connectVertices";
|
||||||
|
import {rn} from "utils/numberUtils";
|
||||||
|
|
||||||
interface IGetPolesProps {
|
interface IGetPolesProps {
|
||||||
vertices: IGraphVertices;
|
vertices: IGraphVertices;
|
||||||
|
|
@ -17,7 +18,7 @@ export function getPolesOfInaccessibility(props: IGetPolesProps) {
|
||||||
const poles: Dict<TPoint> = Object.fromEntries(
|
const poles: Dict<TPoint> = Object.fromEntries(
|
||||||
Object.entries(multiPolygons).map(([id, multiPolygon]) => {
|
Object.entries(multiPolygons).map(([id, multiPolygon]) => {
|
||||||
const [x, y] = polylabel(multiPolygon, 20);
|
const [x, y] = polylabel(multiPolygon, 20);
|
||||||
return [id, [x, y]];
|
return [id, [rn(x), rn(y)]];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue