From 0a15e303c10b91ae6339d429aedd53134d072054 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 26 Dec 2017 00:55:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E6=9E=84drawMapGui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/fs.js | 101 +++++++++ _server/fsTest_cs.html | 104 +-------- drawMapGUI.html | 493 +++++++++++++++++++++-------------------- 3 files changed, 360 insertions(+), 338 deletions(-) create mode 100644 _server/fs.js diff --git a/_server/fs.js b/_server/fs.js new file mode 100644 index 00000000..3384aa8e --- /dev/null +++ b/_server/fs.js @@ -0,0 +1,101 @@ +(function(){ + fs = {}; + var postsomething = function (data,_ip,callback) { + //callback:function(err, data) + //data:字符串 + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function(){ + switch(xhr.readyState){ + case 4 : + if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) { + if (Boolean(callback)){ + if (xhr.responseText.slice(0,6)=='error:'){ + callback(xhr.responseText,null); + } else { + callback(null,xhr.responseText); + } + } + //printf(xhr.responseText) + }else{ + if (Boolean(callback))callback(xhr.status,null); + //printf('error:' + xhr.status+'
'+(xhr.responseText||'')); + } + break; + } + } + xhr.open('post',_ip); + xhr.setRequestHeader('Content-Type','text/plain'); + if(typeof(data)==typeof([][0]) || data==null)data=JSON.stringify({1:2}); + xhr.send(data); + } + + fs.readFile = function (filename,encoding,callback) { + if (typeof(filename)!=typeof('')) + throw 'Type Error in fs.readFile'; + if (encoding=='utf-8'){ + //读文本文件 + //filename:支持"/"做分隔符 + //callback:function(err, data) + //data:字符串 + var data=''; + data+='type=utf8&'; + data+='name='+filename; + postsomething(data,'/readFile',callback); + return; + } + if (encoding=='base64'){ + //读二进制文件 + //filename:支持"/"做分隔符 + //callback:function(err, data) + //data:base64字符串 + var data=''; + data+='type=base64&'; + data+='name='+filename; + postsomething(data,'/readFile',callback); + return; + } + throw 'Type Error in fs.readFile'; + } + + fs.writeFile = function (filename,datastr,encoding,callback) { + if (typeof(filename)!=typeof('') || typeof(datastr)!=typeof('')) + throw 'Type Error in fs.writeFile'; + if (encoding=='utf-8'){ + //写文本文件 + //filename:支持"/"做分隔符 + //callback:function(err) + //datastr:字符串 + var data=''; + data+='type=utf8&'; + data+='name='+filename; + data+='&value='+datastr; + postsomething(data,'/writeFile',callback); + return; + } + if (encoding=='base64'){ + //写二进制文件 + //filename:支持"/"做分隔符 + //callback:function(err) + //datastr:base64字符串 + var data=''; + data+='type=base64&'; + data+='name='+filename; + data+='&value='+datastr; + postsomething(data,'/writeFile',callback); + return; + } + throw 'Type Error in fs.writeFile'; + } + + fs.readdir = function (path, callback) { + //callback:function(err, data) + //path:支持"/"做分隔符,不以"/"结尾 + //data:[filename1,filename2,..] filename是字符串,只包含文件不包含目录 + if (typeof(path)!=typeof('')) + throw 'Type Error in fs.readdir'; + var data=''; + data+='name='+path; + postsomething(data,'/listFile',function(err, data){callback(err,JSON.parse(data))}); + return; + } +})(); \ No newline at end of file diff --git a/_server/fsTest_cs.html b/_server/fsTest_cs.html index 0ae73da0..fc53ee41 100644 --- a/_server/fsTest_cs.html +++ b/_server/fsTest_cs.html @@ -2,109 +2,7 @@ - + - - - - + + + + +}//core 加载['terrains','animates', 'enemys', 'items', 'npcs'] - - - - - + + + From 24689ce46ef0b71c059fbdd08c9f90894940cc83 Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Tue, 26 Dec 2017 09:15:19 +0800 Subject: [PATCH 2/2] Update drawMapGUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把错误图块标红,改成了点导出,如果失败了,把所有未识别id的块标红5秒 --- drawMapGUI.html | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drawMapGUI.html b/drawMapGUI.html index e0cfeff3..663d824e 100644 --- a/drawMapGUI.html +++ b/drawMapGUI.html @@ -623,7 +623,7 @@ editor.prototype.afterImportGrass = function (callback) { return x + y * (fullX + 1); } - editor.updateMap = function (clearError) { + editor.updateMap = function (error) { //clearGrass(); // console.log(editor.map) for (var xx = 0; xx <= fullX; xx++) { @@ -675,14 +675,16 @@ editor.prototype.afterImportGrass = function (callback) { cxt.drawImage(core.material.images[mapxy.images], 0, mapxy.y*32, 32, 32, xx*32, yy*32, 32, 32); if(typeof(mapxy) != typeof({}) || !('idnum' in mapxy) ) {//未定义块画红块 - if (clearError=='clearError'){ + if (error=='clearError'){ editor.map[editor.m(xx,yy)]=0; cxt.clearRect(xx*32, yy*32, 32, 32); continue; } - cxt.fillStyle = 'rgba(255,0,0,0.8)'; - var tmpNum =6; - cxt.fillRect(xx*32+tmpNum, yy*32+tmpNum, 32-tmpNum*2, 32-tmpNum*2); + if (error=='showError'){ + cxt.fillStyle = 'rgba(255,0,0,0.8)'; + var tmpNum =6; + cxt.fillRect(xx*32+tmpNum, yy*32+tmpNum, 32-tmpNum*2, 32-tmpNum*2); + } } } } @@ -914,6 +916,7 @@ editor.prototype.listen = function() { /* editor.updateMap 现在可以通过editor.updateMap('clearError')把所有错误id置零并绘图 +以及editor.updateMap('showError')显示所有错误 editor.loc editor.pos @@ -939,8 +942,10 @@ editor.init(); methods: { exportMap: function(){ + setTimeout(function(){editor.updateMap();},5000); if(editArea.error) { tip.whichShow = 3; + editor.updateMap('showError'); return; } var filestr=''; @@ -953,10 +958,12 @@ editor.init(); else { // mapxy='!!?'; tip.whichShow = 3; + editor.updateMap('showError'); return; } }else if(typeof(mapxy)=='undefined'){ tip.whichShow = 3; + editor.updateMap('showError'); return; } mapxy=String(mapxy);