-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtypes.ts
190 lines (171 loc) · 4.82 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// TileMap
//
// Interface for the constructor options
interface TileMapOptions {
x?: number;
y?: number;
width?: number;
height?: number;
depth?: number;
tileWidth?: number;
tileHeight?: number;
}
// TileMap class definition
declare class TileMap {
x: number;
y: number;
width: number;
height: number;
depth: number;
tileWidth: number;
tileHeight: number;
data: number[][] | number[];
defaultRogueLike: string[];
constructor(options?: TileMapOptions);
initializeDataArray(): number[][] | number[];
fill(value: number): void;
fill2D(value: number): void;
fill3D(value: number, z: number): void;
random(max: number): number;
seed(value: number): void;
seedRandom(): void;
use(subMap: TileMap, offsetX: number, offsetY: number): void;
scaleToTileRange(tileSetRange: number): void;
mask(format?: string[]): string[];
applyBiome(biome: Biome): void; // Define the 'biome' type more precisely if possible
getTileAt(x: number, y: number, z?: number): number;
toJSON(): string;
toTiledJSON(): any; // Define the return type more precisely if possible
query(options: { x?: number; y?: number; width?: number; height?: number; z?: number; tileName?: string }): TileMap;
query3D(options: { x?: number; y?: number; z?: number; width?: number; height?: number; depth?: number; tileName?: string }): any[]; // Define the return type more precisely if possible
findTilesById(tileId: number): Array<{ x: number; y: number; z?: number }>;
getTileIdByName(tileName: string): number;
}
//
// TileSet
//
// Interface for Tile objects
interface Tile {
id: number;
name: string;
}
// Interface for the constructor options
interface TileSetOptions {
tiles?: Tile[];
}
// TileSet class definition
declare class TileSet {
tiles: Tile[];
constructor(options?: TileSetOptions);
addTile(tile: Tile): void;
getTile(id: number): Tile | undefined;
getTileByName(name: string): Tile | undefined;
}
//
// LSystem
//
// Interface for the constructor options of LSystem
interface LSystemOptions {
tileset: TileSet;
axiom: string;
rules: { [tileName: string]: string | ((context: RuleContext) => string) };
generations: number;
}
// Interface for the context object passed to rule functions
interface RuleContext {
tileId: number;
tileName: string;
getTileId: (tileName: string) => number | null;
random: (max: number, min?: number) => number;
tileMap: {
width: number;
height: number;
depth: number;
};
getNeighbors: (x: number, y: number) => (number | undefined)[];
position: {
x: number;
y: number;
z: number;
};
}
// LSystem class definition
declare class LSystem {
tileset: TileSet;
axiom: string;
rules: { [tileName: string]: string | ((context: RuleContext) => string) };
generations: number;
constructor(options: LSystemOptions);
getTileId(tileName: string): number | null;
applyRule(tileId: number, tileMap: TileMap): number;
applyTo(tileMap: TileMap): void;
}
//
// Biome
//
// Interface for the constructor options of Biome
interface BiomeOptions {
name: string;
tileset: TileSet;
distribution?: { [tileId: number]: number }; // Assuming tile ID is a number and weight is also a number
}
// Biome class definition
declare class Biome {
name: string;
tileset: TileSet;
distribution: { [tileId: number]: number };
constructor(options: BiomeOptions);
setDistribution(distribution: { [tileId: number]: number }): void;
}
//
// labyrinthos
//
// Define a generic type for maze generation functions
export type MazeGeneratorFunction = (tileMap: TileMap, options: any) => void; // Replace 'any' with a more specific type if you have a shared options structure
interface mazes {
AldousBroder: MazeGeneratorFunction;
AldousBroder3D: MazeGeneratorFunction;
BinaryTree: MazeGeneratorFunction;
CellularAutomata: MazeGeneratorFunction;
EllersAlgorithm: MazeGeneratorFunction;
GrowingTree: MazeGeneratorFunction;
RecursiveBacktrack: MazeGeneratorFunction;
RecursiveDivision: MazeGeneratorFunction;
ThomasHunter: MazeGeneratorFunction;
BeattieSchoberth: MazeGeneratorFunction;
Metroidvania: MazeGeneratorFunction;
// Add other mazes here following the same pattern
}
interface shapes {
// Define shape generators here if they have a similar signature
Circle: MazeGeneratorFunction;
Square: MazeGeneratorFunction;
Triangle: MazeGeneratorFunction;
}
interface terrains {
FaultLine: MazeGeneratorFunction;
PerlinNoise: MazeGeneratorFunction;
// Define additional terrain generators here if they have a similar signature
}
interface utils {
// Define utility functions here
}
interface labyrinthos {
TileMap: typeof TileMap;
TileSet: typeof TileSet;
Biome: typeof Biome;
LSystem: typeof LSystem;
mazes: mazes;
shapes: shapes;
terrains: terrains;
utils: utils;
}
export {
TileMap,
TileSet,
Biome,
LSystem,
mazes,
labyrinthos
}