2024-05-27 02:19:31 -07:00
|
|
|
export enum TimerType {
|
|
|
|
countDown,
|
|
|
|
CountUp,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Timer {
|
|
|
|
private _timer: number = 0;
|
|
|
|
private _paused: boolean = true;
|
|
|
|
private _type: TimerType;
|
|
|
|
|
|
|
|
constructor(type: TimerType) {
|
|
|
|
this._type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get time() {
|
|
|
|
return this._timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get timeRound() {
|
|
|
|
return Math.round(this._timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public set time(value: number) {
|
|
|
|
this._timer = value;
|
|
|
|
}
|
|
|
|
|
2024-06-09 05:12:08 -07:00
|
|
|
public update(dt: number): void {
|
2024-05-27 02:19:31 -07:00
|
|
|
if (this._paused) return;
|
|
|
|
if (this._type == TimerType.CountUp) {
|
2024-06-09 05:12:08 -07:00
|
|
|
this._timer += dt;
|
2024-05-27 02:19:31 -07:00
|
|
|
} else {
|
2024-06-09 05:12:08 -07:00
|
|
|
this._timer -= dt;
|
2024-05-27 02:19:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public startCount() {
|
|
|
|
this._paused = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public stopCount() {
|
|
|
|
this._paused = true;
|
|
|
|
}
|
|
|
|
}
|