editArea-1

This commit is contained in:
YouWei Zhao 2019-03-19 22:36:13 -04:00
parent b61a9afea8
commit a1e144f2da
5 changed files with 35 additions and 39 deletions

View File

@ -54,7 +54,7 @@ body {
height: 630px; height: 630px;
} }
#editArea { #mapEditArea {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 400px; height: 400px;
@ -107,7 +107,7 @@ body {
top: 530px; top: 530px;
} }
#editArea p { #mapEditArea p {
margin: 10px; margin: 10px;
display: block; display: block;
width: 70%; width: 70%;

View File

@ -37,7 +37,7 @@ body {
position: absolute; position: absolute;
} }
#editArea { #mapEditArea {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 70%; height: 70%;
@ -64,7 +64,7 @@ body {
overflow: auto; overflow: auto;
} }
#editArea p { #mapEditArea p {
margin: 10px; margin: 10px;
display: block; display: block;
width: 70%; width: 70%;

View File

@ -29,13 +29,13 @@ exportMap.onclick=function(){
filestr += ']' + (yy == sy ? '' : ',\n'); filestr += ']' + (yy == sy ? '' : ',\n');
} }
pout.value = filestr; pout.value = filestr;
editArea.mapArr = filestr; mapEditArea.mapArr = filestr;
exportMap.isExport = true; exportMap.isExport = true;
editArea.error = 0; mapEditArea.error = 0;
tip.whichShow = 2; tip.whichShow = 2;
} }
var editArea = new Vue({ var mapEditArea = new Vue({
el: '#editArea', el: '#mapEditArea',
data: { data: {
mapArr: '', mapArr: '',
errors: [ // 编号1,2,3,4 errors: [ // 编号1,2,3,4
@ -49,39 +49,36 @@ var editArea = new Vue({
}, },
watch: { watch: {
mapArr: function (val, oldval) { mapArr: function (val, oldval) {
var that = this;
if (val == '') return; if (val == '') return;
if (exportMap.isExport) { if (exportMap.isExport) {
exportMap.isExport = false; exportMap.isExport = false;
return; return;
} }
if (that.formatArr()) { if (mapEditArea.formatArr()) {
that.error = 0; mapEditArea.error = 0;
setTimeout(function () { setTimeout(function () {
that.mapArr = that.formatArr(); mapEditArea.mapArr = mapEditArea.formatArr();
that.drawMap(); mapEditArea.drawMap();
tip.whichShow = 8 tip.whichShow = 8
}, 1000); }, 1000);
that.formatTimer = setTimeout(function () { mapEditArea.formatTimer = setTimeout(function () {
pout.value = that.formatArr(); pout.value = mapEditArea.formatArr();
}, 5000); //5s后再格式化不然光标跳到最后很烦 }, 5000); //5s后再格式化不然光标跳到最后很烦
} else { } else {
that.error = 1; mapEditArea.error = 1;
} }
}, },
error: function () { error: function () {
// console.log(editArea.mapArr); // console.log(mapEditArea.mapArr);
if (this.error>0) if (mapEditArea.error>0)
printe(this.errors[this.error-1]) printe(mapEditArea.errors[mapEditArea.error-1])
} }
}, },
methods: { methods: {
drawMap: function () { drawMap: function () {
var that = this; // var mapArray = mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' ');
var mapArray = JSON.parse('[' + mapEditArea.mapArr + ']');
// var mapArray = that.mapArr.split(/\D+/).join(' ').trim().split(' ');
var mapArray = JSON.parse('[' + that.mapArr + ']');
var sy=editor.map.length,sx=editor.map[0].length; var sy=editor.map.length,sx=editor.map[0].length;
for (var y = 0; y < sy; y++) for (var y = 0; y < sy; y++)
for (var x = 0; x < sx; x++) { for (var x = 0; x < sx; x++) {
@ -89,7 +86,7 @@ var editArea = new Vue({
if (num == 0) if (num == 0)
editor.map[y][x] = 0; editor.map[y][x] = 0;
else if (typeof(editor.indexs[num][0]) == 'undefined') { else if (typeof(editor.indexs[num][0]) == 'undefined') {
that.error = 2; mapEditArea.error = 2;
editor.map[y][x] = undefined; editor.map[y][x] = undefined;
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
} }
@ -99,11 +96,10 @@ var editArea = new Vue({
}, },
formatArr: function () { formatArr: function () {
var formatArrStr = ''; var formatArrStr = '';
var that = this; clearTimeout(mapEditArea.formatTimer);
clearTimeout(that.formatTimer);
var si=editor.map.length,sk=editor.map[0].length; var si=editor.map.length,sk=editor.map[0].length;
if (this.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false; if (mapEditArea.mapArr.split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false;
var arr = this.mapArr.replace(/\s+/g, '').split('],['); var arr = mapEditArea.mapArr.replace(/\s+/g, '').split('],[');
if (arr.length != si) return; if (arr.length != si) return;
for (var i = 0; i < si; i++) { for (var i = 0; i < si; i++) {
@ -131,8 +127,8 @@ copyMap.err=''
copyMap.onclick=function(){ copyMap.onclick=function(){
tip.whichShow = 0; tip.whichShow = 0;
if (pout.value.trim() != '') { if (pout.value.trim() != '') {
if (editArea.error) { if (mapEditArea.error) {
copyMap.err = editArea.errors[editArea.error - 1]; copyMap.err = mapEditArea.errors[mapEditArea.error - 1];
tip.whichShow = 5 tip.whichShow = 5
return; return;
} }
@ -161,12 +157,12 @@ clearMapButton.onclick=function () {
;printf('地图清除成功'); ;printf('地图清除成功');
}); });
editor.updateMap(); editor.updateMap();
clearTimeout(editArea.formatTimer); clearTimeout(mapEditArea.formatTimer);
clearTimeout(tip.timer); clearTimeout(tip.timer);
pout.value = ''; pout.value = '';
editArea.mapArr = ''; mapEditArea.mapArr = '';
tip.whichShow = 4; tip.whichShow = 4;
editArea.error = 0; mapEditArea.error = 0;
} }
var deleteMap=document.getElementById('deleteMap') var deleteMap=document.getElementById('deleteMap')
deleteMap.onclick=function () { deleteMap.onclick=function () {

View File

@ -18,7 +18,7 @@
<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="editArea" v-cloak> <div id="mapEditArea" v-cloak>
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea>
<!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> --> <!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> -->
</div> </div>
@ -522,8 +522,8 @@ if (location.protocol.indexOf("http")!=0) {
<script> <script>
//所有全局量 //所有全局量
__all__ = ['Vue', 'fs', 'editor_file', 'editor_mode', 'main', 'core', 'hasOwnProp', 'printf', 'printe', 'editor', 'converter', 'ActionParser', 'MotaActionFunctions', 'MotaActionBlocks']; __all__ = ['Vue', 'fs', 'editor_file', 'editor_mode', 'main', 'core', 'hasOwnProp', 'printf', 'printe', 'editor', 'converter', 'ActionParser', 'MotaActionFunctions', 'MotaActionBlocks'];
__id__ = ['editArea', 'arrRowMark', 'mapRowMark', 'data', 'bg', 'dataSelection', 'blocklyDiv', 'codeAreaHL', 'entryType']; __id__ = ['mapEditArea', 'arrRowMark', 'mapRowMark', 'data', 'bg', 'dataSelection', 'blocklyDiv', 'codeAreaHL', 'entryType'];
__Vue__ = ['editArea', 'exportMap', 'copyMap', 'clearMap', 'deleteMap', 'tip', 'selectBox']; __Vue__ = ['mapEditArea', 'exportMap', 'copyMap', 'clearMap', 'deleteMap', 'tip', 'selectBox'];
//var event = document.getElementById('event'); //var event = document.getElementById('event');
var hasOwnProperty = Object.prototype.hasOwnProperty; var hasOwnProperty = Object.prototype.hasOwnProperty;

View File

@ -17,7 +17,7 @@
<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="editArea" v-cloak> <div id="mapEditArea" v-cloak>
<textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea> <textarea cols="10" rows="10" id="pout" v-model="mapArr"></textarea>
<!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> --> <!-- <p class="warnText" v-if="error">{{ errors[error-1] }}</p> -->
</div> </div>
@ -505,8 +505,8 @@ if (location.protocol.indexOf("http")!=0) {
<script> <script>
//所有全局量 //所有全局量
__all__ = ['Vue', 'fs', 'editor_file', 'editor_mode', 'main', 'core', 'hasOwnProp', 'printf', 'printe', 'editor', 'converter', 'ActionParser', 'MotaActionFunctions', 'MotaActionBlocks']; __all__ = ['Vue', 'fs', 'editor_file', 'editor_mode', 'main', 'core', 'hasOwnProp', 'printf', 'printe', 'editor', 'converter', 'ActionParser', 'MotaActionFunctions', 'MotaActionBlocks'];
__id__ = ['editArea', 'arrRowMark', 'mapRowMark', 'data', 'bg', 'dataSelection', 'blocklyDiv', 'codeAreaHL', 'entryType']; __id__ = ['mapEditArea', 'arrRowMark', 'mapRowMark', 'data', 'bg', 'dataSelection', 'blocklyDiv', 'codeAreaHL', 'entryType'];
__Vue__ = ['editArea', 'exportMap', 'copyMap', 'clearMap', 'deleteMap', 'tip', 'selectBox']; __Vue__ = ['mapEditArea', 'exportMap', 'copyMap', 'clearMap', 'deleteMap', 'tip', 'selectBox'];
//var event = document.getElementById('event'); //var event = document.getElementById('event');
var hasOwnProperty = Object.prototype.hasOwnProperty; var hasOwnProperty = Object.prototype.hasOwnProperty;