1.png (58 KB, 下载次数: 27)
2.png (47.18 KB, 下载次数: 24)
3.png (13.05 KB, 下载次数: 22)
//============================================================================= // ceshi.js //============================================================================= /*: * @plugindesc 名称 * @author wangwang作者信息 * * @param cs * @desc 默认参数 * @default 汪汪 * * @help * 帮助的信息 * * */ (function() { ww_tileAdd = {} //临时读取 地图文件 ww_tileAdd._tempMapData = {} //保存的 地图文件数据 ww_tileAdd._mapData = {} //添加记录 ww_tileAdd._mapDataAdd = {} ww_tileAdd._loadListeners = {} //读取时呼叫 ww_tileAdd._callLoadListeners = function(mapId) { var loadListeners = ww_tileAdd._loadListeners[mapId] if (Array.isArray(loadListeners)){ while (loadListeners.length > 0) { var listener = loadListeners.shift(); listener(); } } ww_tileAdd._loadListeners[mapId] = [] }; //添加呼叫 ww_tileAdd.addLoadListener = function(mapId,listner) { if (ww_tileAdd._tempMapData[mapId]) { listner(); } else { if (!Array.isArray(ww_tileAdd._loadListeners[mapId])){ ww_tileAdd._loadListeners[mapId] = [] } ww_tileAdd._loadListeners[mapId].push(listner); if(ww_tileAdd._tempMapData[mapId] !== null){ ww_tileAdd._tempMapDataLoad(mapId) } } }; //读取数据文件 ww_tileAdd.loadDataFile = function(mapId, src) { var xhr = new XMLHttpRequest(); var url = 'data/' + src; xhr.open('GET', url); xhr.overrideMimeType('application/json'); xhr.onload = function() { if (xhr.status < 400) { ww_tileAdd._tempMapData[mapId] = JSON.parse(xhr.responseText); ww_tileAdd.onLoad(ww_tileAdd._tempMapData[mapId]); ww_tileAdd._callLoadListeners(mapId) } }; xhr.onerror = function() { DataManager._errorUrl = DataManager._errorUrl || url; }; ww_tileAdd._tempMapData[mapId] = null; xhr.send(); }; //当读取 ww_tileAdd.onLoad = function(object) { var array; DataManager.extractMetadata(object); array = object.events; if (Array.isArray(array)) { for (var i = 0; i < array.length; i++) { var data = array[i]; if (data && data.note !== undefined) { DataManager.extractMetadata(data); } } } }; //读取临时地图数据 ww_tileAdd._tempMapDataLoad = function (mapId) { if (mapId > 0) { var filename = 'Map%1.json'.format(mapId.padZero(3)); ww_tileAdd.loadDataFile(mapId, filename); } else { ww_tileAdd.makeEmptyMap(mapId); } } //制作空白地图 ww_tileAdd.makeEmptyMap = function(mapId) { ww_tileAdd._tempMapData[mapId] = {}; var MapData = ww_tileAdd._tempMapData[mapId] MapData.data = []; MapData.events = []; MapData.width = 100; MapData.height = 100; MapData.scrollType = 3; }; //是横向循环 ww_tileAdd._isLoopHorizontal = function(scrollType) { return scrollType === 2 || scrollType === 3; }; //是纵向循环 ww_tileAdd._isLoopVertical = function(scrollType) { return scrollType === 1 || scrollType === 3; }; //图块复制(本地图的 x,y,z处图块,复制到x,y,z) ww_tileAdd.tileClone = function (x,y,z,tx,ty,tz){ var tile = ww_tileAdd.loadNowMapTile(x,y,z) var tmapid = $gameMap.mapId() ww_tileAdd.changeMapTile(tmapid,tx,ty,tz,tile) } //图块区域复制(本地图的x,y,宽,高,z区域的图块,复制到x,y,z) ww_tileAdd.tileAreaClone = function (x,y,w,h,z,tx,ty,tz){ var tileArea = ww_tileAdd.loadNowMapTileArea(x,y,z) var tmapid = $gameMap.mapId() ww_tileAdd.changeMapTileArea(tmapid,tx,ty,tz,tileArea) } //图块克隆(fmapid地图的x,y,z的图块,克隆到tmapid地图的x,y,z) ww_tileAdd.tile2 = function (fmapid,x,y,z,tmapid,tx,ty,tz){ ww_tileAdd.addLoadListener( fmapid, function () { var tile = ww_tileAdd.loadMapTile(fmapid,x,y,z) ww_tileAdd.changeMapTile(tmapid,tx,ty,tz,tile) } ) } //图块区域克隆(fmapid地图的x,y,宽,高,z区域的图块,克隆到tmapid地图的x,y,z) ww_tileAdd.tileArea2 = function (fmapid,x,y,w,h,z,tmapid,tx,ty,tz){ ww_tileAdd.addLoadListener( fmapid, function () { var tileArea = ww_tileAdd.loadMapTileArea(fmapid,x,y,w,h,z) if(Array.isArray(tileArea)){ ww_tileAdd.changeMapTileArea(tmapid,tx,ty,tz,tileArea) } } ) } //改变地图图块 ww_tileAdd.changeMapTile = function (mapid,x,y,z,tile){ ww_tileAdd._mapDataAdd[mapid] = ww_tileAdd._mapDataAdd[mapid] || [] var key = ["changeMapTile",x,y,z,tile] ww_tileAdd._mapDataAdd[mapid].push(key) if( mapid == $gameMap.mapId() && DataManager.isMapLoaded()){ ww_tileAdd._changeNowMapTile(x,y,z,tile) $gameMap.requestRefresh() } } //改变地图图块区域 ww_tileAdd.changeMapTileArea = function (mapid,x,y,z,tileArea){ ww_tileAdd._mapDataAdd[mapid] = ww_tileAdd._mapDataAdd[mapid] || [] var key = ["changeMapTileArea",x,y,z,tileArea] ww_tileAdd._mapDataAdd[mapid].push(key) if( mapid == $gameMap.mapId() && DataManager.isMapLoaded()){ ww_tileAdd._changeNowMapTileArea(x,y,z,tileArea) $gameMap.requestRefresh() } } //改变当前地图图块 ww_tileAdd._changeNowMapTile = function(x, y, z, tile) { var tile = tile || 0 if ($dataMap.data) { var width = $dataMap.width; var height =$dataMap.height; var horizontalWrap = ww_tileAdd._isLoopHorizontal($dataMap.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical($dataMap.scrollType) if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { $dataMap.data[(z * height + y) * width + x] = tile } } }; //改变当前地图图块区域 ww_tileAdd._changeNowMapTileArea = function(x0, y0, z, tileArea) { var tileArea = tileArea if ($dataMap.data) { var width = $dataMap.width; var height =$dataMap.height; var horizontalWrap = ww_tileAdd._isLoopHorizontal($dataMap.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical($dataMap.scrollType) for (var wi =0 ;wi<tileArea.length ;wi++){ var tileArea2 = tileArea[wi] if (Array.isArray(tileArea2)){ for (var hi = 0;hi<tileArea2.length;hi++){ var tile = tileArea2[hi] var x = x0 + wi var y = x0 + hi if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { $dataMap.data[(z * height + y) * width + x] = tile } } } } } }; ww_tileAdd.loadMapTile =function (fmapid,x,y,z) { var mapdata = ww_tileAdd._tempMapData[fmapid] if (mapdata){ var data = mapdata.data if (data) { var width = mapdata.width var height = mapdata.height var horizontalWrap = ww_tileAdd._isLoopHorizontal(mapdata.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical(mapdata.scrollType) if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { return data[(z * height + y) * width + x] || 0; } } } return 0; } ww_tileAdd.loadMapTileArea =function (fmapid,x0,y0,w,h,z) { var tileArea =[] for (var wi=0;wi<w;wi++){ tileArea[wi]=[] for (var hi = 0;hi<h;hi++){ tileArea[wi][hi]=0 } } var mapdata = ww_tileAdd._tempMapData[fmapid] if (mapdata){ var data = mapdata.data if (data) { var width = mapdata.width var height = mapdata.height var horizontalWrap = ww_tileAdd._isLoopHorizontal(mapdata.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical(mapdata.scrollType) for (var wi=0;wi<w;wi++){ for (var hi = 0;hi<h;hi++){ var x = x0 + wi var y = x0 + hi if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { tileArea[wi][hi] = data[(z * height + y) * width + x] || 0; } } } } } return tileArea; } ww_tileAdd.loadNowMapTile =function (x,y,z) { var mapdata = $dataMap if (mapdata){ var data = mapdata.data if (data) { var width = mapdata.width var height = mapdata.height var horizontalWrap = ww_tileAdd._isLoopHorizontal(mapdata.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical(mapdata.scrollType) if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { return data[(z * height + y) * width + x] || 0; } } } return 0; } ww_tileAdd.loadNowMapTileArea =function (x0,y0,w,h,z) { var tileArea =[] for (var wi=0;wi<w;wi++){ tileArea[wi]=[] for (var hi = 0;hi<h;hi++){ tileArea[wi][hi]=0 } } var mapdata = $dataMap if (mapdata){ var data = mapdata.data if (data) { var width = mapdata.width var height = mapdata.height var horizontalWrap = ww_tileAdd._isLoopHorizontal(mapdata.scrollType) var verticalWrap = ww_tileAdd._isLoopVertical(mapdata.scrollType) for (var wi=0;wi<w;wi++){ for (var hi = 0;hi<h;hi++){ var x = x0 + wi var y = x0 + hi if (horizontalWrap) { x = x.mod(width); } if (verticalWrap) { y = y.mod(height); } if (x >= 0 && x < width && y >= 0 && y < height) { tileArea[wi][hi] = data[(z * height + y) * width + x] || 0; } } } } } return tileArea; } //当地图读取时的处理 ww_tileAdd._onMapLoaded = function () { var mapid = $gameMap.mapId() var mapDataAdds = ww_tileAdd._mapDataAdd[mapid] if (Array.isArray(mapDataAdds)){ while (mapDataAdds.length > 0) { var mapDataAdd = mapDataAdds.shift(); if(mapDataAdd[0] ){ if( mapDataAdd[0] == "changeMapTile"){ var x = mapDataAdd[1] || 0 var y = mapDataAdd[2] || 0 var z = mapDataAdd[3] || 0 var tile = mapDataAdd[4] || 0 ww_tileAdd._changeNowMapTile(x,y,z,tile) } if( mapDataAdd[0] == "changeMapTileArea"){ var x = mapDataAdd[1] || 0 var y = mapDataAdd[2] || 0 var z = mapDataAdd[3] || 0 var tileArea = mapDataAdd[4] || 0 ww_tileAdd._changeNowMapTileArea(x,y,z,tileArea) } } } } return true; } ww_tileAdd._onMapLoaded2 = Scene_Map.prototype.onMapLoaded Scene_Map.prototype.onMapLoaded = function() { ww_tileAdd._onMapLoaded() ww_tileAdd._onMapLoaded2.call(this); }; })();
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |