pure-full-lily/js/plugins/ShiftMultiPictures.js
2025-09-16 10:12:44 -05:00

124 lines
4.9 KiB
JavaScript
Raw 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.4 複数ピクチャを一括で移動・色調変更(イージング対応) @author IvI
*
* @command MovePictures
* @text ピクチャ移動
* @desc 指定ピクチャをまとめて移動
*
* @arg ids @type string @text ピクチャIDリスト @desc 例: 1-3,5,\V[30]
* @arg dx @type string @text X移動量 @default 0
* @arg dy @type string @text Y移動量 @default 0
* @arg duration @type string @text フレーム数 @default 60
* @arg easing
* @type select
* @text イージング
* @option Linear @value 0
* @option EaseIn @value 1
* @option EaseOut @value 2
* @option EaseInOut @value 3
* @default 0
* @arg wait @type boolean @text 完了までウェイト @default false
*
* @command TintPictures
* @text ピクチャ色調変更
* @desc 指定ピクチャをまとめて色調変更
*
* @arg ids @type string @text ピクチャIDリスト @desc 例: 1-3,5,\V[30]
* @arg tone @type string @text 色調(R,G,B,Gray) @default 0,0,0,0
* @arg duration @type string @text フレーム数 @default 60
*
* @help
* ■概要
* カンマ・ハイフン区切りで指定した複数 ID のピクチャを
* 一括で「移動」または「色調変更」します。
* - \V[n] 置換+四則演算に対応
* - 移動はイージングLinear / EaseIn / EaseOut / EaseInOut指定可
* - 「完了までウェイト」ON でイベントを待機
*
* ■利用方法
* 1. 本ファイルを js/plugins に配置しプラグイン管理で ON
* 2. イベント → プラグインコマンドから設定
*
* MIT ライセンス(表記任意・改変/商用利用可)
*/
(() => {
"use strict";
const PLUGIN_NAME = "ShiftMultiPictures"; // ←ファイル名と合わせる
// -------------------------------------------------- 共通
function evalNumber(str){
const s = String(str).replace(/\\V\[(\d+)\]/gi, (_, n) => $gameVariables.value(+n));
try { return Math.floor(eval(s)); } catch { return 0; }
}
function parseIdList(text = ""){
return text.split(",").flatMap(t => {
t = t.trim(); if(!t) return [];
if(t.includes("-")){
const [a, b] = t.split("-").map(evalNumber);
const start = Math.min(a, b), end = Math.max(a, b);
return Array.from({length: end - start + 1}, (_, i) => start + i);
}
return [evalNumber(t)];
}).filter(n => Number.isInteger(n) && n > 0);
}
// -------------------------------------------------- MovePictures
PluginManager.registerCommand(PLUGIN_NAME, "MovePictures", function(args){
const ids = parseIdList(args.ids);
const dx = evalNumber(args.dx), dy = evalNumber(args.dy);
const dur = Math.max(1, evalNumber(args.duration));
const easing = Number(args.easing || 0); // 0-3
const wait = args.wait === "true" && ids.length;
ids.forEach(id => {
const p = $gameScreen.picture(id);
if(p){
const origin = p.origin();
const blendMode = p.blendMode();
const tx = p.x() + dx, ty = p.y() + dy;
p.move(origin, tx, ty, p.scaleX(), p.scaleY(), p.opacity(), blendMode, dur, easing);
}
});
if(wait){ this.setWaitMode("picture"); this._smpIds = ids; }
});
const _updateWait = Game_Interpreter.prototype.updateWaitMode;
Game_Interpreter.prototype.updateWaitMode = function(){
if(this._waitMode === "picture"){
const busy = this._smpIds.some(id => {
const p = $gameScreen.picture(id);
return p && p.isMoving(); // ← isMoving() は後述ポリフィルで補完
});
if(!busy){ this._waitMode = ""; this._smpIds = null; }
return busy;
}
return _updateWait.call(this);
};
// -------------------------------------------------- TintPictures
PluginManager.registerCommand(PLUGIN_NAME, "TintPictures", function(args){
const ids = parseIdList(args.ids);
const tone = args.tone.split(",").map(s => evalNumber(s.trim())).slice(0, 4);
while(tone.length < 4) tone.push(0);
const dur = Math.max(1, evalNumber(args.duration));
ids.forEach(id => { const p = $gameScreen.picture(id); if(p) p.tint(tone, dur); });
});
// -------------------------------------------------- MZ 互換ポリフィル (MV→MZ)
if(!Game_Picture.prototype.isMoving){
/**
* Game_Picture.prototype.isMoving
* MZ には存在しないため互換実装を追加。
* ・移動フレーム _duration
* ・色調変更フレーム _toneDuration
* が残っていれば「移動中」と判定する。
*/
Game_Picture.prototype.isMoving = function(){
return (this._duration || 0) > 0 || (this._toneDuration || 0) > 0;
};
}
})(); // End of IIFE