refactor(package): use generics to type point args

This commit is contained in:
Luke
2023-02-20 17:25:12 +01:00
parent 7ff9f93838
commit 7520509da3

View File

@@ -6,32 +6,35 @@ let nearbyCount: number = 0;
let closestPoint: Point | undefined; let closestPoint: Point | undefined;
let tick: number | undefined; let tick: number | undefined;
interface LibPoint { interface LibPoint<T = unknown> {
coords: number[]; coords: number[];
distance: number; distance: number;
onEnter?: () => void; onEnter?: () => void;
onExit?: () => void; onExit?: () => void;
nearby?: () => void; nearby?: () => void;
args?: T;
} }
export class Point { export class Point<T = unknown> {
id: number = 0; id: number = 0;
coords: Vector3; coords: Vector3;
distance: number = 0; distance: number = 0;
onEnter?: () => void; onEnter?: () => void;
onExit?: () => void; onExit?: () => void;
nearby?: () => void; nearby?: () => void;
args?: T;
inside: boolean = false; inside: boolean = false;
currentDistance?: number; currentDistance?: number;
isClosest: boolean = false; isClosest: boolean = false;
constructor(point: LibPoint) { constructor(point: LibPoint<T>) {
this.id = points.length + 1; this.id = points.length + 1;
this.coords = Vector3.fromArray(point.coords); this.coords = Vector3.fromArray(point.coords);
this.distance = point.distance; this.distance = point.distance;
this.onEnter = point.onEnter; this.onEnter = point.onEnter;
this.onExit = point.onExit; this.onExit = point.onExit;
this.nearby = point.nearby; this.nearby = point.nearby;
this.args = point.args;
points.push(this); points.push(this);
} }