From 1165fd443d3892046e07f1fcae658da763983838 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Thu, 15 Jul 2021 16:03:49 +0800 Subject: [PATCH] blockly disable --- _server/MotaAction.g4 | 88 ++++++++++++++++++++++++--------- _server/MotaActionParser.js | 40 +++++++-------- _server/editor_blockly.js | 55 +++++++++++++++++++++ _server/editor_blocklyconfig.js | 4 +- libs/events.js | 6 ++- 5 files changed, 146 insertions(+), 47 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index d6ff541e..04d024e3 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -766,7 +766,12 @@ helpUrl : /_docs/#/instruction doubleclicktext : EvalString_Multi_0 default : ["欢迎使用事件编辑器(回车直接多行编辑)"] var code = '"'+EvalString_Multi_0+'"'; -if (block.isCollapsed()) code = '{"type": "text", "text": '+code+', "_collapsed": true}'; +if (block.isCollapsed() || !block.isEnabled()) { + code = '{"type": "text", "text": '+code; + if (block.isCollapsed()) code += ', "_collapsed": true'; + if (!block.isEnabled()) code += ', "_disabled": true'; + code += '}'; +} return code+',\n'; */; @@ -793,7 +798,12 @@ if(EvalString_2 && !(/^(up|center|down|hero|this)(,(hero|null|\d+,\d+|\d+))?$/.t } EvalString_2 = EvalString_2 && ('\\b['+EvalString_2+']'); var code = '"'+title+EvalString_2+EvalString_Multi_0+'"'; -if (block.isCollapsed()) code = '{"type": "text", "text": '+code+', "_collapsed": true}'; +if (block.isCollapsed() || !block.isEnabled()) { + code = '{"type": "text", "text": '+code; + if (block.isCollapsed()) code += ', "_collapsed": true'; + if (!block.isEnabled()) code += ', "_disabled": true'; + code += '}'; +} return code+',\n'; */; @@ -821,7 +831,12 @@ if(EvalString_2 && !(/^(up|center|down|hero|this)(,(hero|null|\d+,\d+|\d+))?$/.t } EvalString_2 = EvalString_2 && ('\\b['+EvalString_2+']'); var code = '"'+title+EvalString_2+textDrawingList_0.replace(/\s/g, '')+EvalString_Multi_0+'"'; -if (block.isCollapsed()) code = '{"type": "text", "text": '+code+', "_collapsed": true}'; +if (block.isCollapsed() || !block.isEnabled()) { + code = '{"type": "text", "text": '+code; + if (block.isCollapsed()) code += ', "_collapsed": true'; + if (!block.isEnabled()) code += ', "_disabled": true'; + code += '}'; +} return code+',\n'; */; @@ -2357,8 +2372,10 @@ if_s tooltip : if: 条件判断 helpUrl : /_docs/#/instruction colour : this.eventColor -var code = ['{"type": "if", "condition": "',expression_0,'",',block.isCollapsed()?'"_collapsed": true,\n':'\n', - '"true": [\n',action_0,'],\n', +var code = ['{"type": "if", "condition": "',expression_0,'",', + block.isCollapsed()?' "_collapsed": true,':'', + block.isEnabled()?'':' "_disabled": true,', + '\n"true": [\n',action_0,'],\n', '"false": [\n',action_1,']', '},\n'].join(''); return code; @@ -2372,8 +2389,10 @@ if_1_s tooltip : if: 条件判断 helpUrl : /_docs/#/instruction colour : this.eventColor -var code = ['{"type": "if", "condition": "',expression_0,'",',block.isCollapsed()?'"_collapsed": true,\n':'\n', - '"true": [\n',action_0,']', +var code = ['{"type": "if", "condition": "',expression_0,'",', + block.isCollapsed()?' "_collapsed": true,':'', + block.isEnabled()?'':' "_disabled": true,', + '\n"true": [\n',action_0,']', '},\n'].join(''); return code; */; @@ -2387,7 +2406,10 @@ tooltip : switch: 多重条件分歧 helpUrl : /_docs/#/instruction default : ["判别值"] colour : this.eventColor -var code = ['{"type": "switch", "condition": "',expression_0,'", ',block.isCollapsed()?'"_collapsed": true, ':'','"caseList": [\n', +var code = ['{"type": "switch", "condition": "',expression_0,'", ', + block.isCollapsed()?'"_collapsed": true, ':'', + block.isEnabled()?'':'"_disabled": true, ', + '"caseList": [\n', switchCase_0, '], },\n'].join(''); return code; @@ -2404,7 +2426,8 @@ default : ["", false] colour : this.subColor Bool_0 = Bool_0?', "nobreak": true':''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"case": "'+expression_0+'"'+Bool_0+collapsed+', "action": [\n'+action_0+']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"case": "'+expression_0+'"'+Bool_0+collapsed+disabled+', "action": [\n'+action_0+']},\n'; return code; */; @@ -2429,7 +2452,10 @@ if (EvalString_0==''){ EvalString_Multi_0 = title+EvalString_Multi_0; EvalString_Multi_0 = EvalString_Multi_0 ?(', "text": "'+EvalString_Multi_0+'"'):''; Int_0 = Int_0 ? (', "timeout": '+Int_0) : ''; -var code = ['{"type": "choices"',EvalString_Multi_0,Int_0,block.isCollapsed()?', "_collapsed": true':'',', "choices": [\n', +var code = ['{"type": "choices"',EvalString_Multi_0,Int_0, + block.isCollapsed()?', "_collapsed": true':'', + block.isEnabled()?'':', "_disabled": true', + ', "choices": [\n', choicesContext_0, ']},\n'].join(''); return code; @@ -2450,7 +2476,8 @@ EvalString_1 = EvalString_1 && (', "need": "'+EvalString_1+'"'); EvalString_2 = EvalString_2 && (', "condition": "'+EvalString_2+'"'); IdString_0 = IdString_0?(', "icon": "'+IdString_0+'"'):''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"text": "'+EvalString_0+'"'+IdString_0+ColorString_0+EvalString_1+EvalString_2+collapsed+', "action": [\n'+action_0+']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"text": "'+EvalString_0+'"'+IdString_0+ColorString_0+EvalString_1+EvalString_2+collapsed+disabled+', "action": [\n'+action_0+']},\n'; return code; */; @@ -2464,8 +2491,10 @@ default : ["确认要xxx吗?",0,false] doubleclicktext : EvalString_Multi_0 Bool_0 = Bool_0?', "default": true':'' Int_0 = Int_0 ? (', "timeout": '+Int_0) : ''; -var code = ['{"type": "confirm"'+Int_0+Bool_0+', "text": "',EvalString_Multi_0,'",',block.isCollapsed()?'"_collapsed": true,\n':'\n', - '"yes": [\n',action_0,'],\n', +var code = ['{"type": "confirm"'+Int_0+Bool_0+', "text": "',EvalString_Multi_0,'",', + block.isCollapsed()?' "_collapsed": true,':'', + block.isEnabled()?'':' "_disabled": true,', + '\n"yes": [\n',action_0,'],\n', '"no": [\n',action_1,']\n', '},\n'].join(''); return code; @@ -2482,7 +2511,8 @@ if (!/^temp:[A-Z]$/.test(expression_0)) { throw new Error('循环遍历仅允许使用临时变量!'); } var collapsed=block.isCollapsed()?', "_collapsed": true':''; -return '{"type": "for", "name": "'+expression_0+'", "from": "'+EvalString_0+'", "to": "'+EvalString_1+'", "step": "'+EvalString_2+'"'+collapsed+',\n"data": [\n'+action_0+']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +return '{"type": "for", "name": "'+expression_0+'", "from": "'+EvalString_0+'", "to": "'+EvalString_1+'", "step": "'+EvalString_2+'"'+collapsed+disabled+',\n"data": [\n'+action_0+']},\n'; */; forEach_s @@ -2499,7 +2529,8 @@ if (JsonEvalString_0 == '' || !(JSON.parse(JsonEvalString_0) instanceof Array)) throw new Error('参数列表必须是个有效的数组!'); } var collapsed=block.isCollapsed()?', "_collapsed": true':''; -return '{"type": "forEach", "name": "'+expression_0+'", "list": '+JsonEvalString_0 + collapsed+',\n"data": [\n'+action_0+']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +return '{"type": "forEach", "name": "'+expression_0+'", "list": '+JsonEvalString_0 + collapsed+disabled+',\n"data": [\n'+action_0+']},\n'; */; while_s @@ -2509,8 +2540,10 @@ while_s tooltip : while:前置条件循环 helpUrl : /_docs/#/instruction colour : this.eventColor -var code = ['{"type": "while", "condition": "',expression_0,'",',block.isCollapsed()?'"_collapsed": true,\n':'\n', - '"data": [\n',action_0,'],\n', +var code = ['{"type": "while", "condition": "',expression_0,'",', + block.isCollapsed()?' "_collapsed": true,':'', + block.isEnabled()?'':' "_disabled": true,', + '\n"data": [\n',action_0,'],\n', '},\n'].join(''); return code; */; @@ -2522,8 +2555,10 @@ dowhile_s tooltip : dowhile:后置条件循环 helpUrl : /_docs/#/instruction colour : this.eventColor -var code = ['{"type": "dowhile", "condition": "',expression_0,'",',block.isCollapsed()?'"_collapsed": true,\n':'\n', - '"data": [\n',action_0,'],\n', +var code = ['{"type": "dowhile", "condition": "',expression_0,'",', + block.isCollapsed()?' "_collapsed": true,':'', + block.isEnabled()?'':' "_disabled": true,', + '\n"data": [\n',action_0,'],\n', '},\n'].join(''); return code; */; @@ -2567,7 +2602,8 @@ colour : this.soundColor Int_0 = Int_0?(', "timeout": ' + Int_0):''; waitContext_0 = waitContext_0 ? (', "data": [\n' + waitContext_0 + ']') : ''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"type": "wait"' + Int_0 + collapsed + waitContext_0 + '},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"type": "wait"' + Int_0 + collapsed + disabled + waitContext_0 + '},\n'; return code; */; @@ -2592,7 +2628,8 @@ if (!/^\d+(,\d+)*$/.test(EvalString_0)) { } Bool_0 = Bool_0?', "break": true':''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"case": "keyboard", "keycode": "' + EvalString_0 + '"'+Bool_0+collapsed+', "action": [\n' + action_0 + ']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"case": "keyboard", "keycode": "' + EvalString_0 + '"'+Bool_0+collapsed+disabled+', "action": [\n' + action_0 + ']},\n'; return code; */; @@ -2608,7 +2645,8 @@ previewBlock : true colour : this.subColor Bool_0 = Bool_0?', "break": true':''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"case": "mouse", "px": [' + PosString_0 + ',' + PosString_1 + '], "py": [' + PosString_2 + ',' + PosString_3 + ']'+Bool_0+collapsed+', "action": [\n' + action_0 + ']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"case": "mouse", "px": [' + PosString_0 + ',' + PosString_1 + '], "py": [' + PosString_2 + ',' + PosString_3 + ']'+Bool_0+collapsed+disabled+', "action": [\n' + action_0 + ']},\n'; return code; */; @@ -2622,7 +2660,8 @@ colour : this.subColor default : [false] Bool_0 = Bool_0?', "break": true':''; var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = '{"case": "timeout"'+Bool_0+collapsed+', "action": [\n' + action_0 + ']},\n'; +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = '{"case": "timeout"'+Bool_0+collapsed+disabled+', "action": [\n' + action_0 + ']},\n'; return code; */; @@ -2724,7 +2763,8 @@ tooltip : previewUI: ui绘制并预览 helpUrl : /_docs/#/instruction previewBlock : true var collapsed=block.isCollapsed()?', "_collapsed": true':''; -var code = ['{"type": "previewUI"'+collapsed+', "action": [\n', action_0,']},\n'].join(''); +var disabled=block.isEnabled()?'':', "_disabled": true'; +var code = ['{"type": "previewUI"'+collapsed+disabled+', "action": [\n', action_0,']},\n'].join(''); return code; */; diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index 92b3a03b..ede248a6 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -249,14 +249,14 @@ ActionParser.prototype.parseAction = function() { } this.next = MotaActionFunctions.xmlText('text_2_s', [ info[0], info[1], info[2], info[3], buildTextDrawing(textDrawing), this.next - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); } else if (info[0] || info[1] || info[2]) { this.next = MotaActionFunctions.xmlText('text_1_s',[ - info[0], info[1], info[2], info[3], this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + info[0], info[1], info[2], info[3], this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); } else { this.next = MotaActionFunctions.xmlText('text_0_s', [info[3],this.next], - /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); } break; case "autoText": // 自动剧情文本 @@ -658,13 +658,13 @@ ActionParser.prototype.parseAction = function() { this.expandEvalBlock([data.condition]), this.insertActionList(data["true"]), this.insertActionList(data["false"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); } else { this.next = MotaActionFunctions.xmlText('if_1_s', [ this.expandEvalBlock([data.condition]), this.insertActionList(data["true"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); } break; case "confirm": // 显示确认框 @@ -672,18 +672,18 @@ ActionParser.prototype.parseAction = function() { this.EvalString_Multi(data.text), data.timeout||0, data["default"], this.insertActionList(data["yes"]), this.insertActionList(data["no"]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "switch": // 多重条件分歧 var case_caseList = null; for(var ii=data.caseList.length-1,caseNow;caseNow=data.caseList[ii];ii--) { case_caseList=MotaActionFunctions.xmlText('switchCase', [ this.isset(caseNow.case)?this.expandEvalBlock([caseNow.case]):"值",caseNow.nobreak,this.insertActionList(caseNow.action),case_caseList], - /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed); + /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); } this.next = MotaActionFunctions.xmlText('switch_s', [ this.expandEvalBlock([data.condition]), - case_caseList,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + case_caseList,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "choices": // 提供选项 var text_choices = null; @@ -691,38 +691,38 @@ ActionParser.prototype.parseAction = function() { choice.color = this.Colour(choice.color); text_choices=MotaActionFunctions.xmlText('choicesContext', [ choice.text,choice.icon,choice.color,'rgba('+choice.color+')',choice.need||'',choice.condition||'',this.insertActionList(choice.action),text_choices], - /* isShadow */false, /*comment*/ null, /*collapsed*/ choice._collapsed); + /* isShadow */false, /*comment*/ null, /*collapsed*/ choice._collapsed, /*disabled*/ choice._disabled); } if (!this.isset(data.text)) data.text = ''; var info = this.getTitleAndPosition(data.text); this.next = MotaActionFunctions.xmlText('choices_s', [ - info[3],info[0],info[1],data.timeout||0,text_choices,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + info[3],info[0],info[1],data.timeout||0,text_choices,this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "for": // 循环遍历 this.next = MotaActionFunctions.xmlText('for_s',[ this.expandEvalBlock([data.name]), data.from || 0, data.to || 0, data.step || 0, this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "forEach": // 循环遍历列表 this.next = MotaActionFunctions.xmlText('forEach_s',[ this.expandEvalBlock([data.name]), JSON.stringify(data.list), this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "while": // 前置条件循环处理 this.next = MotaActionFunctions.xmlText('while_s',[ this.expandEvalBlock([data.condition]), this.insertActionList(data.data), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "dowhile": // 后置条件循环处理 this.next = MotaActionFunctions.xmlText('dowhile_s',[ this.insertActionList(data.data), this.expandEvalBlock([data.condition]), - this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "break": // 跳出循环 this.next = MotaActionBlocks['break_s'].xmlText([ @@ -781,20 +781,20 @@ ActionParser.prototype.parseAction = function() { if (caseNow["case"] == "keyboard") { case_waitList = MotaActionFunctions.xmlText('waitContext_1',[ caseNow.keycode || "0", caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed); + ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); } else if (caseNow["case"] == "mouse") { case_waitList = MotaActionFunctions.xmlText('waitContext_2',[ caseNow.px[0], caseNow.px[1], caseNow.py[0], caseNow.py[1], caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed); + ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); } else if (caseNow["case"] == "timeout") { case_waitList = MotaActionFunctions.xmlText('waitContext_3',[ caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed); + ], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled); } } } this.next = MotaActionFunctions.xmlText('wait_s',[ - data.timeout||0,case_waitList, this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + data.timeout||0,case_waitList, this.next], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "waitAsync": // 等待所有异步事件执行完毕 this.next = MotaActionBlocks['waitAsync_s'].xmlText([ @@ -827,7 +827,7 @@ ActionParser.prototype.parseAction = function() { case "previewUI": // UI绘制预览 this.next = MotaActionFunctions.xmlText('previewUI_s',[ this.insertActionList(data.action), this.next - ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed); + ], /* isShadow */false, /*comment*/ null, /*collapsed*/ data._collapsed, /*disabled*/ data._disabled); break; case "clearMap": // 清除画布 this.next = MotaActionBlocks['clearMap_s'].xmlText([ @@ -1253,7 +1253,7 @@ MotaActionFunctions.PosString_pre = function(PosString){ if (!PosString || /^-?\d+$/.test(PosString)) return PosString; //if (!(MotaActionFunctions.pattern.id.test(PosString)))throw new Error(PosString+'中包含了0-9 a-z A-Z _ 和中文之外的字符,或者是没有以flag: 开头'); var comma = PosString.indexOf(','); - if (comma >= 0 && PosString.substring(0, comma).indexOf('(') < 0) throw '此处不可写多点坐标'; + if (comma >= 0 && PosString.substring(0, comma).ifndexOf('(') < 0) throw '此处不可写多点坐标'; return '"'+MotaActionFunctions.replaceFromName(PosString)+'"'; } diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 66470253..01c04fb4 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -1008,3 +1008,58 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) { this.pasteBlock_(xmlBlock); } }; + +// -- Support showing disabled blocks + +Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { + if (this.isInitialized === false) { + console.warn( + 'Generator init was not called before blockToCode was called.'); + } + if (!block) { + return ''; + } + var supportedDisabledBlocks = [ + 'text_0_s', 'text_1_s', 'text_2_s', 'if_s', 'if_1_s', 'confirm_s', 'switch_s', 'choices_s', + 'for_s', 'forEach_s', 'while_s', 'dowhile_s', 'wait_s', 'previewUI_s', + 'waitContext_1', 'waitContext_2', 'waitContext_3', 'switchCase', 'choicesContext' + ]; + if (!block.isEnabled() && supportedDisabledBlocks.indexOf(block.type) < 0) { + // Skip past this block if it is disabled. + return opt_thisOnly ? '' : this.blockToCode(block.getNextBlock()); + } + if (block.isInsertionMarker()) { + // Skip past insertion markers. + return opt_thisOnly ? '' : this.blockToCode(block.getChildren(false)[0]); + } + + var func = this[block.type]; + if (typeof func != 'function') { + throw Error('Language "' + this.name_ + '" does not know how to generate ' + + 'code for block type "' + block.type + '".'); + } + // First argument to func.call is the value of 'this' in the generator. + // Prior to 24 September 2013 'this' was the only way to access the block. + // The current preferred method of accessing the block is through the second + // argument to func.call, which becomes the first parameter to the generator. + var code = func.call(block, block); + if (Array.isArray(code)) { + // Value blocks return tuples of code and operator order. + if (!block.outputConnection) { + throw TypeError('Expecting string from statement block: ' + block.type); + } + return [this.scrub_(block, code[0], opt_thisOnly), code[1]]; + } else if (typeof code == 'string') { + if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { + code = this.injectId(this.STATEMENT_PREFIX, block) + code; + } + if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) { + code = code + this.injectId(this.STATEMENT_SUFFIX, block); + } + return this.scrub_(block, code, opt_thisOnly); + } else if (code === null) { + // Block has handled code generation itself. + return ''; + } + throw SyntaxError('Invalid code generated: ' + code); +}; diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 79c3dbe1..a3a5f81f 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -479,11 +479,11 @@ function omitedcheckUpdateFunction(event) { } // 因为在editor_blockly.parse里已经HTML转义过一次了,所以这里要覆盖掉以避免在注释中出现<等 - MotaActionFunctions.xmlText = function (ruleName,inputs,isShadow,comment,collapsed) { + MotaActionFunctions.xmlText = function (ruleName,inputs,isShadow,comment,collapsed,disabled) { var rule = MotaActionBlocks[ruleName]; var blocktext = isShadow?'shadow':'block'; var xmlText = []; - xmlText.push('<'+blocktext+' type="'+ruleName+'"'+(collapsed ? ' collapsed="true"' : '')+'>'); + xmlText.push('<'+blocktext+' type="'+ruleName+'"'+(collapsed ? ' collapsed="true"' : '')+(disabled ? ' disabled="true"' : '')+'>'); if(!inputs)inputs=[]; for (var ii=0,inputType;inputType=rule.argsType[ii];ii++) { var input = inputs[ii]; diff --git a/libs/events.js b/libs/events.js index 1e133275..224a184a 100644 --- a/libs/events.js +++ b/libs/events.js @@ -944,6 +944,8 @@ events.prototype.doAction = function () { core.status.event.data.current = data; if (typeof data == "string") data = {"type": "text", "text": data}; + // 该事件块已经被禁用 + if (data._disabled) return core.doAction(); data.floorId = data.floorId || floorId; core.status.event.data.type = data.type; this.doEvent(data, x, y, prefix); @@ -1831,6 +1833,7 @@ events.prototype._action_switch = function (data, x, y, prefix) { var key = core.calValue(data.condition, prefix) var list = []; for (var i = 0; i < data.caseList.length; i++) { + if (data.caseList[i]._disabled) continue; var condition = data.caseList[i]["case"]; if (condition == "default" || core.calValue(condition, prefix) === key) { core.push(list, data.caseList[i].action); @@ -1853,6 +1856,7 @@ events.prototype._precompile_switch = function (data) { events.prototype._action_choices = function (data, x, y, prefix) { data.choices = data.choices.filter(function (x) { + if (x._disabled) return false; if (x.condition == null || x.condition == '') return true; try { return core.calValue(x.condition, prefix); } catch (e) { return true; } }) @@ -2223,7 +2227,7 @@ events.prototype.__action_wait_afterGet = function (data) { var todo = []; var stop = false; data.data.forEach(function (one) { - if (stop) return; + if (one._disabled || stop) return; if (one["case"] == "keyboard" && core.getFlag("type") == 0) { (one.keycode + "").split(",").forEach(function (keycode) { if (core.getFlag("keycode", 0) == keycode) {