menacephere-of-inverted-dreams/js/plugins/ChangeMapTile.js
2025-04-07 10:17:54 -05:00

391 lines
14 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

//=============================================================================
// Plugin for RPG Maker MZ
// ChangeMapTile.js
//=============================================================================
/*:
* @target MZ
* @plugindesc Change MapTile and Save state of MapTile
* @author sou_sitaku
*
* @command set
* @text
* @desc
*
* @arg setSwitchID
* @type number
* @text SetSwitchID
* @desc Input switch ID you switch on.
*
* @command reset
* @text
* @desc マップタイルの変更を解除します。
*
* @arg resetSwitchID
* @text ResetSwitchID
* @desc Input switch ID you switch OFF.
*
* @param switchID
* @text switchID
* @desc
* @type number[]
* @min 1
* @default 1
* @param x
* @text x coordinate
* @desc
* @type number[]
*
* @param y
* @text y coordinate
* @desc
* @type number[]
*
* @param z
* @text Depth of Layer
* @desc
* @type number[]
*
* @param MapTileID
* @text MapTileID
* @desc
* @type number[]
*
* @param MapID
* @text MapID
* @desc
* @type number[]
*
* @param debugMode
* @text debugMode
* @type boolean
*
* @help
* This plugin runs under RPG Maker MZ.
*
* Appoint x-y coordinate and depth of layer and MapTileID with plugin command.
* This plugin changes maptile at the coordinate and depth of layer which you appointed.
*
* ■Parameters
*
* ・switchID Input switch ID which manages the maptile change's ON/OFF.
* ・x coordinate Input x coordinate of map that you change the maptile.
* ・y coordinate Input y coordinate of map that you change the maptile.
* ・z coordinate Input depth of layer that you change tha maptile.
* Input 0 to 3, it expresses 1st to 4th layer.
* ・MapTileID Input maptile ID that you change.
* You can refer to the following URL about maptile ID.
* https://github.com/tonbijp/RPGMakerMZ/blob/master/Reference/Tilemap.md
* ・MapID Input map ID that you change the maptile.
* ・DebugMode Select ON or OFF of debug mode.
* If you select ON, this plugin output some logs that you can
* check your input contents of parameters.
*
* ■How to use this plugin, and example of input.
* 1) Input parameters.
* Parameters except for DebugMode are arrays.
* Input parameters of one case in same number of elements of every arrays.
*
* 【example】
* ・switchID ["1","2"]
* ・x coordinate ["3","20"]
* ・y coordinate ["6","3"].
* ・z coordinate ["2","1"]
* ・MapTileID ["762","54"]
* ・MapID ["1","3"]
* ・DebugMode false
*
* In the above, the maptile at the x-y-coodinate[20, 3] and the 4th depth from the bottom of layers,
* is changed to the maptileID[52] while switchID[002] is ON.
*
* 2) Use Plugin Command
* ・Plugin Command[set]
* Input a switch ID you want to switch on.
* When this command is run, this plugin turns on the switch,
* and changes maptiles following the parameters.
*
* ・Plugin Command[reset]
* Input a switch ID you want to switch off.
* When this command is run, this plugin turns off the switch,
* and changes maptiles following the parameters.
*
* [License]
* this plugin is released under MIT license.
* http://opensource.org/licenses/mit-license.php
*/
/*:ja
* @target MZ
* @plugindesc マップタイルを変更し、その状態を保存します。
* @author sou_sitaku
*
* @command set
* @text
* @desc マップタイルを変更します。
*
* @arg setSwitchID
* @text スイッチID
* @desc ONにするスイッチのIDを入力してください。
*
* @command reset
* @text
* @desc マップタイルの変更を解除します。
*
* @arg resetSwitchID
* @text スイッチID
* @desc OFFにするスイッチのIDを入力してください。
*
* @param switchID
* @text スイッチID
* @desc
* @type number[]
*
* @param x
* @text x座標
* @desc
* @type number[]
*
* @param y
* @text y座標
* @desc
* @type number[]
*
* @param z
* @text レイヤーの深さ
* @desc
* @type number[]
*
* @param MapTileID
* @text マップタイルID
* @desc
* @type number[]
*
* @param MapID
* @text マップID
* @desc
* @type number[]
*
* @param DebugMode
* @text デバッグモード
* @type boolean
*
* @help
* このプラグインは、RPGツクールMZに対応しています。
*
* パラメーターで座標、座標、レイヤーの深さ、マップタイルIDを指定します。
* 指定した座標のレイヤーの深さに、指定したマップタイルを変更します。
*
* ■パラメータ
*
* ・スイッチID :マップタイルが変更されているかどうかを表す
* スイッチのIDを入力します。
* ・x座標 マップタイルを変更する位置のx座標を入力します。
* ・y座標 マップタイルを変更する位置のy座標を入力します。
* ・z座標 :マップタイルを変更するレイヤーを入力します。
* 03でレイヤー14を表します。
* ・マップタイルID変更後のマップタイルIDを入力します。
* マップタイルIDについては下記URLが参考になります。
* https://github.com/tonbijp/RPGMakerMZ/blob/master/Reference/Tilemap.md
* ・マップID マップタイルを変更するマップのIDを入力します。
* ・デバッグモードデバッグモードのON/OFFを選択します。
* デバッグモードを押すとテストプレイ時に入力内容の
* チェックができるログをコンソールに出力します。
*
* ■使用方法と入力例
* 1)パラメータを設定してください。
* デバッグモード以外のパラメータは配列です。一つのマップタイルの変更内容は、
* 全ての配列の同じ要素番号に入力してください。
*
* 【入力例】
* ・スイッチID ["1","2"]
* ・x座標 ["3","20"]
* ・y座標 ["6","3"]
* ・z座標 ["2","1"]
* ・マップタイルID["762","54"]
* ・マップID ["1","3"]
* ・デバッグモードfalse
*
* 上記の入力の場合、スイッチID:002がONのとき、マップID003のx座標20、y座標3、
* 下から番目のレイヤーのマップタイルをマップタイルID52に変更します。
*
* 2)プラグインコマンドを使ってください。
* ・プラグインコマンド[set]
* 指定したスイッチIDをONにしたあと、パラメータに従ってマップタイルを変更します。
*
* ・プラグインコマンド[reset]
* 指定したスイッチIDをONにしたあと、パラメータに従ってマップタイルを変更します。
*
* ■ライセンス表記
* このプラグインは MIT ライセンスで配布されます。
* ご自由にお使いください。
* http://opensource.org/licenses/mit-license.php
*/
(() => {
"use strict";
const pluginName = "ChangeMapTile";
//パラメータから配列を受け取ります。
const Param = PluginManager.parameters(pluginName);
const ParamSwitchID = JSON.parse(Param["switchID"]);
const ParamX = JSON.parse(Param["x"]);
const ParamY = JSON.parse(Param["y"]);
const ParamZ = JSON.parse(Param["z"]);
const ParamMapTileID = JSON.parse(Param["MapTileID"]);
const ParamMapID = JSON.parse(Param["MapID"]);
//=======================================================================
//デバッグモード設定
//
if (Param["DebugMode"] !== "true") {
if (!window.console) {
window.console = {};
}
var methods = ["log", "debug", "warn", "info"];
for (var i = 0; i < methods.length; i++) {
console[methods[i]] = function () {};
}
}
console.log(pluginName);
//=======================================================================
// マップタイルを変更する実処理 x=x座標 y=y座標 z=レイヤーの深さ tileID=変更後のマップタイルID
//
const setDataMap = (x, y, z, tileId) => {
console.log(
"functionnamesetDataMap|x" +
x +
"|y" +
y +
"|z" +
z +
"|tileID" +
tileId
);
$dataMap.data[
(Number(z) * $dataMap.height + Number(y)) * $dataMap.width + Number(x)
] = Number(tileId);
};
//=======================================================================
// 主処理。パラメータから設定値を受け取り、各種チェックのあと、setDataMapに引き渡す。
//
Game_Map.prototype._changeMapTile = function () {
console.log("functionnameGame_Map.prototype._changeMapTile");
if (ParamSwitchID.length !== 0) {
//要素数チェック。各パラメータの要素数が合っているかを確認する。
if (
ParamSwitchID.length === ParamX.length &&
ParamSwitchID.length === ParamY.length &&
ParamSwitchID.length === ParamZ.length &&
ParamSwitchID.length === ParamMapTileID.length &&
ParamSwitchID.length === ParamMapID.length
) {
console.log(
"要素数チェックOK ParamSwitchID.length = " + ParamSwitchID.length
);
} else {
console.error("要素数チェックNG");
console.log("ParamSwitchID.length = " + ParamSwitchID.length);
console.log("ParamX.length = " + ParamX.length);
console.log("ParamY.length = " + ParamY.length);
console.log("ParamZ.length = " + ParamZ.length);
console.log("ParamMapTileID.length = " + ParamMapTileID.length);
console.log("ParamMapID.length = " + ParamMapID.length);
return;
}
for (let i = 0; i < ParamSwitchID.length; i++) {
//パラメータ配列の数だけsetDataMapを繰り返す。
//型チェック。値に数値以外のものが入っていた場合はエラーを返します。
if (
typeof Number(ParamSwitchID[i]) !== "number" ||
typeof Number(ParamX[i]) !== "number" ||
typeof Number(ParamY[i]) !== "number" ||
typeof Number(ParamZ[i]) !== "number" ||
typeof Number(ParamMapTileID[i]) !== "number" ||
typeof Number(ParamMapID[i]) !== "number"
) {
console.error("パラメータの値が数値ではない項目があります。");
console.log(
"ParamSwitchID[" + i + "]:" + Number(typeof ParamSwitchID[i])
);
console.log("ParamX[" + i + "]:" + Number(typeof ParamX[i]));
console.log("ParamY[" + i + "]:" + Number(typeof ParamY[i]));
console.log("ParamZ[" + i + "]:" + Number(typeof ParamZ[i]));
console.log(
"ParamMapTileID[" + i + "]:" + Number(typeof ParamMapTileID[i])
);
console.log("ParamMapID[" + i + "]:" + Number(typeof ParamMapID[i]));
} else if (
$gameSwitches.value(ParamSwitchID[i]) &&
Number(ParamMapID[i]) === $gameMap._mapId
) {
//設定したIDのスイッチがON かつ 今のマップが設定したマップIDであればマップタイルを変更する。
console.log("ParamSwitchID[" + i + "]:" + ParamSwitchID[i]);
console.log("ParamX[" + i + "]:" + ParamX[i]);
console.log("ParamY[" + i + "]:" + ParamY[i]);
console.log("ParamZ[" + i + "]:" + ParamZ[i]);
console.log("ParamMapTileID[" + i + "]:" + ParamMapTileID[i]);
console.log("ParamMapID[" + i + "]:" + ParamMapID[i]);
if (!this._originalTileID) {
this._originalTileID = {};
} else if (typeof this._originalTileID[i] === "undefined") {
this._originalTileID[i] =
SceneManager._scene._spriteset._tilemap._readMapData(
ParamX[i],
ParamY[i],
ParamZ[i]
);
}
setDataMap(ParamX[i], ParamY[i], ParamZ[i], ParamMapTileID[i]);
} else {
//設定したIDのスイッチがOFF もしくは 今のマップが設定したマップIDではない場合。
console.log(
"設定したIDのスイッチがOFF もしくは 今のマップが設定したマップIDではない場合。"
);
console.log("ParamSwitchID[" + i + "]:" + ParamSwitchID[i]);
console.log("ParamX[" + i + "]:" + ParamX[i]);
console.log("ParamY[" + i + "]:" + ParamY[i]);
console.log("ParamZ[" + i + "]:" + ParamZ[i]);
console.log("ParamMapTileID[" + i + "]:" + ParamMapTileID[i]);
console.log("ParamMapID[" + i + "]:" + ParamMapID[i]);
if (!this._originalTileID) {
this._originalTileID = {};
} else if (typeof this._originalTileID[i] !== "undefined") {
setDataMap(
ParamX[i],
ParamY[i],
ParamZ[i],
this._originalTileID[i]
);
}
}
}
} else {
console.error("パラメータの値が設定されていません");
}
};
//=======================================================================
// コマンドでイベントから_changeMapTileを呼び出す。
//
PluginManager.registerCommand(pluginName, "set", (args) => {
$gameSwitches.setValue(args.setSwitchID, true);
$gameMap._changeMapTile();
});
PluginManager.registerCommand(pluginName, "reset", (args) => {
$gameSwitches.setValue(args.resetSwitchID, false);
$gameMap._changeMapTile();
});
//=======================================================================
// マップのロードのために呼び出される。
//
const _Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded;
Scene_Map.prototype.onMapLoaded = function () {
console.log("functionnameScene_Map.prototype.onMapLoaded");
_Scene_Map_onMapLoaded.call(this);
$gameMap._changeMapTile();
};
})();