175 lines
No EOL
7.1 KiB
JavaScript
175 lines
No EOL
7.1 KiB
JavaScript
/*:
|
|
* @target MZ
|
|
* @plugindesc プラグインコマンドで、イベント内の変数操作を手動でロックします。v3.1.0
|
|
* @author IvI (改変: Gemini)
|
|
*
|
|
* @help
|
|
* ■ 概要 (v3.1.0)
|
|
* プラグインコマンドを使い、イベント内の変数操作をロックします。
|
|
* 「全ての変数をロック」するか、「指定した変数だけをロック」するかを選べます。
|
|
*
|
|
* 【!!!警告!!!】
|
|
* このバージョンは、v1.x, v2.x系のバージョンと一切の互換性がありません。
|
|
*
|
|
* ■ 使い方
|
|
* イベントコマンドの好きな位置で、以下のプラグインコマンドを実行します。
|
|
*
|
|
* ・「指定した変数をロック」
|
|
* パラメータで指定した変数の操作だけを禁止します。
|
|
*
|
|
* ・「指定した変数のロックを解除」
|
|
* 上記でかけたロックを変数ごとに解除します。
|
|
*
|
|
* ・「このイベントの全ての変数操作をロック」
|
|
* イベント内の全ての変数操作を禁止します。
|
|
*
|
|
* ・「このイベントの全てのロックを解除」
|
|
* 全ての変数操作の禁止を解除します。
|
|
*
|
|
* @command lockVariables
|
|
* @text 指定した変数をロック
|
|
* @desc このコマンド実行後、このイベントで指定した変数の操作を禁止します。
|
|
* @arg variables
|
|
* @type variable[]
|
|
* @text ロックする変数
|
|
* @desc ここで指定した変数がロック対象になります。
|
|
*
|
|
* @command unlockVariables
|
|
* @text 指定した変数のロックを解除
|
|
* @desc 指定した変数のロックを解除します。
|
|
* @arg variables
|
|
* @type variable[]
|
|
* @text ロックを解除する変数
|
|
* @desc ここで指定した変数がロック解除対象になります。
|
|
*
|
|
* @command lockAll
|
|
* @text このイベントの全ての変数操作をロック
|
|
* @desc このコマンド実行後、このイベントでの変数操作をすべて禁止します。この状態はセーブされます。
|
|
*
|
|
* @command unlockAll
|
|
* @text このイベントの全てのロックを解除
|
|
* @desc このイベントの変数操作の全ロックを解除します。
|
|
*
|
|
* @param BypassSwitch
|
|
* @text グローバル強制上書きスイッチ
|
|
* @type switch
|
|
* @desc このスイッチがONの時、このプラグインの全てのロック機能が無効になります。デバッグ等に利用できます。
|
|
* @default 0
|
|
*
|
|
*/
|
|
(() => {
|
|
'use strict';
|
|
|
|
const PN = "IvI_EventOnceVar";
|
|
const PARAM = PluginManager.parameters(PN);
|
|
const BYPASS_SWITCH_ID = Number(PARAM.BypassSwitch || 0);
|
|
|
|
// ---- セーブ用データ構造の初期化 ----
|
|
const _DataManager_createGameObjects = DataManager.createGameObjects;
|
|
DataManager.createGameObjects = function() {
|
|
_DataManager_createGameObjects.call(this);
|
|
// v3.1.0: 2種類のロックテーブルを用意
|
|
$gameSystem._manualEventVarLocks = $gameSystem._manualEventVarLocks || {}; // 変数指定ロック用
|
|
$gameSystem._manualEventAllLocks = $gameSystem._manualEventAllLocks || {}; // 全ロック用
|
|
};
|
|
|
|
// ---- util ----
|
|
const getKey = (interpreter) => {
|
|
if (interpreter && interpreter.eventId() > 0) {
|
|
return `${interpreter._mapId}_${interpreter._eventId}`;
|
|
}
|
|
return null;
|
|
};
|
|
const getInterpreter = () => $gameTemp._currentOnceVarInterpreter || $gameMap.interpreter;
|
|
|
|
// ---- プラグインコマンド登録 ----
|
|
|
|
// 指定した変数をロック
|
|
PluginManager.registerCommand(PN, "lockVariables", args => {
|
|
const interpreter = getInterpreter();
|
|
const key = getKey(interpreter);
|
|
const varsToLock = JSON.parse(args.variables || "[]").map(Number);
|
|
|
|
if (key && varsToLock.length > 0) {
|
|
if (!$gameSystem._manualEventVarLocks) $gameSystem._manualEventVarLocks = {};
|
|
|
|
const currentList = $gameSystem._manualEventVarLocks[key] || [];
|
|
const newList = [...new Set([...currentList, ...varsToLock])]; // 重複を避けて結合
|
|
$gameSystem._manualEventVarLocks[key] = newList;
|
|
}
|
|
});
|
|
|
|
// 指定した変数のロックを解除
|
|
PluginManager.registerCommand(PN, "unlockVariables", args => {
|
|
const interpreter = getInterpreter();
|
|
const key = getKey(interpreter);
|
|
const varsToUnlock = JSON.parse(args.variables || "[]").map(Number);
|
|
|
|
if (key && varsToUnlock.length > 0 && $gameSystem._manualEventVarLocks && $gameSystem._manualEventVarLocks[key]) {
|
|
$gameSystem._manualEventVarLocks[key] = $gameSystem._manualEventVarLocks[key].filter(
|
|
id => !varsToUnlock.includes(id)
|
|
);
|
|
}
|
|
});
|
|
|
|
// 全ての変数をロック
|
|
PluginManager.registerCommand(PN, "lockAll", args => {
|
|
const interpreter = getInterpreter();
|
|
const key = getKey(interpreter);
|
|
if (key) {
|
|
if (!$gameSystem._manualEventAllLocks) $gameSystem._manualEventAllLocks = {};
|
|
$gameSystem._manualEventAllLocks[key] = true;
|
|
}
|
|
});
|
|
|
|
// 全ての変数のロックを解除
|
|
PluginManager.registerCommand(PN, "unlockAll", args => {
|
|
const interpreter = getInterpreter();
|
|
const key = getKey(interpreter);
|
|
if (key && $gameSystem._manualEventAllLocks) {
|
|
delete $gameSystem._manualEventAllLocks[key];
|
|
}
|
|
});
|
|
|
|
/**
|
|
* @description Game_Interpreter.prototype.executeCommand をフック
|
|
*/
|
|
const _Game_Interpreter_executeCommand = Game_Interpreter.prototype.executeCommand;
|
|
Game_Interpreter.prototype.executeCommand = function() {
|
|
$gameTemp._currentOnceVarInterpreter = this;
|
|
const result = _Game_Interpreter_executeCommand.call(this);
|
|
$gameTemp._currentOnceVarInterpreter = null;
|
|
return result;
|
|
};
|
|
|
|
/**
|
|
* @description Game_Variables.prototype.setValue をフック
|
|
*/
|
|
const _setValue = Game_Variables.prototype.setValue;
|
|
Game_Variables.prototype.setValue = function(id, value) {
|
|
// グローバル上書きスイッチがONなら、全てのロックを無視
|
|
if (BYPASS_SWITCH_ID > 0 && $gameSwitches.value(BYPASS_SWITCH_ID)) {
|
|
_setValue.call(this, id, value);
|
|
return;
|
|
}
|
|
|
|
const interpreter = getInterpreter();
|
|
const key = getKey(interpreter);
|
|
|
|
if (key) {
|
|
// 1. 全ロックをチェック
|
|
if ($gameSystem._manualEventAllLocks && $gameSystem._manualEventAllLocks[key]) {
|
|
return; // 全ロック中なので中断
|
|
}
|
|
// 2. 変数指定ロックをチェック
|
|
if ($gameSystem._manualEventVarLocks && $gameSystem._manualEventVarLocks[key]) {
|
|
if ($gameSystem._manualEventVarLocks[key].includes(id)) {
|
|
return; // 指定された変なので中断
|
|
}
|
|
}
|
|
}
|
|
|
|
// ロックされていなければ元の処理を実行
|
|
_setValue.call(this, id, value);
|
|
};
|
|
})(); |