Source: Game_System.js

Game_System.js

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

/**
 * Initialize the game system
 */
Game_System.prototype.initialize = function() {
    this._saveEnabled = true;
    this._menuEnabled = true;
    this._encounterEnabled = true;
    this._formationEnabled = true;
    this._battleCount = 0;
    this._winCount = 0;
    this._escapeCount = 0;
    this._saveCount = 0;
    this._versionId = 0;
    this._savefileId = 0;
    this._framesOnSave = 0;
    this._bgmOnSave = null;
    this._bgsOnSave = null;
    this._windowTone = null;
    this._battleBgm = null;
    this._victoryMe = null;
    this._defeatMe = null;
    this._savedBgm = null;
    this._walkingBgm = null;
};

/**
 * Check if the locale is Japanese
 *
 * @return {boolean} True if Japanese
 */
Game_System.prototype.isJapanese = function() {
    return $dataSystem.locale.match(/^ja/);
};

/**
 * Check if the locale is Chinese
 *
 * @return {boolean} True if Chinese
 */
Game_System.prototype.isChinese = function() {
    return $dataSystem.locale.match(/^zh/);
};

/**
 * Check if the locale is Korean
 *
 * @return {boolean} True if Korean
 */
Game_System.prototype.isKorean = function() {
    return $dataSystem.locale.match(/^ko/);
};

/**
 * Check if the locale is Chinese/Japanese/Korean
 *
 * @return {boolean} True if Chinese/Japanese/Korean
 */
Game_System.prototype.isCJK = function() {
    return $dataSystem.locale.match(/^(ja|zh|ko)/);
};

/**
 * Check if the locale is Russian
 *
 * @return {boolean} True if Russian
 */
Game_System.prototype.isRussian = function() {
    return $dataSystem.locale.match(/^ru/);
};

/**
 * Check if the game is side view battle system
 *
 * @return {boolean} True if side view
 */
Game_System.prototype.isSideView = function() {
    return $dataSystem.optSideView;
};

/**
 * Check if the game has autosave enabled
 *
 * @return {boolean} True if autosave enabled
 */
Game_System.prototype.isAutosaveEnabled = function() {
    return $dataSystem.optAutosave;
};

/**
 * Check if the game has message skip enabled
 * @since 1.8.1
 *
 * @return {boolean} True if message skip enabled
 */
Game_System.prototype.isMessageSkipEnabled = function() {
    return $dataSystem.optMessageSkip;
};

/**
 * Check if the game has save enabled
 *
 * @return {boolean} True if save enabled
 */
Game_System.prototype.isSaveEnabled = function() {
    return this._saveEnabled;
};

/**
 * Disables saving
 */
Game_System.prototype.disableSave = function() {
    this._saveEnabled = false;
};

/**
 * Enables saving
 */
Game_System.prototype.enableSave = function() {
    this._saveEnabled = true;
};

/**
 * Check if the game has its menu enabled
 *
 * @return {boolean} True if menu enabled
 */
Game_System.prototype.isMenuEnabled = function() {
    return this._menuEnabled;
};

/**
 * Disables the menu
 */
Game_System.prototype.disableMenu = function() {
    this._menuEnabled = false;
};

/**
 * Enables the menu
 */
Game_System.prototype.enableMenu = function() {
    this._menuEnabled = true;
};

/**
 * Check if encounters are enabled
 *
 * @return {boolean} True if encounters are enabled
 */
Game_System.prototype.isEncounterEnabled = function() {
    return this._encounterEnabled;
};

/**
 * Disables encounters
 */
Game_System.prototype.disableEncounter = function() {
    this._encounterEnabled = false;
};

/**
 * Enables encounters
 */
Game_System.prototype.enableEncounter = function() {
    this._encounterEnabled = true;
};

/**
 * Check if the formation command is enabled
 *
 * @return {boolean} True if the formation command is enabled
 */
Game_System.prototype.isFormationEnabled = function() {
    return this._formationEnabled;
};

/**
 * Disables the formation command
 */
Game_System.prototype.disableFormation = function() {
    this._formationEnabled = false;
};

/**
 * Enables the formation command
 */
Game_System.prototype.enableFormation = function() {
    this._formationEnabled = true;
};

/**
 * Get the amount of battles
 *
 * @return {number} Amount of battles
 */
Game_System.prototype.battleCount = function() {
    return this._battleCount;
};

/**
 * Get the amount of battles won
 *
 * @return {number} Amount of battles won
 */
Game_System.prototype.winCount = function() {
    return this._winCount;
};

/**
 * Get the amount of battles escaped
 *
 * @return {number} Amount of battles escaped
 */
Game_System.prototype.escapeCount = function() {
    return this._escapeCount;
};

/**
 * Get the amount of times saved
 *
 * @return {number} Amount of times saved
 */
Game_System.prototype.saveCount = function() {
    return this._saveCount;
};

/**
 * Get the version id
 *
 * @return {number} Version id
 */
Game_System.prototype.versionId = function() {
    return this._versionId;
};

/**
 * Get the current save file id
 *
 * @return {number} Save file id
 */
Game_System.prototype.savefileId = function() {
    return this._savefileId || 0;
};

/**
 * Set the current save file id
 *
 * @param {number} savefileId - The new save file id
 */
Game_System.prototype.setSavefileId = function(savefileId) {
    this._savefileId = savefileId;
};

/**
 * Gets the window tone
 *
 * @return {Array} Window tone array object
 */
Game_System.prototype.windowTone = function() {
    return this._windowTone || $dataSystem.windowTone;
};

/**
 * Sets the window tone
 *
 * @param {Array} value - The new window tone array object
 */
Game_System.prototype.setWindowTone = function(value) {
    this._windowTone = value;
};

/**
 * Gets the battle bgm
 *
 * @return {Object} The battle bgm
 */
Game_System.prototype.battleBgm = function() {
    return this._battleBgm || $dataSystem.battleBgm;
};

/**
 * Sets the battle bgm
 *
 * @param {Object} value - The new battle bgm
 */
Game_System.prototype.setBattleBgm = function(value) {
    this._battleBgm = value;
};

/**
 * Gets the victory me
 *
 * @return {Object} The victory me
 */
Game_System.prototype.victoryMe = function() {
    return this._victoryMe || $dataSystem.victoryMe;
};

/**
 * Sets the victory me
 *
 * @param {Object} value - The new victory me
 */
Game_System.prototype.setVictoryMe = function(value) {
    this._victoryMe = value;
};

/**
 * Gets the defeat me
 *
 * @return {Object} The defeat me
 */
Game_System.prototype.defeatMe = function() {
    return this._defeatMe || $dataSystem.defeatMe;
};

/**
 * Sets the defeat me
 *
 * @param {Object} value - The new defeat me
 */
Game_System.prototype.setDefeatMe = function(value) {
    this._defeatMe = value;
};

/**
 * Processing when a battle starts
 */
Game_System.prototype.onBattleStart = function() {
    this._battleCount++;
};

/**
 * Processing when a battle is won
 */
Game_System.prototype.onBattleWin = function() {
    this._winCount++;
};

/**
 * Processing when a battle is escaped
 */
Game_System.prototype.onBattleEscape = function() {
    this._escapeCount++;
};

/**
 * Processing before a save occurs
 */
Game_System.prototype.onBeforeSave = function() {
    this._saveCount++;
    this._versionId = $dataSystem.versionId;
    this._framesOnSave = Graphics.frameCount;
    this._bgmOnSave = AudioManager.saveBgm();
    this._bgsOnSave = AudioManager.saveBgs();
};

/**
 * Processing after a save file is loaded
 */
Game_System.prototype.onAfterLoad = function() {
    Graphics.frameCount = this._framesOnSave;
    AudioManager.playBgm(this._bgmOnSave);
    AudioManager.playBgs(this._bgsOnSave);
};

/**
 * Get the playtime in seconds
 *
 * @return {number} The playtime
 */
Game_System.prototype.playtime = function() {
    return Math.floor(Graphics.frameCount / 60);
};

/**
 * Get the playtime as text
 *
 * @return {string} The playtime as text
 */
Game_System.prototype.playtimeText = function() {
    const hour = Math.floor(this.playtime() / 60 / 60);
    const min = Math.floor(this.playtime() / 60) % 60;
    const sec = this.playtime() % 60;
    return hour.padZero(2) + ":" + min.padZero(2) + ":" + sec.padZero(2);
};

/**
 * Save the current bgm
 */
Game_System.prototype.saveBgm = function() {
    this._savedBgm = AudioManager.saveBgm();
};

/**
 * Replays the saved bgm
 */
Game_System.prototype.replayBgm = function() {
    if (this._savedBgm) {
        AudioManager.replayBgm(this._savedBgm);
    }
};

/**
 * Save the walking bgm
 */
Game_System.prototype.saveWalkingBgm = function() {
    this._walkingBgm = AudioManager.saveBgm();
};

/**
 * Replays the walking bgm
 */
Game_System.prototype.replayWalkingBgm = function() {
    if (this._walkingBgm) {
        AudioManager.playBgm(this._walkingBgm);
    }
};

/**
 * Save the walking bgm 2
 */
Game_System.prototype.saveWalkingBgm2 = function() {
    this._walkingBgm = $dataMap.bgm;
};

/**
 * Get the main font face
 *
 * @return {string} The main font face
 */
Game_System.prototype.mainFontFace = function() {
    return "rmmz-mainfont, " + $dataSystem.advanced.fallbackFonts;
};

/**
 * Get the number font face
 *
 * @return {string} The number font face
 */
Game_System.prototype.numberFontFace = function() {
    return "rmmz-numberfont, " + this.mainFontFace();
};

/**
 * Get the main font size
 *
 * @return {number} The main font size
 */
Game_System.prototype.mainFontSize = function() {
    return $dataSystem.advanced.fontSize;
};

/**
 * Get the window padding
 *
 * @return {number} The window padding
 */
Game_System.prototype.windowPadding = function() {
    return 12;
};

/**
 * Get the window opacity
 *
 * @return {number} The window opacity
 * @since Version 1.3.0
 */
Game_System.prototype.windowOpacity = function() {
    return $dataSystem.advanced.windowOpacity;
};