83 lines
No EOL
3 KiB
JavaScript
83 lines
No EOL
3 KiB
JavaScript
/*=============================================================================
|
|
MessageAutoReplace.js
|
|
----------------------------------------------------------------------------
|
|
(C)2022 Triacontane
|
|
This software is released under the MIT License.
|
|
http://opensource.org/licenses/mit-license.php
|
|
----------------------------------------------------------------------------
|
|
Version
|
|
1.0.0 2022/04/05 初版
|
|
1.1.0 2025/01/26 アイテムの説明文にも置換を適用
|
|
----------------------------------------------------------------------------*/
|
|
|
|
(() => {
|
|
'use strict';
|
|
|
|
// プラグインパラメータの設定
|
|
var createPluginParameter = function(pluginName) {
|
|
var paramReplacer = function(key, value) {
|
|
if (value === 'null') {
|
|
return value;
|
|
}
|
|
if (value[0] === '"' && value[value.length - 1] === '"') {
|
|
return value;
|
|
}
|
|
try {
|
|
return JSON.parse(value);
|
|
} catch (e) {
|
|
return value;
|
|
}
|
|
};
|
|
var parameter = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
|
|
PluginManager.setParameters(pluginName, parameter);
|
|
return parameter;
|
|
};
|
|
|
|
var param = createPluginParameter('MessageAutoReplace');
|
|
if (!param.replaceList) {
|
|
param.replaceList = [];
|
|
}
|
|
|
|
// メッセージウィンドウでの置換処理
|
|
var _Game_Message_allText = Game_Message.prototype.allText;
|
|
Game_Message.prototype.allText = function() {
|
|
return this.applyTextReplace(_Game_Message_allText.apply(this, arguments));
|
|
};
|
|
|
|
Game_Message.prototype.applyTextReplace = function(text) {
|
|
param.replaceList.forEach(function(item) {
|
|
if (item.switchId && !$gameSwitches.value(item.switchId)) {
|
|
return;
|
|
}
|
|
const regExp = new RegExp(item.targetText, 'g');
|
|
text = text.replace(regExp, function() {
|
|
const params = Array.from(arguments).slice(1);
|
|
return item.text.format.apply(item.text, params);
|
|
});
|
|
});
|
|
return text;
|
|
};
|
|
|
|
// アイテム説明文にも置換を適用
|
|
var _Game_Item_description = Game_Item.prototype.description;
|
|
Game_Item.prototype.description = function() {
|
|
var description = _Game_Item_description.call(this);
|
|
return this.applyTextReplace(description);
|
|
};
|
|
|
|
// アイテム説明文の置換処理を追加
|
|
Game_Item.prototype.applyTextReplace = function(text) {
|
|
param.replaceList.forEach(function(item) {
|
|
if (item.switchId && !$gameSwitches.value(item.switchId)) {
|
|
return;
|
|
}
|
|
const regExp = new RegExp(item.targetText, 'g');
|
|
text = text.replace(regExp, function() {
|
|
const params = Array.from(arguments).slice(1);
|
|
return item.text.format.apply(item.text, params);
|
|
});
|
|
});
|
|
return text;
|
|
};
|
|
|
|
})(); |