diff --git a/_server/README.md b/_server/README.md index 9f9a2475..ec9d1981 100644 --- a/_server/README.md +++ b/_server/README.md @@ -18,15 +18,16 @@ editor.file.loadFloorFile editor.file.saveFloorFile editor.file.saveFloorFileAs ``` -5个编辑模式有关的查询 +6个编辑模式有关的查询 ```javascript editor.file.editItem('redJewel',[],function(a){console.log(a)}); editor.file.editEnemy('redBat',[],function(a){console.log(a)}); editor.file.editLoc(2,0,[],function(a){console.log(a)}); editor.file.editFloor([],function(a){console.log(a)}); editor.file.editTower([],function(a){console.log(a)}); +editor.file.editFunctions([],function(a){console.log(a)}); ``` -5个编辑模式有关的编辑 +6个编辑模式有关的编辑 ```javascript editor.info={images: "terrains", y: 9}; editor.file.changeIdAndIdnum('yellowWall2',16,editor.info,function(a){console.log(a)}); @@ -35,15 +36,17 @@ editor.file.editEnemy('redBat',[['change',"['atk']",20]],function(a){console.log editor.file.editLoc(2,6,[["change","['afterBattle']",null]],function(a){console.log(a)}); editor.file.editFloor([["change","['title']",'样板 33 层']],function(a){console.log(a)}); editor.file.editTower([["change","['values']['lavaDamage']",200]],function(a){console.log(a)}); +editor.file.editFunctions(["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"],function(a){console.log(a)}); ``` ### editor_mode.js -4个生成表格并绑定事件的函数 +5个生成表格并绑定事件的函数 ```javascript editor.mode.loc(); editor.mode.emenyitem(); editor.mode.floor(); editor.mode.tower(); +editor.mode.functions(); ``` 切换模式 ```javascript @@ -52,6 +55,7 @@ editor.mode.onmode('loc'); editor.mode.onmode('emenyitem'); editor.mode.onmode('floor'); editor.mode.onmode('tower'); +editor.mode.onmode('functions'); ``` 在切换模式时,改动才会保存到文件,并且需要刷新页面使得`editor`能看到改动 diff --git a/_server/css/editor_mode.css b/_server/css/editor_mode.css index 724bb347..3a6a86cc 100644 --- a/_server/css/editor_mode.css +++ b/_server/css/editor_mode.css @@ -56,13 +56,29 @@ #left6 #blocklyDiv {height: 480px; width: 940px;float:left;} #left6 #codeArea {width: 99.5%; height: 15.4em;overflow:y;/* resize:none; */clear:both;} -#left6 #multiLineDiv {height: 440px; width: 375px;float:left;} -#left6 #multiLineDiv .CodeMirror { + +#left7 { + /* height: 440px; width: 375px;float:left; */ + left: 5px; + top: 5px; + z-index: 200; + position: fixed; + background-color: rgb(245, 245, 245); + width: 1335px; + height: 780px; +} +#left7 .CodeMirror { /* border-top: 1px solid black; border-bottom: 1px solid black; */ border: 1px solid #eee; - height: 438px; - width: 373px; + height: 700px; + width: 940px; +} + +#left8 { + left: 900px; + top: 1290px; + width: 440px; } .etable table, diff --git a/_server/editor.js b/_server/editor.js index d6130e83..718199a7 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -22,6 +22,7 @@ editor.prototype.init = function(callback){ } var afterMainInit = function(){ + core.floors=JSON.parse(JSON.stringify(core.floors,function(k,v){if(v instanceof Function){return v.toString()}else return v})); editor.main=main; editor.core=core; editor.fs=fs; @@ -154,6 +155,7 @@ editor.prototype.mapInit = function(){ editor.currentFloorData.afterBattle={}; editor.currentFloorData.afterGetItem={}; editor.currentFloorData.afterOpenDoor={}; + editor.currentFloorData.cannotMove={}; } editor.prototype.drawMapBg = function(img){ var bgc = bg.getContext('2d'); diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index dbe164d4..214fbb36 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -357,35 +357,6 @@ editor_blockly.confirm = function (){ setvalue(JSON.stringify(obj)); } -var codeEditor = CodeMirror.fromTextArea(document.getElementById("multiLineCode"), { - lineNumbers: true, - matchBrackets: true, - lineWrapping: true, - continueComments: "Enter", - extraKeys: {"Ctrl-Q": "toggleComment"} -}); -editor_blockly.showCodeEditor = function(){document.getElementById("multiLineDiv").style='';} -editor_blockly.hideCodeEditor = function(){document.getElementById("multiLineDiv").style='z-index:-1;opacity: 0;';} - -var multiLineArgs=[null,null,null]; -editor_blockly.multiLineEdit = function(value,b,f,callback){ - editor_blockly.showCodeEditor(); - codeEditor.setValue(value.split('\\n').join('\n')||''); - multiLineArgs[0]=b; - multiLineArgs[1]=f; - multiLineArgs[2]=callback; -} -editor_blockly.multiLineDone = function(){ - editor_blockly.hideCodeEditor(); - if(!multiLineArgs[0] || !multiLineArgs[1] || !multiLineArgs[2])return; - var newvalue = codeEditor.getValue()||''; - multiLineArgs[2](newvalue,multiLineArgs[0],multiLineArgs[1]) -} -editor_blockly.multiLineCancel = function(){ - multiLineArgs=[null,null,null]; - editor_blockly.hideCodeEditor(); -} - editor_blockly.doubleClickBlock = function (blockId){ var b=editor_blockly.workspace.getBlockById(blockId); console.log(b); @@ -400,7 +371,7 @@ editor_blockly.doubleClickBlock = function (blockId){ if(f){ var value = b.getFieldValue(f); //多行编辑 - editor_blockly.multiLineEdit(value,b,f,function(newvalue,b,f){ + editor_multi.multiLineEdit(value,b,f,function(newvalue,b,f){ if(textStringDict[b.type]!=='RawEvalString_0'){} b.setFieldValue(newvalue.split('\n').join('\\n'),f); }); diff --git a/_server/editor_file.js b/_server/editor_file.js index ce340d8a..2667ec0c 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -3,35 +3,28 @@ editor_file = function(editor, callback){ var editor_file = {}; - - (function(){ - var script = document.createElement('script'); - if (window.location.href.indexOf('_server')!==-1) - script.src = '../project/comment.js'; - else - script.src = 'project/comment.js'; - document.body.appendChild(script); - script.onload = function () { - editor_file.comment=comment_c456ea59_6018_45ef_8bcc_211a24c627dc; - delete(comment_c456ea59_6018_45ef_8bcc_211a24c627dc); - if (editor_file.comment && editor_file.dataComment && callback) - callback(); - } - })(); - (function(){ - var script = document.createElement('script'); - if (window.location.href.indexOf('_server')!==-1) - script.src = '../project/data.comment.js'; - else - script.src = 'project/data.comment.js'; - document.body.appendChild(script); - script.onload = function () { - editor_file.dataComment=data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d; - delete(data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d); - if (editor_file.comment && editor_file.dataComment && callback) - callback(); - } - })(); + var commentjs={ + 'comment':'comment', + 'data.comment':'dataComment', + 'functions.comment':'functionsComment', + } + for(var key in commentjs){ + (function(key){ + var value = commentjs[key]; + var script = document.createElement('script'); + if (window.location.href.indexOf('_server')!==-1) + script.src = '../project/'+key+'.js'; + else + script.src = 'project/'+key+'.js'; + document.body.appendChild(script); + script.onload = function () { + editor_file[value]=eval(key.replace('.','_')+'_c456ea59_6018_45ef_8bcc_211a24c627dc'); + var loaded = Boolean(callback); + for(var key_ in commentjs){loaded = loaded && editor_file[commentjs[key_]]} + if (loaded)callback(); + } + })(key); + } editor_file.getFloorFileList = function(callback){ @@ -396,6 +389,52 @@ editor_file = function(editor, callback){ } //callback([obj,commentObj,err:String]) + //////////////////////////////////////////////////////////////////// + + var fmap = {}; + var fjson = JSON.stringify(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a,function(k,v){if(v instanceof Function){var id_ = editor.guid();fmap[id_]=v.toString();return id_;}else return v},4); + var fobj = JSON.parse(fjson); + editor_file.functionsMap = fmap; + editor_file.functionsJSON = fjson; + var buildlocobj = function(locObj){ + for(var key in locObj){ + if(typeof(locObj[key])!==typeof(''))buildlocobj(locObj[key]); + else locObj[key]=fmap[locObj[key]]; + } + }; + + editor_file.editFunctions = function(actionList,callback){ + /*actionList:[ + ["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"], + ["change","['ui']['drawAbout']","function(){...}"], + ] + 为[]时只查询不修改 + */ + if (!isset(callback)) {printe('未设置callback');throw('未设置callback')}; + if (isset(actionList) && actionList.length > 0){ + saveSetting('functions',actionList,function (err) { + callback([ + (function(){ + var locObj=JSON.parse(fjson); + buildlocobj(locObj); + return locObj; + })(), + editor_file.functionsComment, + err]); + }); + } else { + callback([ + (function(){ + var locObj=JSON.parse(fjson); + buildlocobj(locObj); + return locObj; + })(), + editor_file.functionsComment, + null]); + } + } + //callback([obj,commentObj,err:String]) + //////////////////////////////////////////////////////////////////// var isset = function (val) { @@ -422,6 +461,12 @@ editor_file = function(editor, callback){ } return formatArrStr; } + + var encode = function (str) { + return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { + return String.fromCharCode(parseInt(p1, 16)) + })) + } var saveSetting = function(file,actionList,callback) { console.log(file); @@ -490,6 +535,22 @@ editor_file = function(editor, callback){ }); return; } + if (file=='functions') { + actionList.forEach(function (value) { + if (value[0]!='change')return; + eval("fmap[fobj"+value[1]+']='+JSON.stringify(value[2])); + }); + var fraw = fjson; + for(var id_ in fmap){ + fraw = fraw.replace('"'+id_+'"',fmap[id_]) + } + var datastr='functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = \n'; + datastr+=fraw; + fs.writeFile('project/functions.js',encode(datastr),'base64',function(err, data){ + callback(err); + }); + return; + } if (file=='floors') { actionList.forEach(function (value) { if (value[0]!='change')return; diff --git a/_server/editor_mode.js b/_server/editor_mode.js index a0092c85..9ad234e8 100644 --- a/_server/editor_mode.js +++ b/_server/editor_mode.js @@ -6,7 +6,8 @@ function editor_mode(){ 'loc':'left2', 'emenyitem':'left3', 'floor':'left4', - 'tower':'left5' + 'tower':'left5', + 'functions':'left8' } this._ids={} this.dom={} @@ -74,6 +75,7 @@ editor_mode.prototype.objToTable = function(obj,commentObj){ } input.ondblclick = function(){ editor_blockly.import(guid); + editor_multi.import(guid); } }); } @@ -164,6 +166,10 @@ editor_mode.prototype.doActionList = function(mode,actionList){ editor.file.editTower(actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); break; + case 'functions': + + editor.file.editFunctions(actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null){printe(objs_.slice(-1)[0]);throw(objs_.slice(-1)[0])};printf('修改成功')}); + break; default: break; } @@ -243,6 +249,16 @@ editor_mode.prototype.tower = function(callback){ if (Boolean(callback))callback(); } +editor_mode.prototype.functions = function(callback){ + var objs=[]; + editor.file.editFunctions([],function(objs_){objs=objs_;console.log(objs_)}); + //只查询不修改时,内部实现不是异步的,所以可以这么写 + var tableinfo=editor_mode.objToTable(objs[0],objs[1]); + document.getElementById('table_e260a2be_5690_476a_b04e_dacddede78b3').innerHTML=tableinfo.HTML; + tableinfo.listen(tableinfo.guids); + if (Boolean(callback))callback(); +} + ///////////////////////////////////////////////////////////////////////////// editor_mode.prototype.listen = function(callback){ diff --git a/_server/editor_multi.js b/_server/editor_multi.js new file mode 100644 index 00000000..3a620b8d --- /dev/null +++ b/_server/editor_multi.js @@ -0,0 +1,76 @@ +editor_multi = function(){ + +var editor_multi = {}; + +var codeEditor = CodeMirror.fromTextArea(document.getElementById("multiLineCode"), { + lineNumbers: true, + matchBrackets: true, + lineWrapping: true, + continueComments: "Enter", + extraKeys: {"Ctrl-Q": "toggleComment"} +}); + +editor_multi.id=''; + +editor_multi.show = function(){document.getElementById('left7').style='';} +editor_multi.hide = function(){document.getElementById('left7').style='z-index:-1;opacity: 0;';} + + +editor_multi.import = function(id_){ + var thisTr = document.getElementById(id_); + if(!thisTr)return; + var input = thisTr.children[2].children[0].children[0]; + var field = thisTr.children[0].getAttribute('title'); + var type = input.value && (input.value.slice(0,11)==='"function ('); + if(!type)return; + editor_multi.id=id_; + codeEditor.setValue(JSON.parse(input.value)||''); + editor_multi.show(); +} + +editor_multi.cancel = function(){ + editor_multi.hide(); + editor_multi.id=''; + multiLineArgs=[null,null,null]; +} + +editor_multi.confirm = function (){ + if(!editor_multi.id){ + editor_multi.id=''; + return; + } + if(editor_multi.id==='callFromBlockly'){ + editor_multi.id=''; + editor_multi.multiLineDone(); + return; + } + var setvalue = function(value){ + var thisTr = document.getElementById(editor_multi.id); + editor_multi.id=''; + var input = thisTr.children[2].children[0].children[0]; + input.value = JSON.stringify(value); + editor_multi.hide(); + input.onchange(); + } + setvalue(codeEditor.getValue()||''); +} + +var multiLineArgs=[null,null,null]; +editor_multi.multiLineEdit = function(value,b,f,callback){ + editor_multi.id='callFromBlockly'; + codeEditor.setValue(value.split('\\n').join('\n')||''); + multiLineArgs[0]=b; + multiLineArgs[1]=f; + multiLineArgs[2]=callback; + editor_multi.show(); +} +editor_multi.multiLineDone = function(){ + editor_multi.hide(); + if(!multiLineArgs[0] || !multiLineArgs[1] || !multiLineArgs[2])return; + var newvalue = codeEditor.getValue()||''; + multiLineArgs[2](newvalue,multiLineArgs[0],multiLineArgs[1]) +} + +return editor_multi; +} +//editor_multi=editor_multi(); \ No newline at end of file diff --git a/editor.html b/editor.html index 854ab8cb..73320236 100644 --- a/editor.html +++ b/editor.html @@ -125,14 +125,24 @@
| 条目 | 注释 | 值 |