refactor: specify burgs fixes

This commit is contained in:
max 2022-08-07 00:31:59 +03:00
parent 7f57c9af65
commit 8c741a559e
6 changed files with 34 additions and 19 deletions

View file

@ -1044,10 +1044,9 @@ window.COA = (function () {
const shapeGroup = emblemShape.selectedOptions[0]?.parentNode.label || "Diversiform"; const shapeGroup = emblemShape.selectedOptions[0]?.parentNode.label || "Diversiform";
if (shapeGroup !== "Diversiform") return emblemShape.value; if (shapeGroup !== "Diversiform") return emblemShape.value;
if (emblemShape.value === "state" && stateShield) return stateShield; if (emblemShape.value === "state" && stateShield) return stateShield;
if (cultureShield) return cultureShield;
if (cultureShield) cultureShield;
ERROR && console.error("Shield shape is not defined on culture level"); ERROR && console.error("Shield shape is not defined on culture level");
return "heater"; return "heater";
}; };

View file

@ -28,7 +28,7 @@ export function createStates(capitals: TCapitals, cultures: TCultures) {
const shield = COA.getShield(cultureShield, null); const shield = COA.getShield(cultureShield, null);
const coa: ICoa = {...COA.generate(null, null, null, type), shield}; const coa: ICoa = {...COA.generate(null, null, null, type), shield};
return {i: id, center: cellId, type, name, color, expansionism, capital: capitalId, culture: cultureId, coa}; return {i: id, name, type, center: cellId, color, expansionism, capital: capitalId, culture: cultureId, coa};
}); });
TIME && console.timeEnd("createStates"); TIME && console.timeEnd("createStates");

View file

@ -12,6 +12,7 @@ export function generateBurgsAndStates(
cultures: TCultures, cultures: TCultures,
features: TPackFeatures, features: TPackFeatures,
temp: Int8Array, temp: Int8Array,
rivers: Omit<IRiver, "name" | "basin" | "type">[],
vertices: IGraphVertices, vertices: IGraphVertices,
cells: Pick< cells: Pick<
IPack["cells"], IPack["cells"],
@ -55,6 +56,7 @@ export function generateBurgsAndStates(
vertices, vertices,
cultures, cultures,
states, states,
rivers,
pick(cells, "v", "p", "g", "h", "f", "haven", "harbor", "s", "biome", "fl", "r") pick(cells, "v", "p", "g", "h", "f", "haven", "harbor", "s", "biome", "fl", "r")
); );

View file

@ -25,6 +25,7 @@ export function specifyBurgs(
vertices: IGraphVertices, vertices: IGraphVertices,
cultures: TCultures, cultures: TCultures,
states: TStatesReturn, states: TStatesReturn,
rivers: Omit<IRiver, "name" | "basin" | "type">[],
cells: Pick<IPack["cells"], "v" | "p" | "g" | "h" | "f" | "haven" | "harbor" | "s" | "biome" | "fl" | "r"> cells: Pick<IPack["cells"], "v" | "p" | "g" | "h" | "f" | "haven" | "harbor" | "s" | "biome" | "fl" | "r">
): TBurgs { ): TBurgs {
TIME && console.time("specifyBurgs"); TIME && console.time("specifyBurgs");
@ -102,7 +103,11 @@ export function specifyBurgs(
if (haven && (waterBody as TPackFeature).type === "lake") return "Lake"; if (haven && (waterBody as TPackFeature).type === "lake") return "Lake";
if (cells.h[cellId] > ELEVATION.FOOTHILLS) return "Highland"; if (cells.h[cellId] > ELEVATION.FOOTHILLS) return "Highland";
if (cells.r[cellId] && rivers[cellId].length > 100) return "River";
if (cells.r[cellId]) {
const river = rivers.find(river => river.i === cellId);
if (river && river.length > 100) return "River";
}
if (population < 6) { if (population < 6) {
const biome = cells.biome[cellId]; const biome = cells.biome[cellId];

View file

@ -58,10 +58,10 @@ export const mergeLakeData = function (
const lake = lakeData.find(lake => lake.i === feature.i); const lake = lakeData.find(lake => lake.i === feature.i);
if (!lake) return feature; if (!lake) return feature;
const {firstCell, height, flux, temp, evaporation} = lake; const {firstCell, height, flux, temp, evaporation, cells} = lake;
const inlets = lake.inlets?.filter(inlet => rivers.find(river => river.i === inlet)); const inlets = lake.inlets?.filter(inlet => rivers.find(river => river.i === inlet));
const outlet = rivers.find(river => river.i === lake.outlet)?.i; const outlet = rivers.find(river => river.i === lake.outlet)?.i;
const group = defineLakeGroup({firstCell, height, flux, temp, evaporation, inlets, outlet}); const group = defineLakeGroup({firstCell, height, flux, temp, evaporation, cells, inlets, outlet});
const lakeFeature: IPackFeatureLake = {...feature, flux, temp, evaporation, inlets, outlet, group}; const lakeFeature: IPackFeatureLake = {...feature, flux, temp, evaporation, inlets, outlet, group};
if (!inlets || !inlets.length) delete lakeFeature.inlets; if (!inlets || !inlets.length) delete lakeFeature.inlets;
@ -79,6 +79,7 @@ function defineLakeGroup({
flux, flux,
temp, temp,
evaporation, evaporation,
cells,
inlets, inlets,
outlet outlet
}: { }: {
@ -87,6 +88,7 @@ function defineLakeGroup({
flux: number; flux: number;
temp: number; temp: number;
evaporation: number; evaporation: number;
cells: number;
inlets?: number[]; inlets?: number[];
outlet?: number; outlet?: number;
}): IPackFeatureLake["group"] { }): IPackFeatureLake["group"] {

View file

@ -95,19 +95,26 @@ export function createPack(grid: IGrid): IPack {
pop: population pop: population
}); });
const {burgIds, stateIds, burgs, states} = generateBurgsAndStates(cultures, mergedFeatures, temp, vertices, { const {burgIds, stateIds, burgs, states} = generateBurgsAndStates(
...pick(cells, "v", "c", "p", "i", "g"), cultures,
h: heights, mergedFeatures,
f: featureIds, temp,
t: distanceField, rawRivers,
haven, vertices,
harbor, {
r: riverIds, ...pick(cells, "v", "c", "p", "i", "g"),
fl: flux, h: heights,
biome, f: featureIds,
s: suitability, t: distanceField,
culture: cultureIds haven,
}); harbor,
r: riverIds,
fl: flux,
biome,
s: suitability,
culture: cultureIds
}
);
// Religions.generate(); // Religions.generate();
// BurgsAndStates.defineStateForms(); // BurgsAndStates.defineStateForms();