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

85 lines
2.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 [MZ] 変数48の値に応じてピクチャの透明度を操作会話開始時に即255化特定スイッチ状態で無効
* @author you
*
* @help
* ・変数48が1のとき
* 上下左右キーを押している間はピクチャ21〜30を半透明128
* それ以外は不透明255にします。
*
* ・変数48が2のとき
* 上下左右キーを押している間は0.5秒(30フレーム)かけてフェードアウト、
* 離したときは1秒(60フレーム)かけてフェードインします。
*
* ・以下の状況では動作しません:
* ├ 会話中(メッセージウィンドウが開いている間)
* ├ スイッチ11がONのとき
* └ スイッチ31がOFFのとき
*
* ・会話が始まった瞬間に、ピクチャ21〜30を即座に不透明255に戻します。
*
* この処理はフレームごとに監視されます(並列処理不要)。
*/
(() => {
const pictureIds = [...Array(10)].map((_, i) => i + 21); // ピクチャ21〜30
let wasMessageBusy = false; // 前フレームの会話状態を記録
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
const isMessageBusy = $gameMessage.isBusy();
// 会話が始まった瞬間前はfalse → 今true
if (!wasMessageBusy && isMessageBusy) {
resetPictureOpacity();
}
wasMessageBusy = isMessageBusy;
// 会話中、スイッチ11がON、またはスイッチ31がOFFなら処理を無効化
if (isMessageBusy || $gameSwitches.value(11) || !$gameSwitches.value(31)) return;
updatePictureOpacity();
};
// 会話開始時にピクチャを即座に255に戻す
function resetPictureOpacity() {
for (const id of pictureIds) {
const p = $gameScreen.picture(id);
if (p) p.setOpacity(255);
}
}
function updatePictureOpacity() {
const mode = $gameVariables.value(48);
const pressed =
Input.isPressed('up') ||
Input.isPressed('down') ||
Input.isPressed('left') ||
Input.isPressed('right');
if (mode === 1) {
// 半透明/不透明切替
for (const id of pictureIds) {
const p = $gameScreen.picture(id);
if (p) p.setOpacity(pressed ? 128 : 255);
}
} else if (mode === 2) {
// フェード処理
for (const id of pictureIds) {
const p = $gameScreen.picture(id);
if (!p) continue;
if (pressed) {
const next = Math.max(0, p.opacity() - 255 / 30);
p.setOpacity(next);
} else {
const next = Math.min(255, p.opacity() + 255 / 60);
p.setOpacity(next);
}
}
}
}
})();