mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor - define stateForms
This commit is contained in:
parent
2be3c68290
commit
cffb0a8ec3
10 changed files with 262 additions and 108 deletions
|
|
@ -2,7 +2,8 @@ import {TIME} from "config/logging";
|
|||
import {getColors} from "utils/colorUtils";
|
||||
import {NEUTRALS} from "./config";
|
||||
import {createAreaTiers, defineStateForm} from "./defineStateForm";
|
||||
import {defineFullStateName} from "./defineStateName";
|
||||
import {defineFullStateName, defineStateName} from "./defineStateName";
|
||||
import {isBurg} from "utils/typeUtils";
|
||||
|
||||
import type {TStateStatistics} from "./collectStatistics";
|
||||
import type {TStateData} from "./createStateData";
|
||||
|
|
@ -10,28 +11,35 @@ import type {TStateData} from "./createStateData";
|
|||
export function specifyStates(
|
||||
statesData: TStateData[],
|
||||
statistics: TStateStatistics,
|
||||
stateIds: Uint16Array,
|
||||
burgIds: Uint16Array
|
||||
cultures: TCultures,
|
||||
burgs: TBurgs
|
||||
): TStates {
|
||||
TIME && console.time("specifyState");
|
||||
TIME && console.time("specifyStates");
|
||||
|
||||
const colors = getColors(statesData.length);
|
||||
const getAreaTier = createAreaTiers(statistics);
|
||||
const getNameBase = (cultureId: number) => cultures[cultureId].base;
|
||||
|
||||
const states: IState[] = statesData.map((stateData, index) => {
|
||||
const {i, type, name} = stateData;
|
||||
const {area, ...stats} = statistics[i];
|
||||
const {i, center, type, culture, capital} = stateData;
|
||||
const {area, burgs: burgsNumber, ...stats} = statistics[i];
|
||||
|
||||
const capitalBurg = burgs[capital];
|
||||
const capitalName = isBurg(capitalBurg) ? capitalBurg.name : null;
|
||||
if (!capitalName) throw new Error("State capital is not a burg");
|
||||
|
||||
const nameBase = getNameBase(culture);
|
||||
const areaTier = getAreaTier(area);
|
||||
const {form, formName} = defineStateForm(type, areaTier);
|
||||
const fullName = defineFullStateName(name, form);
|
||||
const {form, formName} = defineStateForm(type, areaTier, nameBase, burgsNumber);
|
||||
const name = defineStateName(center, capitalName, nameBase, formName);
|
||||
const fullName = defineFullStateName(name, formName);
|
||||
|
||||
const color = colors[index];
|
||||
|
||||
const state: IState = {...stateData, form, formName, fullName, color, area, ...stats};
|
||||
const state: IState = {name, ...stateData, form, formName, fullName, color, area, burgs: burgsNumber, ...stats};
|
||||
return state;
|
||||
});
|
||||
|
||||
TIME && console.timeEnd("specifyState");
|
||||
TIME && console.timeEnd("specifyStates");
|
||||
return [NEUTRALS, ...states];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue