2016-08-15 21:37:36 -04:00
|
|
|
var Timer = require('../util/timer');
|
|
|
|
|
2016-10-17 23:23:16 -04:00
|
|
|
function Clock (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-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;
|
|
|
|
var dt = this._projectTimer.timeElapsed() - this._pausedTime;
|
|
|
|
this._projectTimer.startTime += dt;
|
|
|
|
};
|
|
|
|
|
2016-08-15 21:37:36 -04:00
|
|
|
Clock.prototype.resetProjectTimer = function () {
|
|
|
|
this._projectTimer.start();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Clock;
|