321 lines
10 KiB
JavaScript
321 lines
10 KiB
JavaScript
/*:
|
||
* @plugindesc プラグインコマンドで数値を入力してピクチャを表示するプラグイン
|
||
* @target MZ
|
||
* @author ChatGPT
|
||
*
|
||
* @command PictureDisplay
|
||
* @text ピクチャ表示
|
||
* @desc 数値リストを入力してピクチャを表示します。
|
||
*
|
||
* @arg values
|
||
* @type text
|
||
* @text 数値リスト
|
||
* @desc 表示する数値リストをカンマ区切りで入力してください。
|
||
* @default [1,2,3,4,5,6]
|
||
*
|
||
* @arg applyTone
|
||
* @type boolean
|
||
* @text 色調変更を適用
|
||
* @desc ONであれば全てのピクチャの色調を0にします。
|
||
* @default false
|
||
*
|
||
* @arg position
|
||
* @type select
|
||
* @text PCの位置
|
||
* @desc 表示するピクチャのX軸位置を指定します。
|
||
* @default event
|
||
* @option field
|
||
* @value field
|
||
* @option event
|
||
* @value event
|
||
*
|
||
* @command UpdateAvatar
|
||
|
||
* @text アバター更新
|
||
* @desc アバターの値を更新します。
|
||
*
|
||
* @arg values
|
||
* @type text
|
||
* @text アバター数値
|
||
*
|
||
* @command UpdateFace
|
||
* @text ヒロインの表情更新
|
||
* @desc ヒロインの表情に関連する値のみを更新します。
|
||
*
|
||
* @arg values
|
||
* @type text
|
||
* @text 表情数値リスト
|
||
* @desc 表情を更新する3つの数値をカンマ区切りで入力してください。
|
||
* @default [1,1,1]
|
||
*
|
||
* @command UpdateEffect
|
||
* @text エフェクト更新
|
||
* @desc エフェクトの値を更新します。
|
||
*
|
||
* @arg values
|
||
* @type text
|
||
* @text エフェクト数値
|
||
* @help PictureDisplayPlugin.js
|
||
*
|
||
* このプラグインは、プラグインコマンドで指定した数値に基づいて
|
||
* ピクチャを表示します。
|
||
*
|
||
* 表示するピクチャは以下のフォルダから読み取られます:
|
||
* img/pictures/chara/
|
||
*
|
||
* ファイル名形式:
|
||
* T0[変数10]_a[変数11]_NN.png
|
||
* (NNはスイッチ12と13の状態によるサフィックス)
|
||
*
|
||
* ◆ プラグインコマンド
|
||
* 1. PictureDisplay [1,2,3,4,5,6]
|
||
* 指定された値が変数に代入され、ピクチャが表示されます。
|
||
*
|
||
* 2. UpdateFace [1,1,1]
|
||
* ヒロインの表情に関連する3つの値のみを更新します。
|
||
* 他の値は変更されません。
|
||
*
|
||
* 3. UpdateAvatar 1
|
||
* ヒロインのメイン画像の値を更新します。
|
||
* 他の値は変更されません。
|
||
* *
|
||
* 5. UpdatePosition event
|
||
* ピクチャの位置を更新します。
|
||
*
|
||
* 6. UpdateEffect 1
|
||
* エフェクトの値を更新します。
|
||
*
|
||
* 注意:
|
||
* - ファイルが存在しない場合、コンソールに警告が表示されます。
|
||
* - ピクチャIDは 30 ~ 34 を使用します。
|
||
*/
|
||
|
||
(() => {
|
||
"use strict";
|
||
|
||
const pluginName = "PictureDisplayPlugin";
|
||
|
||
PluginManager.registerCommand(pluginName, "PictureDisplay", args => {
|
||
try {
|
||
const values = JSON.parse(args.values);
|
||
const applyTone = args.applyTone === "true";
|
||
const position = args.position || "event";
|
||
|
||
|
||
if (!Array.isArray(values)) {
|
||
console.warn("渡された値が配列ではありません: ", args.values);
|
||
return;
|
||
}
|
||
|
||
values.forEach((value, index) => {
|
||
$gameVariables.setValue(10 + index, value || 0);
|
||
});
|
||
|
||
$gameVariables.setValue(16, position);
|
||
|
||
updatePictures(applyTone);
|
||
} catch (e) {
|
||
console.error("プラグインコマンドの解析エラー: ", e);
|
||
}
|
||
|
||
});
|
||
|
||
// ポジション更新する 変数16: field or event
|
||
PluginManager.registerCommand(pluginName, "UpdatePosition", args => {
|
||
try {
|
||
const values = JSON.parse(args.values);
|
||
const position = args.position || "field";
|
||
|
||
setDefaultVariables();
|
||
|
||
console.log('UpdatePosition', values);
|
||
|
||
$gameVariables.setValue(16, position);
|
||
logVariables();
|
||
|
||
const applyTone = true;
|
||
updatePictures(applyTone);
|
||
|
||
|
||
} catch (e) {
|
||
console.error("プラグインコマンドの解析エラー: ", e);
|
||
}
|
||
});
|
||
|
||
PluginManager.registerCommand(pluginName, "UpdateAvatar", args => {
|
||
try {
|
||
const values = JSON.parse(args.values);
|
||
|
||
setDefaultVariables();
|
||
|
||
console.log('UpdateAvatar', values);
|
||
|
||
|
||
logVariables();
|
||
// 変数11の値を更新
|
||
$gameVariables.setValue(11, parseInt(values));
|
||
logVariables();
|
||
|
||
|
||
// 元のapplyToneを使用
|
||
const applyTone = true;
|
||
updatePictures(applyTone);
|
||
|
||
} catch (e) {
|
||
console.error("プラグインコマンドの解析エラー: ", e);
|
||
}
|
||
});
|
||
|
||
|
||
PluginManager.registerCommand(pluginName, "UpdateFace", args => {
|
||
try {
|
||
const values = JSON.parse(args.values);
|
||
|
||
if (!Array.isArray(values) || values.length !== 3) {
|
||
console.warn("渡された値が不正です。3つの値を配列で指定してください: ", args.values);
|
||
return;
|
||
}
|
||
|
||
setDefaultVariables();
|
||
|
||
logVariables();
|
||
// 現在の変数の値を置き換え
|
||
const variableIndices = [12, 13, 14]; // 変数番号 口,眉,目
|
||
|
||
variableIndices.forEach((index, i) => {
|
||
$gameVariables.setValue(index, parseInt(values[i]));
|
||
});
|
||
|
||
|
||
// 2,3,4番目(index: 1,2,3)の値のみを更新
|
||
console.log('UpdateFace', values);
|
||
logVariables();
|
||
|
||
|
||
|
||
// 元のapplyToneを使用
|
||
const applyTone = true;
|
||
updatePictures(applyTone);
|
||
|
||
|
||
} catch (e) {
|
||
console.error("プラグインコマンドの解析エラー: ", e);
|
||
}
|
||
});
|
||
|
||
PluginManager.registerCommand(pluginName, "UpdateEffect", args => {
|
||
try {
|
||
const values = JSON.parse(args.values);
|
||
|
||
setDefaultVariables();
|
||
|
||
console.log('UpdateEffect', values);
|
||
|
||
|
||
logVariables();
|
||
// 変数15の値を更新
|
||
$gameVariables.setValue(15, parseInt(values));
|
||
logVariables();
|
||
|
||
// 元のapplyToneを使用
|
||
const applyTone = true;
|
||
updatePictures(applyTone);
|
||
|
||
} catch (e) {
|
||
console.error("プラグインコマンドの解析エラー: ", e);
|
||
}
|
||
});
|
||
|
||
function setDefaultVariables() {
|
||
if ($gameVariables.value(10) === 0) {
|
||
$gameVariables.setValue(10, 2);
|
||
$gameVariables.setValue(11, 2);
|
||
$gameVariables.setValue(12, 2);
|
||
$gameVariables.setValue(13, 1);
|
||
$gameVariables.setValue(14, 1);
|
||
$gameVariables.setValue(15, 1);
|
||
$gameVariables.setValue(16, "event");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
function logVariables() {
|
||
// 11,12,13,14,15,16の値を取得
|
||
const variable10 = $gameVariables.value(10);
|
||
const variable11 = $gameVariables.value(11);
|
||
const variable12 = $gameVariables.value(12);
|
||
const variable13 = $gameVariables.value(13);
|
||
const variable14 = $gameVariables.value(14);
|
||
const variable15 = $gameVariables.value(15);
|
||
const variable16 = $gameVariables.value(16);
|
||
|
||
console.log('logVariables メイン10:', variable10, '素体11:', variable11, '口12:', variable12, '眉13:', variable13, '目14:', variable14, 'エフェクト15:', variable15, '位置16:', variable16);
|
||
}
|
||
|
||
|
||
function updatePictures(applyTone) {
|
||
function fileExists(filePath) {
|
||
try {
|
||
const fs = require("fs");
|
||
return fs.existsSync(filePath);
|
||
} catch (e) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
const basePath = "chara/"; // フォルダ名
|
||
const mainVariable = $gameVariables.value(10); // T0[変数10] に対応
|
||
|
||
// a: メイン画像
|
||
// b: 口
|
||
// c: 眉
|
||
// d: 目
|
||
// e: エフェクト
|
||
const suffixes = ['a', 'b', 'c', 'd', 'e']; // サフィックス配列
|
||
const variableIndices = [11, 12, 13, 14, 15]; // 変数番号
|
||
|
||
|
||
// スイッチの状態を取得
|
||
const switch12 = $gameSwitches.value(12);
|
||
const switch13 = $gameSwitches.value(13);
|
||
|
||
// サフィックスの決定(aのみ)
|
||
let extraSuffix = "01";
|
||
if (switch12 && switch13) {
|
||
extraSuffix = "03"; // スイッチ13が優先
|
||
} else if (switch12) {
|
||
extraSuffix = "02";
|
||
} else if (switch13) {
|
||
extraSuffix = "03";
|
||
}
|
||
|
||
const switch16 = $gameVariables.value(16);
|
||
const xPosition = switch16 === "event" ? 100 : 0;
|
||
|
||
suffixes.forEach((suffix, i) => {
|
||
const variableValue = $gameVariables.value(variableIndices[i]).toString().padStart(2, "0");
|
||
let picturePath;
|
||
|
||
if (suffix === 'a') {
|
||
// `a` の場合のみスイッチに応じたサフィックスを追加
|
||
picturePath = `${basePath}T0${mainVariable}_${suffix}${variableValue}_${extraSuffix}`;
|
||
} else {
|
||
// `b`, `c`, `d`, `e` はスイッチに依存せず固定
|
||
picturePath = `${basePath}T0${mainVariable}_${suffix}${variableValue}`;
|
||
}
|
||
|
||
const pictureId = 30 + i; // ピクチャIDを30~34に固定
|
||
|
||
if (fileExists(`img/pictures/${picturePath}.png`)) {
|
||
const currentPicture = $gameScreen.picture(pictureId);
|
||
const tone = applyTone ? [0, 0, 0, 0] : (currentPicture ? currentPicture._tone : [0, 0, 0, 0]);
|
||
|
||
$gameScreen.showPicture(pictureId, picturePath, 0, xPosition, 0, 100, 100, 255, 0);
|
||
$gameScreen.picture(pictureId).tint(tone, 1);
|
||
} else {
|
||
console.warn(`File not found: img/pictures/${picturePath}.png`);
|
||
}
|
||
});
|
||
}
|
||
})();
|