blockly解析提示

This commit is contained in:
ckcz123 2020-05-17 11:11:31 +08:00
parent 47283d30a9
commit 0d3ed417b3
4 changed files with 34 additions and 12 deletions

View File

@ -398,22 +398,22 @@ function omitedcheckUpdateFunction(event) {
}
}
if(editor_blockly.workspace.topBlocks_.length>=2){
codeAreaHL.setValue('入口方块只能有一个');
editor_blockly.setValue('入口方块只能有一个');
return;
}
var eventType = document.getElementById('entryType').value;
if(editor_blockly.workspace.topBlocks_.length==1){
var blockType = editor_blockly.workspace.topBlocks_[0].type;
if(blockType!==eventType+'_m'){
codeAreaHL.setValue('入口方块类型错误');
editor_blockly.setValue('入口方块类型错误');
return;
}
}
try {
var code = Blockly.JavaScript.workspaceToCode(workspace).replace(/\\\\(i|c|d|e|z)/g, '\\\\\\\\$1');
codeAreaHL.setValue(code);
editor_blockly.setValue(code);
} catch (error) {
codeAreaHL.setValue(String(error));
editor_blockly.setValue(String(error));
if (error instanceof OmitedError){
var blockName = error.blockName;
var varName = error.varName;
@ -529,13 +529,19 @@ function omitedcheckUpdateFunction(event) {
xhr.open('GET', '_server/MotaAction.g4', true);
xhr.send(null);
codeAreaHL = CodeMirror.fromTextArea(document.getElementById("codeArea"), {
var codeAreaHL = CodeMirror.fromTextArea(document.getElementById("codeArea"), {
lineNumbers: true,
matchBrackets: true,
lineWrapping: true,
continueComments: "Enter",
extraKeys: {"Ctrl-Q": "toggleComment"}
extraKeys: {"Ctrl-Q": "toggleComment"},
});
codeAreaHL.on('changes', function () {
editor_blockly.highlightParse(!changeFromBlockly);
changeFromBlockly = false;
});
var changeFromBlockly = false;
var shouldNotifyParse = false;
editor_blockly.showXML = function () {
var xml = Blockly.Xml.workspaceToDom(editor_blockly.workspace);
@ -561,6 +567,11 @@ function omitedcheckUpdateFunction(event) {
}
}
editor_blockly.setValue = function (value) {
changeFromBlockly = true;
codeAreaHL.setValue(value);
}
editor_blockly.parse = function () {
MotaActionFunctions.parse(
eval('obj=' + codeAreaHL.getValue().replace(/[<>&]/g, function (c) {
@ -580,7 +591,7 @@ function omitedcheckUpdateFunction(event) {
var type = args.type;
if (!type) return false;
editor_blockly.id = id_;
codeAreaHL.setValue(input.value);
editor_blockly.setValue(input.value);
document.getElementById('entryType').value = type;
editor_blockly.parse();
editor_blockly.show();
@ -604,6 +615,13 @@ function omitedcheckUpdateFunction(event) {
}
}
var blocklyParseBtn = document.getElementById('blocklyParse');
editor_blockly.highlightParse = function (shouldHighLight) {
if (shouldNotifyParse == shouldHighLight) return;
shouldNotifyParse = shouldHighLight;
blocklyParseBtn.style.background = shouldNotifyParse ? '#FFCCAA' : 'unset';
}
editor_blockly.cancel = function () {
editor_blockly.id = '';
editor_blockly.hide();
@ -614,15 +632,19 @@ function omitedcheckUpdateFunction(event) {
editor_blockly.id = '';
return;
}
if (shouldNotifyParse) {
alert('你尚未解析修改后的内容,请进行解析或放弃操作');
return;
}
if(editor_blockly.workspace.topBlocks_.length>=2){
codeAreaHL.setValue('入口方块只能有一个');
editor_blockly.setValue('入口方块只能有一个');
return;
}
var eventType = document.getElementById('entryType').value;
if(editor_blockly.workspace.topBlocks_.length==1){
var blockType = editor_blockly.workspace.topBlocks_[0].type;
if(blockType!==eventType+'_m'){
codeAreaHL.setValue('入口方块类型错误');
editor_blockly.setValue('入口方块类型错误');
return;
}
}

View File

@ -219,7 +219,7 @@
<option value="item">item</option>
</select>
<button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button>
<button id='blocklyParse' onclick="editor_blockly.parse()">解析</button>
<button onclick="editor_blockly.cancel()">取消</button>
<!-- 手机端放不下,因此不显示搜索框 -->
<div style="display: none">

View File

@ -215,7 +215,7 @@
<option value="item">item</option>
</select>
<button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button>
<button id='blocklyParse' onclick="editor_blockly.parse()">解析</button>
<button onclick="editor_blockly.cancel()">取消</button>
<div style="position: relative; display: inline-block; margin-left: 10px">
<div class="searchLogo"></div>

View File

@ -55,7 +55,7 @@
(已完成!) loader并行加载
合并items.js
(已完成!) 增加fonts目录全塔属性增加fonts引用
右边框输入完后解析按钮高亮
(已完成!) 右边框输入完后解析按钮高亮
-------------