/* * -------------------------------------------------- * MNKR_TMTimerExMZ.js * Ver.1.0.1 * Copyright (c) 2020 Munokura * This software is released under the MIT license. * http://opensource.org/licenses/mit-license.php * -------------------------------------------------- */ //============================================================================= // TMVplugin - タイマー拡張 // 作者: tomoaky (http://hikimoki.sakura.ne.jp/) // Version: 1.0 // 最終更新日: 2016/07/29 //============================================================================= /*: @target MZ @url https://raw.githubusercontent.com/munokura/MNKR-MZ-plugins/master/MNKR_TMTimerExMZ.js @plugindesc Changes the timer display from seconds to milliseconds. @author tomoaky,munokura @license MIT License @help How to Use: Extend the timer functionality simply by installing this plugin. When using the timer judgment of the "Conditional Branch" event command, it may be determined that the timer has run out even if there is still time remaining in milliseconds. This problem can be avoided by assigning the remaining time to a game variable using the plugin command, and then using that variable to execute the conditional branch. Displaying milliseconds requires redrawing every frame, which can slow down processing. Plugin Command: timerMsec 5 Assigns the remaining timer time in milliseconds to game variable 5. # Contact Information This is a plugin originally created for RPG Maker MV that has been ported to MZ. Please contact the modifier for any inquiries. # Terms of Use MIT License. http://opensource.org/licenses/mit-license.php You may modify and redistribute it without permission from the author, and there are no restrictions on its use (commercial, R18, etc.). @param timerX @text Timer X coordinate @desc The X coordinate to display the timer. @type number @default 816 @param timerY @text Timer Y coordinate @desc The Y coordinate at which to display the timer. @type number @default 48 @param showMinutes @text Timer display format @desc Displays the timer in minutes:seconds format. @type boolean @on minutes: seconds @off Seconds only @default true @param msecShiftY @text Y adjustment in milliseconds @desc Adjusts the Y coordinate of the millisecond display. @type number @default 36 @command timerMsec @text Assign the remaining time to the timer @desc Sets the remaining time on the timer. @arg variableId @text Variable ID @desc Sets the variable to the number of milliseconds remaining on the timer. @type variable @default 0 */ /*:ja @target MZ @url https://raw.githubusercontent.com/munokura/MNKR-MZ-plugins/master/MNKR_TMTimerExMZ.js @plugindesc タイマー表示を秒単位からミリ秒単位に変更します。 @author tomoaky (改変:munokura) @help 使用方法: プラグインを導入するだけでタイマー機能が拡張されます。 イベントコマンド『条件分岐』のタイマー判定を使用すると、 ミリ秒単位ではまだ時間が残っているのにも関わらず、 時間切れと判定されてしまいます。 プラグインコマンドでゲーム変数に残り時間を代入してから、 その変数を使って条件分岐を実行することでこの問題を回避できます。 ミリ秒表示は毎フレーム再描画を実行するため、処理が重くなります。 プラグインコマンド: timerMsec 5 ゲーム変数5番にタイマーの残り時間をミリ秒単位で代入します。 # 問い合わせ先 これはRPGツクールMV用に作成されたプラグインをMZ用に移植したものです。 お問い合わせは改変者へお願いいたします。 # 利用規約 MITライセンスです。 http://opensource.org/licenses/mit-license.php 作者に無断で改変、再配布が可能で、 利用形態(商用、18禁利用等)についても制限はありません。 @param timerX @text タイマーX座標 @type number @desc タイマーを表示するX座標。 初期値: 816(ウィンドウの幅以上の値の場合は右端) @default 816 @param timerY @text タイマーY座標 @type number @desc タイマーを表示するY座標。 初期値: 48(ウィンドウの高さ以上の値の場合は下端) @default 48 @param showMinutes @text タイマー表示形式 @type boolean @on 分:秒 @off 秒のみ @desc タイマーを 分 : 秒 の書式で表示する。 初期値: true (false-秒のみ / true-分:秒) @default true @param msecShiftY @text ミリ秒のY調整 @type number @desc ミリ秒表示のY座標を調整します。 初期値: 36 @default 36 @command timerMsec @text タイマーの残り時間を代入 @desc タイマーの残り時間を代入します。 @arg variableId @text 変数ID @desc 変数にタイマーの残り時間をミリ秒単位で代入します。 @type variable @default 0 */ var Imported = Imported || {}; Imported.TMTimerEx = true; (() => { "use strict"; const pluginName = document.currentScript.src.split("/").pop().replace(/\.js$/, ""); const parameters = PluginManager.parameters(pluginName); const timerX = +parameters['timerX']; const timerY = +parameters['timerY']; const showMinutes = parameters['showMinutes'] === 'true'; const msecShiftY = +parameters['msecShiftY']; //----------------------------------------------------------------------------- // Game_Timer // Game_Timer.prototype.msec = function () { return Math.floor(this._frames / 60 * 1000); }; //----------------------------------------------------------------------------- // PluginManager // PluginManager.registerCommand(pluginName, "timerMsec", args => { const arr = [args.variableId]; $gameVariables.setValue(+arr[0], $gameTimer.msec()); }); //----------------------------------------------------------------------------- // Sprite_Timer // Sprite_Timer.prototype.createBitmap = function () { this.bitmap = new Bitmap(160, 48); }; const _Sprite_Timer_updateBitmap = Sprite_Timer.prototype.updateBitmap; Sprite_Timer.prototype.updateBitmap = function () { _Sprite_Timer_updateBitmap.call(this); let msec = $gameTimer.msec(); if (this._msec !== msec) { this._msec = msec; this.redrawMsec(); } }; Sprite_Timer.prototype.redraw = function () { this.bitmap.fontSize = 32; let text = showMinutes ? this.timerText() : '' + this._seconds; let height = this.bitmap.height; this.bitmap.clearRect(0, 0, 96, height); this.bitmap.drawText(text, 0, 0, 96, height, 'right'); }; Sprite_Timer.prototype.redrawMsec = function () { this.bitmap.fontSize = 16; let text = '.' + (this._msec % 1000).padZero(3); let y = this.bitmap.height - msecShiftY; let width = this.bitmap.width - 96; this.bitmap.clearRect(96, y, width, msecShiftY); this.bitmap.drawText(text, 96, y, width, msecShiftY, 'left'); }; Sprite_Timer.prototype.updatePosition = function () { if (timerX >= Graphics.width) { this.x = Graphics.width - this.bitmap.width; } else { this.x = timerX; } if (timerY >= Graphics.height) { this.y = Graphics.height - this.bitmap.height; } else { this.y = timerY; } }; })();