bigmap-editor
drawEventBlock, exportMap, formatMap 等对于的大地图的支持
This commit is contained in:
parent
702c22d49d
commit
4bb60bd2f7
@ -245,6 +245,18 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
|||||||
"_type": "textarea",
|
"_type": "textarea",
|
||||||
"_data": "显示在状态栏中的层数"
|
"_data": "显示在状态栏中的层数"
|
||||||
},
|
},
|
||||||
|
"width": {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "false",
|
||||||
|
"_data": "地图x方向大小,这里不能更改,仅能在新建地图时设置,null视为13"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "false",
|
||||||
|
"_data": "地图y方向大小,这里不能更改,仅能在新建地图时设置,null视为13"
|
||||||
|
},
|
||||||
"canFlyTo": {
|
"canFlyTo": {
|
||||||
"_leaf": true,
|
"_leaf": true,
|
||||||
"_type": "checkbox",
|
"_type": "checkbox",
|
||||||
|
|||||||
@ -163,9 +163,10 @@ editor.prototype.mapInit = function () {
|
|||||||
ec.clearRect(0, 0, core.bigmap.width*32, core.bigmap.height*32);
|
ec.clearRect(0, 0, core.bigmap.width*32, core.bigmap.height*32);
|
||||||
document.getElementById('event2').getContext('2d').clearRect(0, 0, core.bigmap.width*32, core.bigmap.height*32);
|
document.getElementById('event2').getContext('2d').clearRect(0, 0, core.bigmap.width*32, core.bigmap.height*32);
|
||||||
editor.map = [];
|
editor.map = [];
|
||||||
for (var y = 0; y < 13; y++) {
|
var sy=editor.currentFloorData.map.length,sy=editor.currentFloorData.map[0].length;
|
||||||
|
for (var y = 0; y < sy; y++) {
|
||||||
editor.map[y] = [];
|
editor.map[y] = [];
|
||||||
for (var x = 0; x < 13; x++) {
|
for (var x = 0; x < sx; x++) {
|
||||||
editor.map[y][x] = 0;
|
editor.map[y][x] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +203,7 @@ editor.prototype.drawEventBlock = function () {
|
|||||||
for (var i=0;i<13;i++) {
|
for (var i=0;i<13;i++) {
|
||||||
for (var j=0;j<13;j++) {
|
for (var j=0;j<13;j++) {
|
||||||
var color=null;
|
var color=null;
|
||||||
var loc=i+","+j;
|
var loc=(i+core.bigmap.offsetX/32)+","+(j+core.bigmap.offsetY/32);
|
||||||
if (core.isset(editor.currentFloorData.events[loc]))
|
if (core.isset(editor.currentFloorData.events[loc]))
|
||||||
color = '#FF0000';
|
color = '#FF0000';
|
||||||
else if (core.isset(editor.currentFloorData.changeFloor[loc]))
|
else if (core.isset(editor.currentFloorData.changeFloor[loc]))
|
||||||
@ -255,8 +256,8 @@ editor.prototype.updateMap = function () {
|
|||||||
}
|
}
|
||||||
// 绘制地图 start
|
// 绘制地图 start
|
||||||
var eventCtx = document.getElementById('event').getContext("2d");
|
var eventCtx = document.getElementById('event').getContext("2d");
|
||||||
for (var y = 0; y < 13; y++)
|
for (var y = 0; y < editor.map.length; y++)
|
||||||
for (var x = 0; x < 13; x++) {
|
for (var x = 0; x < editor.map[0].length; x++) {
|
||||||
var tileInfo = editor.map[y][x];
|
var tileInfo = editor.map[y][x];
|
||||||
if (false && isAutotile(tileInfo)) {
|
if (false && isAutotile(tileInfo)) {
|
||||||
addIndexToAutotileInfo(x, y);
|
addIndexToAutotileInfo(x, y);
|
||||||
@ -848,6 +849,7 @@ editor.prototype.listen = function () {
|
|||||||
core.bigmap.offsetY = core.clamp(core.bigmap.offsetY+32*y, 0, 32*core.bigmap.height-416);
|
core.bigmap.offsetY = core.clamp(core.bigmap.offsetY+32*y, 0, 32*core.bigmap.height-416);
|
||||||
core.control.updateViewport();
|
core.control.updateViewport();
|
||||||
editor.buildMark();
|
editor.buildMark();
|
||||||
|
editor.drawEventBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewportButtons=document.getElementById('viewportButtons');
|
var viewportButtons=document.getElementById('viewportButtons');
|
||||||
|
|||||||
@ -695,19 +695,20 @@ editor_file = function (editor, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var formatMap = function (mapArr) {
|
var formatMap = function (mapArr) {
|
||||||
//把13*13或者1*169数组格式化
|
//把二维数组格式化
|
||||||
var formatArrStr = '';
|
var formatArrStr = '';
|
||||||
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');
|
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');
|
||||||
for (var i = 0; i < 13; i++) {
|
var si=mapArr.length-1,sk=mapArr[0].length-1;
|
||||||
|
for (var i = 0; i <= si; i++) {
|
||||||
var a = [];
|
var a = [];
|
||||||
formatArrStr += ' [';
|
formatArrStr += ' [';
|
||||||
if (i == 0 || i == 12) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
if (i == 0 || i == si) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
||||||
else a = arr[i].split(/\D+/);
|
else a = arr[i].split(/\D+/);
|
||||||
for (var k = 0; k < 13; k++) {
|
for (var k = 0; k <= sk; k++) {
|
||||||
var num = parseInt(a[k]);
|
var num = parseInt(a[k]);
|
||||||
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == 12 ? '' : ',');
|
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk ? '' : ',');
|
||||||
}
|
}
|
||||||
formatArrStr += ']' + (i == 12 ? '' : ',\n');
|
formatArrStr += ']' + (i == si ? '' : ',\n');
|
||||||
}
|
}
|
||||||
return formatArrStr;
|
return formatArrStr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,11 +67,12 @@ var exportMap = new Vue({
|
|||||||
methods: {
|
methods: {
|
||||||
exportMap: function () {
|
exportMap: function () {
|
||||||
editor.updateMap();
|
editor.updateMap();
|
||||||
|
var sx=editor.map.length-1,sy=editor.map[0].length-1;
|
||||||
|
|
||||||
var filestr = '';
|
var filestr = '';
|
||||||
for (var yy = 0; yy < 13; yy++) {
|
for (var yy = 0; yy <= sy; yy++) {
|
||||||
filestr += '['
|
filestr += '['
|
||||||
for (var xx = 0; xx < 13; xx++) {
|
for (var xx = 0; xx <= sx; xx++) {
|
||||||
var mapxy = editor.map[yy][xx];
|
var mapxy = editor.map[yy][xx];
|
||||||
if (typeof(mapxy) == typeof({})) {
|
if (typeof(mapxy) == typeof({})) {
|
||||||
if ('idnum' in mapxy) mapxy = mapxy.idnum;
|
if ('idnum' in mapxy) mapxy = mapxy.idnum;
|
||||||
@ -86,10 +87,10 @@ var exportMap = new Vue({
|
|||||||
}
|
}
|
||||||
mapxy = String(mapxy);
|
mapxy = String(mapxy);
|
||||||
mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy;
|
mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy;
|
||||||
filestr += mapxy + (xx == 12 ? '' : ',')
|
filestr += mapxy + (xx == sx ? '' : ',')
|
||||||
}
|
}
|
||||||
|
|
||||||
filestr += ']' + (yy == 12 ? '' : ',\n');
|
filestr += ']' + (yy == sy ? '' : ',\n');
|
||||||
}
|
}
|
||||||
pout.value = filestr;
|
pout.value = filestr;
|
||||||
editArea.mapArr = filestr;
|
editArea.mapArr = filestr;
|
||||||
@ -104,7 +105,7 @@ var editArea = new Vue({
|
|||||||
data: {
|
data: {
|
||||||
mapArr: '',
|
mapArr: '',
|
||||||
errors: [ // 编号1,2,3,4
|
errors: [ // 编号1,2,3,4
|
||||||
"格式错误!请使用正确格式(13*13数组,如不清楚,可先点击生成地图查看正确格式)",
|
"格式错误!请使用正确格式(width*height数组,如不清楚,可先点击生成地图查看正确格式)",
|
||||||
"当前有未定义ID(在地图区域显示红块),请修改ID或者到icons.js和maps.js中进行定义!",
|
"当前有未定义ID(在地图区域显示红块),请修改ID或者到icons.js和maps.js中进行定义!",
|
||||||
"ID越界(在地图区域显示红块),当前编辑器暂时支持编号小于400,请修改编号!",
|
"ID越界(在地图区域显示红块),当前编辑器暂时支持编号小于400,请修改编号!",
|
||||||
// "发生错误!",
|
// "发生错误!",
|
||||||
@ -145,8 +146,9 @@ var editArea = new Vue({
|
|||||||
|
|
||||||
// var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' ');
|
// var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' ');
|
||||||
var mapArray = JSON.parse('[' + that.mapArr + ']');
|
var mapArray = JSON.parse('[' + that.mapArr + ']');
|
||||||
for (var y = 0; y < 13; y++)
|
var sy=editor.map.length,sx=editor.map[0].length;
|
||||||
for (var x = 0; x < 13; x++) {
|
for (var y = 0; y < sy; y++)
|
||||||
|
for (var x = 0; x < sx; x++) {
|
||||||
var num = mapArray[y][x];
|
var num = mapArray[y][x];
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
editor.map[y][x] = 0;
|
editor.map[y][x] = 0;
|
||||||
@ -166,25 +168,26 @@ var editArea = new Vue({
|
|||||||
var formatArrStr = '';
|
var formatArrStr = '';
|
||||||
var that = this;
|
var that = this;
|
||||||
clearTimeout(that.formatTimer);
|
clearTimeout(that.formatTimer);
|
||||||
if (this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != 169) return false;
|
var si=this.mapArr.length,sk=this.mapArr[0].length;
|
||||||
|
if (this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false;
|
||||||
var arr = this.mapArr.replace(/\s+/g, '').split('],[');
|
var arr = this.mapArr.replace(/\s+/g, '').split('],[');
|
||||||
|
|
||||||
if (arr.length != 13) return;
|
if (arr.length != si) return;
|
||||||
for (var i = 0; i < 13; i++) {
|
for (var i = 0; i < si; i++) {
|
||||||
var a = [];
|
var a = [];
|
||||||
formatArrStr += '[';
|
formatArrStr += '[';
|
||||||
if (i == 0 || i == 12) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
if (i == 0 || i == si-1) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
||||||
else a = arr[i].split(/\D+/);
|
else a = arr[i].split(/\D+/);
|
||||||
if (a.length != 13) {
|
if (a.length != sk) {
|
||||||
formatArrStr = '';
|
formatArrStr = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var k = 0; k < 13; k++) {
|
for (var k = 0; k < sk; k++) {
|
||||||
var num = parseInt(a[k]);
|
var num = parseInt(a[k]);
|
||||||
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == 12 ? '' : ',');
|
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk-1 ? '' : ',');
|
||||||
}
|
}
|
||||||
formatArrStr += ']' + (i == 12 ? '' : ',\n');
|
formatArrStr += ']' + (i == si-1 ? '' : ',\n');
|
||||||
}
|
}
|
||||||
return formatArrStr;
|
return formatArrStr;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user