Make overlay

This commit is contained in:
0xa663
2024-02-15 19:27:26 +01:00
parent 179fdc8f4d
commit cc2aa552ba
34 changed files with 11168 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
export class Array2D<V = any> {
public array:V[] = [];
constructor(defaultValue: V, private width: number, height: number) {
this.array = new Array(width * height);
this.array.fill(defaultValue);
}
at(x: number, y: number){
return y * this.width + x;
}
set(x: number, y: number, value: V) {
this.array[this.at(x, y)] = value;
}
get(x: number, y: number) {
return this.array[this.at(x, y)];
}
static from<V>(array: V[][], width: number, height: number) {
const arr = new Array2D(array[0][0]!, width, height);
for (let y = 0; y < array.length; y++) {
for (let x = 0; x < array[y].length; x++) {
arr.set(x, y, array[y][x]!);
}
}
return arr;
}
}