advent22/ui/src/lib/door.ts

27 lines
486 B
TypeScript
Raw Normal View History

2023-09-07 02:08:56 +00:00
import { Rectangle } from "./rectangle";
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;
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
}
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 01:17:14 +00:00
}