Source: Game_Timer.js

Game_Timer.js

//-----------------------------------------------------------------------------
// Game_Timer
//
// The game object class for the timer.
/**
 * The game object class for the timer.
 *
 * @class
 */
function Game_Timer() {
    this.initialize(...arguments);
}

/**
 * Initialize the timer
 */
Game_Timer.prototype.initialize = function() {
    this._frames = 0;
    this._working = false;
};

/**
 * Update the timer
 *
 * @param {boolean} sceneActive - If the scene is active
 */
Game_Timer.prototype.update = function(sceneActive) {
    if (sceneActive && this._working && this._frames > 0) {
        this._frames--;
        if (this._frames === 0) {
            this.onExpire();
        }
    }
};

/**
 * Start the timer
 *
 * @param {number} count - The frame count of the timer
 */
Game_Timer.prototype.start = function(count) {
    this._frames = count;
    this._working = true;
};

/**
 * Stop the timer
 */
Game_Timer.prototype.stop = function() {
    this._working = false;
};

/**
 * Check if the timer is currently working
 *
 * @return {boolean} True if working
 */
Game_Timer.prototype.isWorking = function() {
    return this._working;
};

/**
 * Get the timer seconds amount
 *
 * @return {number} Amount of seconds in the timer
 */
Game_Timer.prototype.seconds = function() {
    return Math.floor(this._frames / 60);
};

/**
 * Get the timer frames amount
 *
 * @return {number} Amount of frames in the timer
 * @since Version 1.4.0
 */
Game_Timer.prototype.frames = function() {
    return this._frames;
};

/**
 * Processing when the timer expires
 */
Game_Timer.prototype.onExpire = function() {
    BattleManager.abort();
};