2017-04-17 15:10:04 -04:00
|
|
|
const Timer = require('../util/timer');
|
2016-08-15 21:37:36 -04:00
|
|
|
|
2017-04-17 15:10:04 -04:00
|
|
|
const Clock = function (runtime) {
|
2016-08-15 21:37:36 -04:00
|
|
|
this._projectTimer = new Timer();
|
|
|
|
this._projectTimer.start();
|
2016-10-17 23:23:16 -04:00
|
|
|
this._pausedTime = null;
|
|
|
|
this._paused = false;
|
|
|
|
/**
|
|
|
|
* Reference to the owning Runtime.
|
|
|
|
* @type{!Runtime}
|
|
|
|
*/
|
|
|
|
this.runtime = runtime;
|
2016-10-23 17:55:31 -04:00
|
|
|
};
|
2016-08-15 21:37:36 -04:00
|
|
|
|
|
|
|
Clock.prototype.projectTimer = function () {
|
2016-10-17 23:23:16 -04:00
|
|
|
if (this._paused) {
|
|
|
|
return this._pausedTime / 1000;
|
|
|
|
}
|
2016-08-15 21:37:36 -04:00
|
|
|
return this._projectTimer.timeElapsed() / 1000;
|
|
|
|
};
|
|
|
|
|
2016-10-17 23:23:16 -04:00
|
|
|
Clock.prototype.pause = function () {
|
|
|
|
this._paused = true;
|
|
|
|
this._pausedTime = this._projectTimer.timeElapsed();
|
|
|
|
};
|
|
|
|
|
|
|
|
Clock.prototype.resume = function () {
|
|
|
|
this._paused = false;
|
2017-04-17 15:10:04 -04:00
|
|
|
const dt = this._projectTimer.timeElapsed() - this._pausedTime;
|
2016-10-17 23:23:16 -04:00
|
|
|
this._projectTimer.startTime += dt;
|
|
|
|
};
|
|
|
|
|
2016-08-15 21:37:36 -04:00
|
|
|
Clock.prototype.resetProjectTimer = function () {
|
|
|
|
this._projectTimer.start();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Clock;
|