UNPKG

@real_one_chess_king/game-logic

Version:
26 lines 636 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Timer = void 0; class Timer { timeLeft; onTimeEnd; constructor(timeLeft, //MS onTimeEnd) { this.timeLeft = timeLeft; this.onTimeEnd = onTimeEnd; } lastTimestamp = 0; timeout; start() { this.lastTimestamp = Date.now(); this.timeout = setTimeout(() => { this.onTimeEnd(); }, this.timeLeft); } pause() { clearTimeout(this.timeout); this.timeLeft -= Date.now() - this.lastTimestamp; } } exports.Timer = Timer; //# sourceMappingURL=timer.js.map