refactor: interfaces

This commit is contained in:
Azgaar 2022-07-10 03:01:46 +03:00
parent ff97c9227d
commit 3184a29449
6 changed files with 60 additions and 28 deletions

View file

@ -6,7 +6,8 @@ interface Dict<T> {
[key: string]: T;
}
type IntArray = Uint8Array | Uint16Array | Uint32Array;
type UintArray = Uint8Array | Uint16Array | Uint32Array;
type IntArray = Int8Array | Int16Array | Int32Array;
type RGB = `rgb(${number}, ${number}, ${number})`;
type Hex = `#${string}`;

18
src/types/grid.d.ts vendored
View file

@ -8,19 +8,19 @@ interface IGrid {
c: number[][];
};
cells: {
i: IntArray;
b: IntArray;
i: UintArray;
b: UintArray;
c: number[][];
v: number[][];
h: IntArray;
t: IntArray;
f: IntArray;
temp: IntArray;
prec: IntArray;
h: UintArray;
t: UintArray;
f: UintArray;
temp: UintArray;
prec: UintArray;
};
features: IFeature[];
features: IGridFeature[];
}
interface IFeature {
interface IGridFeature {
i: number;
land: boolean;
border: boolean;

56
src/types/pack.d.ts vendored
View file

@ -4,24 +4,26 @@ interface IPack {
v: number[][];
c: number[][];
};
features: IFeature[];
features: TPackFeature[];
cells: {
i: IntArray;
i: UintArray;
p: TPoints;
v: number[][];
c: number[][];
g: IntArray;
h: IntArray;
t: IntArray;
f: IntArray;
biome: IntArray;
g: UintArray;
h: UintArray;
t: UintArray;
f: UintArray;
s: IntArray;
pop: Float32Array;
area: IntArray;
state: IntArray;
culture: IntArray;
religion: IntArray;
province: IntArray;
burg: IntArray;
fl: UintArray;
biome: UintArray;
area: UintArray;
state: UintArray;
culture: UintArray;
religion: UintArray;
province: UintArray;
burg: UintArray;
q: d3.Quadtree<number[]>;
};
states: IState[];
@ -32,11 +34,35 @@ interface IPack {
religions: IReligion[];
}
interface IFeature {
i: number;
interface IPackFeatureBase {
i: number; // feature id starting from 1
border: boolean; // if touches map border
cells: number; // number of cells
firstCell: number; // index of the top left cell
vertices: number[]; // indexes of perimetric vertices
}
interface IPackFeatureOcean extends IPackFeatureBase {
land: false;
type: "ocean";
group: "ocean";
}
interface IPackFeatureIsland extends IPackFeatureBase {
land: true;
type: "island";
group: "continent" | "island" | "isle" | "lake_island";
}
interface IPackFeatureLake extends IPackFeatureBase {
land: false;
type: "lake";
group: "freshwater" | "salt" | "frozen" | "dry" | "sinkhole" | "lava";
name: string;
}
type TPackFeature = IPackFeatureOcean | IPackFeatureIsland | IPackFeatureLake;
interface IState {
i: number;
name: string;