2023-09-07 02:08:56 +00:00
|
|
|
import { Rectangle } from "./rectangle";
|
2023-09-07 03:30:21 +00:00
|
|
|
import { Vector2D } from "./vector2d";
|
|
|
|
|
|
|
|
export interface DoorSerialized {
|
|
|
|
day: number;
|
|
|
|
x1: number;
|
|
|
|
y1: number;
|
|
|
|
x2: number;
|
|
|
|
y2: number;
|
|
|
|
}
|
2023-02-01 16:53:24 +00:00
|
|
|
|
2023-02-02 18:06:55 +00:00
|
|
|
export class Door {
|
|
|
|
private _day = -1;
|
|
|
|
public position: Rectangle;
|
|
|
|
|
2023-09-07 03:29:53 +00:00
|
|
|
constructor(position: Rectangle);
|
|
|
|
constructor(position: Rectangle, day: number);
|
2023-02-02 18:06:55 +00:00
|
|
|
constructor(position: Rectangle, day = -1) {
|
|
|
|
this.day = day;
|
|
|
|
this.position = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get day(): number {
|
2023-09-07 01:17:14 +00:00
|
|
|
return this._day;
|
2023-02-02 18:06:55 +00:00
|
|
|
}
|
|
|
|
|
2023-09-07 00:34:42 +00:00
|
|
|
public set day(day: unknown) {
|
|
|
|
// integer coercion
|
|
|
|
const result = Number(day);
|
|
|
|
|
|
|
|
if (isNaN(result)) {
|
|
|
|
this._day = -1;
|
|
|
|
} else {
|
|
|
|
this._day = Math.max(Math.floor(result), -1);
|
|
|
|
}
|
2023-02-02 18:06:55 +00:00
|
|
|
}
|
2023-09-07 03:30:21 +00:00
|
|
|
|
|
|
|
public static deserialize(serialized: DoorSerialized): Door {
|
|
|
|
return new Door(
|
|
|
|
new Rectangle(
|
|
|
|
new Vector2D(serialized.x1, serialized.y1),
|
|
|
|
new Vector2D(serialized.x2, serialized.y2),
|
|
|
|
),
|
|
|
|
serialized.day,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get serialized(): DoorSerialized {
|
|
|
|
return {
|
|
|
|
day: this.day,
|
|
|
|
x1: this.position.origin.x,
|
|
|
|
y1: this.position.origin.y,
|
|
|
|
x2: this.position.corner.x,
|
|
|
|
y2: this.position.corner.y,
|
|
|
|
};
|
|
|
|
}
|
2023-09-07 01:17:14 +00:00
|
|
|
}
|