mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 10:31:24 +01:00
refactor: generate states cleanup
This commit is contained in:
parent
c2fc0679ad
commit
ff974a4fd0
16 changed files with 98 additions and 64 deletions
|
|
@ -14,22 +14,17 @@ export function createStates(capitals: TCapitals, cultures: TCultures) {
|
|||
TIME && console.time("createStates");
|
||||
|
||||
const colors = getColors(capitals.length);
|
||||
const each5th = each(5); // select each 5th element
|
||||
const powerInput = getInputNumber("powerInput");
|
||||
|
||||
const states = capitals.map((capital, index) => {
|
||||
const {cell: cellId, culture: cultureId, name: capitalName, i: capitalId} = capital;
|
||||
const id = index + 1;
|
||||
|
||||
const useCapitalName = capitalName.length < 9 && each5th(cellId);
|
||||
const basename = useCapitalName ? capitalName : Names.getCultureShort(cultureId);
|
||||
const name: string = Names.getState(basename, cultureId);
|
||||
const name = getStateName(cellId, capitalName, cultureId, cultures);
|
||||
const color = colors[index];
|
||||
|
||||
const type = (cultures[cultureId] as ICulture).type;
|
||||
const expansionism = rn(Math.random() * powerInput + 1, 1);
|
||||
|
||||
const shield = COA.getShield(cultureId, null);
|
||||
const shield = COA.getShield(cultureId, null, cultures);
|
||||
const coa = {...COA.generate(null, null, null, type), shield};
|
||||
|
||||
return {i: id, center: cellId, type, name, color, expansionism, capital: capitalId, culture: cultureId, coa};
|
||||
|
|
@ -38,3 +33,11 @@ export function createStates(capitals: TCapitals, cultures: TCultures) {
|
|||
TIME && console.timeEnd("createStates");
|
||||
return [NEUTRALS, ...states];
|
||||
}
|
||||
|
||||
function getStateName(cellId: number, capitalName: string, cultureId: number, cultures: TCultures) {
|
||||
const useCapitalName = capitalName.length < 9 && each(5)(cellId);
|
||||
const nameBase = cultures[cultureId].base;
|
||||
const basename: string = useCapitalName ? capitalName : Names.getBaseShort(nameBase);
|
||||
|
||||
return Names.getState(basename, basename);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue