139 lines
5.2 KiB
JavaScript
139 lines
5.2 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc メッセージ名に基づくピクチャ色調変更プラグイン
|
||
* @author IvI
|
||
*
|
||
* @help
|
||
* メッセージ名に基づいてピクチャ(10, 11, 12, 13)の色調を変更します。
|
||
*
|
||
* ■ 機能概要:
|
||
* - 名前ごとに特定の色調を適用できます。
|
||
* - 名前ごとに紐づけられたピクチャIDを設定可能です。
|
||
* - デフォルト色調を指定可能です。
|
||
*
|
||
* ■ 使用方法:
|
||
* - プラグインパラメータで名前と色調、ピクチャIDを設定してください。
|
||
* - 名前欄に該当する名前を記述すると色調が適用されます。
|
||
*
|
||
* ■ 利用規約:
|
||
* このプラグインは自由に使用できます(MITライセンス)。
|
||
*
|
||
* @param defaultTone
|
||
* @text デフォルト色調
|
||
* @type number[]
|
||
* @default [-50, -50, -50, 0]
|
||
* @desc 名前が一致しない場合のデフォルト色調(赤, 緑, 青, グレー)。
|
||
*
|
||
* @param nameSettings
|
||
* @text 名前ごとの設定
|
||
* @type struct<NameSetting>[]
|
||
* @default []
|
||
* @desc 名前ごとに色調と対象ピクチャIDを設定します。
|
||
*/
|
||
|
||
/*~struct~NameSetting:
|
||
* @param name
|
||
* @text キャラクター名
|
||
* @type string
|
||
* @desc メッセージウィンドウに表示される名前。
|
||
*
|
||
* @param tone
|
||
* @text 色調
|
||
* @type number[]
|
||
* @desc 対応する色調(赤, 緑, 青, グレー)。
|
||
* @default [0, 0, 0, 0]
|
||
*
|
||
* @param pictureIds
|
||
* @text ピクチャIDリスト
|
||
* @type number[]
|
||
* @desc この名前に紐づけるピクチャIDのリスト。
|
||
* @default []
|
||
*/
|
||
|
||
(() => {
|
||
'use strict';
|
||
|
||
const pluginName = "Picture Tone By Message";
|
||
|
||
// プラグインパラメータの取得
|
||
const parameters = PluginManager.parameters(pluginName);
|
||
|
||
// 名前ごとの設定を取得
|
||
const nameSettings = (() => {
|
||
try {
|
||
return JSON.parse(parameters["nameSettings"] || "[]").map(entry => {
|
||
const data = JSON.parse(entry);
|
||
return {
|
||
name: (data.name || "").toLowerCase(),
|
||
tone: JSON.parse(data.tone || "[0, 0, 0, 0]").map(Number),
|
||
pictureIds: JSON.parse(data.pictureIds || "[]").map(Number)
|
||
};
|
||
});
|
||
} catch (e) {
|
||
console.error(`Error parsing nameSettings: ${e.message}`);
|
||
return [];
|
||
}
|
||
})();
|
||
|
||
// デフォルト色調
|
||
const defaultTone = (() => {
|
||
try {
|
||
return JSON.parse(parameters["defaultTone"] || "[-50, -50, -50, 0]").map(Number);
|
||
} catch (e) {
|
||
console.error(`Error parsing defaultTone: ${e.message}`);
|
||
return [-50, -50, -50, 0];
|
||
}
|
||
})();
|
||
|
||
// Game_Interpreter.command101 をオーバーライド
|
||
const _Game_Interpreter_command101 = Game_Interpreter.prototype.command101;
|
||
Game_Interpreter.prototype.command101 = function(params) {
|
||
const rawName = params[4] || ""; // 名前欄の取得
|
||
const name = rawName.trim().toLowerCase(); // 前後の空白を削除し、小文字化
|
||
|
||
console.log(`Processing Name: ${name}`); // デバッグログ
|
||
|
||
// 名前がマッピングにあるかをチェック
|
||
const activeNameEntry = nameSettings.find(entry => entry.name === name);
|
||
|
||
// 全てのピクチャIDを取得
|
||
const allPictureIds = nameSettings.reduce((acc, entry) => acc.concat(entry.pictureIds), []);
|
||
|
||
if (activeNameEntry) {
|
||
// 名前が一致する場合
|
||
const activePictureIds = activeNameEntry.pictureIds;
|
||
const inactivePictureIds = allPictureIds.filter(id => !activePictureIds.includes(id));
|
||
|
||
console.log(`Active Name: ${name}, Active Picture IDs: ${activePictureIds}, Inactive Picture IDs: ${inactivePictureIds}`); // デバッグログ
|
||
|
||
// アクティブなピクチャに色調を適用
|
||
activePictureIds.forEach(pictureId => {
|
||
const picture = $gameScreen.picture(pictureId);
|
||
if (picture) {
|
||
picture.tint(activeNameEntry.tone, 1); // アクティブトーン適用
|
||
}
|
||
});
|
||
|
||
// 非アクティブなピクチャにデフォルトトーンを適用
|
||
inactivePictureIds.forEach(pictureId => {
|
||
const picture = $gameScreen.picture(pictureId);
|
||
if (picture) {
|
||
picture.tint(defaultTone, 1); // デフォルトトーン適用
|
||
}
|
||
});
|
||
} else {
|
||
// 名前が一致しない場合、全てのピクチャにデフォルトトーンを適用
|
||
console.log(`No Active Name, Applying Default Tone to All Picture IDs: ${allPictureIds}`); // デバッグログ
|
||
|
||
allPictureIds.forEach(pictureId => {
|
||
const picture = $gameScreen.picture(pictureId);
|
||
if (picture) {
|
||
picture.tint(defaultTone, 1); // デフォルトトーン適用
|
||
}
|
||
});
|
||
}
|
||
|
||
// オリジナルの処理を実行
|
||
return _Game_Interpreter_command101.call(this, params);
|
||
};
|
||
})();
|