magical-girls-runa-and-nanami/js/plugins/hide_timer.js
2026-02-28 12:33:13 -06:00

110 lines
3.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*:
* @target MZ
* @plugindesc v1.0 タイマー表示を自動で非表示Map/Battle対応・安全ガード付き
* @author You
*
* @help
* 概要:
* このプラグインは、タイマー起動時の画面右上の数字表示を自動で非表示にします。
* 「タイマーの操作(開始/再開)」はそのまま使えます(カウントは内部で進行)。
*
* エディタ操作:
* - 通常どおりコモンイベント等で「タイマーの操作30秒開始」を実行してください。
* - 表示は出ず、30秒後に「タイマー ≤ 0」の条件が成立します。
*
* 技術メモ:
* - Scene_Map / Scene_Battle の createTimer をフックして非表示化します。
* - 生成が間に合わない場合に備え、Game_Timer.start 後にも遅延で再非表示。
* - オプションで毎フレーム強制非表示(安全策)も行えます。
*
* @param HideOnMap
* @text マップで非表示
* @type boolean
* @on 非表示
* @off 表示
* @default true
*
* @param HideOnBattle
* @text 戦闘で非表示
* @type boolean
* @on 非表示
* @off 表示
* @default true
*
* @param EnforceEveryFrame
* @text 毎フレーム再非表示(安全策)
* @type boolean
* @on 有効
* @off 無効
* @default true
*
* @param DelayMs
* @text 追加の遅延(ms)
* @type number
* @min 0
* @desc タイマー開始直後にスプライト生成が遅れるケース向けの再非表示ディレイ。通常は0〜100で十分。
* @default 100
*/
(() => {
const PLUGIN_NAME = "HideTimerSprite";
const p = PluginManager.parameters(PLUGIN_NAME);
const HIDE_MAP = String(p.HideOnMap || "true") === "true";
const HIDE_BATTLE = String(p.HideOnBattle || "true") === "true";
const ENFORCE_EVERY = String(p.EnforceEveryFrame || "true") === "true";
const DELAY_MS = Number(p.DelayMs || 100);
// 安全に非表示化するユーティリティ
function hideTimerSpriteSafe(scene) {
if (scene && scene._timerSprite) {
scene._timerSprite.visible = false;
}
}
// 現在アクティブなシーンに対して非表示
function hideCurrentTimerSprite() {
const sc = SceneManager._scene;
if (!sc) return;
if ((sc instanceof Scene_Map && HIDE_MAP) || (sc instanceof Scene_Battle && HIDE_BATTLE)) {
hideTimerSpriteSafe(sc);
}
}
// Scene_Map: タイマー生成直後に非表示
const _Scene_Map_createTimer = Scene_Map.prototype.createTimer;
Scene_Map.prototype.createTimer = function() {
_Scene_Map_createTimer.call(this);
if (HIDE_MAP) hideTimerSpriteSafe(this);
};
// Scene_Battle: タイマー生成直後に非表示
const _Scene_Battle_createTimer = Scene_Battle.prototype.createTimer;
Scene_Battle.prototype.createTimer = function() {
_Scene_Battle_createTimer.call(this);
if (HIDE_BATTLE) hideTimerSpriteSafe(this);
};
// Game_Timer.start: 開始後に遅延で再度非表示(生成の遅延に対応)
const _Game_Timer_start = Game_Timer.prototype.start;
Game_Timer.prototype.start = function(count) {
_Game_Timer_start.call(this, count);
if (DELAY_MS >= 0) {
setTimeout(hideCurrentTimerSprite, Math.max(0, DELAY_MS));
}
};
// 安全策: 毎フレームも非表示にしておく(任意)
if (ENFORCE_EVERY) {
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
if (HIDE_MAP) hideTimerSpriteSafe(this);
};
const _Scene_Battle_update = Scene_Battle.prototype.update;
Scene_Battle.prototype.update = function() {
_Scene_Battle_update.call(this);
if (HIDE_BATTLE) hideTimerSpriteSafe(this);
};
}
})();