This commit is contained in:
YouWei Zhao 2019-03-19 23:17:47 -04:00
parent a1e144f2da
commit 49d497b1a8
3 changed files with 98 additions and 94 deletions

View File

@ -29,106 +29,112 @@ exportMap.onclick=function(){
filestr += ']' + (yy == sy ? '' : ',\n'); filestr += ']' + (yy == sy ? '' : ',\n');
} }
pout.value = filestr; pout.value = filestr;
mapEditArea.mapArr = filestr; mapEditArea.mapArr(filestr);
exportMap.isExport = true; exportMap.isExport = true;
mapEditArea.error = 0; mapEditArea.error(0);
tip.whichShow = 2; tip.whichShow = 2;
} }
var mapEditArea = new Vue({ var mapEditArea = document.getElementById('mapEditArea')
el: '#mapEditArea', mapEditArea.errors=[ // 编号1,2
data: { "格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)",
mapArr: '', "当前有未定义ID在地图区域显示红块请修改ID或者到icons.js和maps.js中进行定义"
errors: [ // 编号1,2,3,4 ]
"格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)", mapEditArea.formatTimer=null
"当前有未定义ID在地图区域显示红块请修改ID或者到icons.js和maps.js中进行定义", mapEditArea._mapArr=''
"ID越界在地图区域显示红块当前编辑器暂时支持编号小于400请修改编号", mapEditArea.mapArr=function(value){
// "发生错误!", if(value!=null){
], var val=value
error: 0, var oldval=mapEditArea._mapArr
formatTimer: null, if (val==oldval) return;
},
watch: {
mapArr: function (val, oldval) {
if (val == '') return;
if (exportMap.isExport) {
exportMap.isExport = false;
return;
}
if (mapEditArea.formatArr()) {
mapEditArea.error = 0;
setTimeout(function () { if (exportMap.isExport) {
mapEditArea.mapArr = mapEditArea.formatArr(); exportMap.isExport = false;
mapEditArea.drawMap(); return;
tip.whichShow = 8
}, 1000);
mapEditArea.formatTimer = setTimeout(function () {
pout.value = mapEditArea.formatArr();
}, 5000); //5s后再格式化不然光标跳到最后很烦
} else {
mapEditArea.error = 1;
}
},
error: function () {
// console.log(mapEditArea.mapArr);
if (mapEditArea.error>0)
printe(mapEditArea.errors[mapEditArea.error-1])
} }
}, if (mapEditArea.formatArr()) {
methods: { mapEditArea.error(0);
drawMap: function () {
// var mapArray = mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' ');
var mapArray = JSON.parse('[' + mapEditArea.mapArr + ']');
var sy=editor.map.length,sx=editor.map[0].length;
for (var y = 0; y < sy; y++)
for (var x = 0; x < sx; x++) {
var num = mapArray[y][x];
if (num == 0)
editor.map[y][x] = 0;
else if (typeof(editor.indexs[num][0]) == 'undefined') {
mapEditArea.error = 2;
editor.map[y][x] = undefined;
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
}
editor.updateMap(); setTimeout(function () {
if (mapEditArea.formatArr())mapEditArea.mapArr(mapEditArea.formatArr());
}, mapEditArea.drawMap();
formatArr: function () { tip.whichShow = 8
var formatArrStr = ''; }, 1000);
clearTimeout(mapEditArea.formatTimer); clearTimeout(mapEditArea.formatTimer);
var si=editor.map.length,sk=editor.map[0].length; mapEditArea.formatTimer = setTimeout(function () {
if (mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; pout.value = mapEditArea.formatArr();
var arr = mapEditArea.mapArr.replace(/\s+/g, '').split('],['); }, 5000); //5s后再格式化不然光标跳到最后很烦
} else {
if (arr.length != si) return; mapEditArea.error(1);
for (var i = 0; i < si; i++) {
var a = [];
formatArrStr += '[';
if (i == 0 || i == si-1) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
else a = arr[i].split(/\D+/);
if (a.length != sk) {
formatArrStr = '';
return;
}
for (var k = 0; k < sk; k++) {
var num = parseInt(a[k]);
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk-1 ? '' : ',');
}
formatArrStr += ']' + (i == si-1 ? '' : ',\n');
}
return formatArrStr;
} }
mapEditArea._mapArr=value
} }
}); return mapEditArea._mapArr
}
pout.oninput=function(){
mapEditArea.mapArr(pout.value)
}
mapEditArea._error=0
mapEditArea.error=function(value){
if(value!=null){
mapEditArea._error=value
if (value>0)
printe(mapEditArea.errors[value-1])
}
return mapEditArea._error
}
mapEditArea.drawMap= function () {
// var mapArray = mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ');
var mapArray = JSON.parse('[' + mapEditArea.mapArr() + ']');
var sy=editor.map.length,sx=editor.map[0].length;
for (var y = 0; y < sy; y++)
for (var x = 0; x < sx; x++) {
var num = mapArray[y][x];
if (num == 0)
editor.map[y][x] = 0;
else if (typeof(editor.indexs[num][0]) == 'undefined') {
mapEditArea.error(2);
editor.map[y][x] = undefined;
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
}
editor.updateMap();
}
mapEditArea.formatArr= function () {
var formatArrStr = '';
console.log(1)
var si=editor.map.length,sk=editor.map[0].length;
if (mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false;
var arr = mapEditArea.mapArr().replace(/\s+/g, '').split('],[');
if (arr.length != si) return;
for (var i = 0; i < si; i++) {
var a = [];
formatArrStr += '[';
if (i == 0 || i == si-1) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
else a = arr[i].split(/\D+/);
if (a.length != sk) {
formatArrStr = '';
return;
}
for (var k = 0; k < sk; k++) {
var num = parseInt(a[k]);
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk-1 ? '' : ',');
}
formatArrStr += ']' + (i == si-1 ? '' : ',\n');
}
return formatArrStr;
}
var copyMap=document.getElementById('copyMap') var copyMap=document.getElementById('copyMap')
copyMap.err='' copyMap.err=''
copyMap.onclick=function(){ copyMap.onclick=function(){
tip.whichShow = 0; tip.whichShow = 0;
if (pout.value.trim() != '') { if (pout.value.trim() != '') {
if (mapEditArea.error) { if (mapEditArea.error()) {
copyMap.err = mapEditArea.errors[mapEditArea.error - 1]; copyMap.err = mapEditArea.errors[mapEditArea.error() - 1];
tip.whichShow = 5 tip.whichShow = 5
return; return;
} }
@ -160,9 +166,9 @@ clearMapButton.onclick=function () {
clearTimeout(mapEditArea.formatTimer); clearTimeout(mapEditArea.formatTimer);
clearTimeout(tip.timer); clearTimeout(tip.timer);
pout.value = ''; pout.value = '';
mapEditArea.mapArr = ''; mapEditArea.mapArr('');
tip.whichShow = 4; tip.whichShow = 4;
mapEditArea.error = 0; mapEditArea.error(0);
} }
var deleteMap=document.getElementById('deleteMap') var deleteMap=document.getElementById('deleteMap')
deleteMap.onclick=function () { deleteMap.onclick=function () {

View File

@ -18,9 +18,8 @@
<div id="arrEditor"> <div id="arrEditor">
<table class="col" id='arrColMark'></table> <table class="col" id='arrColMark'></table>
<table class="row" id='arrRowMark'></table> <table class="row" id='arrRowMark'></table>
<div id="mapEditArea" v-cloak> <div id="mapEditArea">
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout"></textarea>
<!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> -->
</div> </div>
<div id="editTip"> <div id="editTip">
<input id='newFileName' placeholder="新楼层id" style="width: 100px"/> <input id='newFileName' placeholder="新楼层id" style="width: 100px"/>

View File

@ -17,9 +17,8 @@
<div id="arrEditor"> <div id="arrEditor">
<table class="col" id='arrColMark'></table> <table class="col" id='arrColMark'></table>
<table class="row" id='arrRowMark'></table> <table class="row" id='arrRowMark'></table>
<div id="mapEditArea" v-cloak> <div id="mapEditArea">
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout"></textarea>
<!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> -->
</div> </div>
<div id="editTip"> <div id="editTip">
<input type="button" value="新建空白地图" id='newMap'/> <input type="button" value="新建空白地图" id='newMap'/>