等待事件 仅检测子块

This commit is contained in:
ckcz123 2021-07-30 23:22:35 +08:00
parent dc5326c982
commit b8ddb2e167
7 changed files with 83 additions and 27 deletions

View File

@ -2982,19 +2982,20 @@ return code;
wait_s
: '等待用户操作并获得按键或点击信息' '超时毫秒数' Int BGNL? Newline waitContext* BEND Newline
: '等待用户操作并获得按键或点击信息' '仅检测子块' Bool '超时毫秒数' Int BGNL? Newline waitContext* BEND Newline
/* wait_s
tooltip : wait: 等待用户操作并获得按键或点击信息
helpUrl : /_docs/#/instruction
default : [0]
default : [true,0]
colour : this.soundColor
Bool_0 = Bool_0?(', "forceChild": true'):'';
Int_0 = Int_0?(', "timeout": ' + Int_0):'';
waitContext_0 = waitContext_0 ? (', "data": [\n' + waitContext_0 + ']') : '';
var collapsed=block.isCollapsed()?', "_collapsed": true':'';
var disabled=block.isEnabled()?'':', "_disabled": true';
var code = '{"type": "wait"' + Int_0 + collapsed + disabled + waitContext_0 + '},\n';
var code = '{"type": "wait"' + Bool_0 + Int_0 + collapsed + disabled + waitContext_0 + '},\n';
return code;
*/;
@ -3003,11 +3004,12 @@ waitContext
: waitContext_1
| waitContext_2
| waitContext_3
| waitContext_4
| waitContext_empty;
waitContext_1
: '按键的场合' '键值' EvalString '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
: '按键的场合' '键值' EvalString '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
/* waitContext_1
tooltip : wait: 等待用户操作并获得按键或点击信息
@ -3026,7 +3028,7 @@ return code;
waitContext_2
: '点击的场合' '像素x范围' PosString '~' PosString '; y范围' PosString '~' PosString '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
: '点击的场合' '像素x范围' PosString '~' PosString '; y范围' PosString '~' PosString '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
/* waitContext_2
tooltip : wait: 等待用户操作并获得按键或点击信息
@ -3042,11 +3044,26 @@ return code;
*/;
waitContext_3
: '超时的场合' '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
: '自定义条件的场合:' expression '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
/* waitContext_3
tooltip : wait: 等待用户操作并获得按键或点击信息
helpUrl : /_docs/#/instruction
default : ["true",false]
colour : this.subColor
Bool_0 = Bool_0?', "break": true':'';
var collapsed=block.isCollapsed()?', "_collapsed": true':'';
var disabled=block.isEnabled()?'':', "_disabled": true';
var code = '{"case": "condition", "condition": "'+expression_0+'"'+Bool_0+collapsed+disabled+', "action": [\n' + action_0 + ']},\n';
return code;
*/;
waitContext_4
: '超时的场合:' '不进行剩余判定' Bool BGNL? Newline action+ BEND Newline
/* waitContext_4
tooltip : wait: 等待用户操作并获得按键或点击信息
helpUrl : /_docs/#/instruction
colour : this.subColor
default : [false]
Bool_0 = Bool_0?', "break": true':'';

View File

@ -906,15 +906,19 @@ ActionParser.prototype.parseAction = function() {
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, /*disabled*/ caseNow._disabled);
} else if (caseNow["case"] == "timeout") {
} else if (caseNow["case"] == "condition") {
case_waitList = MotaActionFunctions.xmlText('waitContext_3',[
this.expandEvalBlock([caseNow.condition]), caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList
], /* isShadow */false, /*comment*/ null, /*collapsed*/ caseNow._collapsed, /*disabled*/ caseNow._disabled);
} else if (caseNow["case"] == "timeout") {
case_waitList = MotaActionFunctions.xmlText('waitContext_4',[
caseNow["break"] || false, this.insertActionList(caseNow.action), case_waitList
], /* 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, /*disabled*/ data._disabled);
data.forceChild||false,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([
@ -1334,6 +1338,7 @@ ActionParser.prototype.expandIdBlock = function(args, isShadow, comment) {
ActionParser.prototype.expandEvalBlock = function(args, isShadow, comment) {
args[0]=MotaActionFunctions.replaceFromName(args[0])
var xml=MotaActionBlocks['evalString_e'].xmlText
if (args[0].indexOf('\n') >= 0 || args[0].indexOf('\\n') >= 0) return xml(args, isShadow, comment);
var ret=this.matchId(args)
if (ret.ret){
xml=ret.xml;

View File

@ -193,6 +193,7 @@ editor_blocklyconfig=(function(){
MotaActionFunctions.actionParser.parseList({"type": "wait", "timeout": 0, "data": [
{"case": "keyboard", "keycode": "13,32", "action": [{"type": "comment", "text": "当按下回车(keycode=13)或空格(keycode=32)时执行此事件\n超时剩余时间会写入flag:timeout"}]},
{"case": "mouse", "px": [0,32], "py": [0,32], "action": [{"type": "comment", "text": "当点击地图左上角时执行此事件\n超时剩余时间会写入flag:timeout"}]},
{"case": "condition", "condition": "flag:type==0\n&&flag:keycode==13", "action": [{"type": "comment", "text": "当满足自定义条件时会执行此事件\n超时剩余时间会写入flag:timeout"}]},
{"case": "timeout", "action": [{"type": "comment", "text": "当超时未操作时执行此事件"}]},
]}),
MotaActionBlocks['waitAsync_s'].xmlText(),

View File

@ -407,6 +407,11 @@ editor_mappanel_wrapper = function (editor) {
var index = editor.core.floorIds.indexOf(editor.currentFloorId);
var toId = editor.currentFloorId;
var saveFloor = document.getElementById('saveFloor');
if (saveFloor && saveFloor.classList.contains('highlight')) {
return;
}
if (direct > 0 && index < editor.core.floorIds.length - 1)
toId = editor.core.floorIds[index + 1];
else if (direct < 0 && index > 0)
@ -433,6 +438,11 @@ editor_mappanel_wrapper = function (editor) {
}
editor.uifunctions.undoFloor_click = function () {
var saveFloor = document.getElementById('saveFloor');
if (saveFloor && saveFloor.classList.contains('highlight')) {
return;
}
var toId = editor.uivalues.recentFloors.pop();
if (toId == null || toId == editor.currentFloorId) return;

View File

@ -164,6 +164,11 @@ editor_ui_wrapper = function (editor) {
// PGUP和PGDOWN切换楼层
if (e.keyCode == 33 || e.keyCode == 34) {
e.preventDefault();
var saveFloor = document.getElementById('saveFloor');
if (saveFloor && saveFloor.classList.contains('highlight')) {
return;
}
var index = editor.core.floorIds.indexOf(editor.currentFloorId);
var nextIndex = index + (e.keyCode == 33 ? 1 : -1);
if (nextIndex >= 0 && nextIndex < editor.core.floorIds.length) {

View File

@ -777,16 +777,18 @@ actions.prototype._sys_onmousewheel = function (direct) {
// wait事件
if (core.status.lockControl && core.status.event.id == 'action' && core.status.event.data.type == 'wait') {
clearTimeout(core.status.event.interval);
var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0;
delete core.status.event.timeout;
core.setFlag('type', 0);
var keycode = direct == 1 ? 33 : 34;
core.setFlag('keycode', keycode);
core.setFlag('timeout', timeout);
core.status.route.push("input:" + (1e8 * timeout + keycode));
core.events.__action_wait_afterGet(core.status.event.data.current);
core.doAction();
var executed = core.events.__action_wait_afterGet(core.status.event.data.current);
if (executed || !core.status.event.data.current.forceChild) {
core.status.route.push("input:" + (1e8 * timeout + keycode));
clearTimeout(core.status.event.interval);
delete core.status.event.timeout;
core.doAction();
}
return;
}
@ -1040,18 +1042,20 @@ actions.prototype._clickAction = function (x, y, px, py) {
}
if (core.status.event.data.type == 'wait') {
clearTimeout(core.status.event.interval);
var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0;
delete core.status.event.timeout;
core.setFlag('type', 1);
core.setFlag('x', x);
core.setFlag('y', y);
core.setFlag('px', px);
core.setFlag('py', py);
core.setFlag('timeout', timeout);
core.status.route.push("input:" + (1e8 * timeout + 1000000 + 1000 * px + py));
core.events.__action_wait_afterGet(core.status.event.data.current);
core.doAction();
var executed = core.events.__action_wait_afterGet(core.status.event.data.current);
if (executed || !core.status.event.data.current.forceChild) {
core.status.route.push("input:" + (1e8 * timeout + 1000000 + 1000 * px + py));
clearTimeout(core.status.event.interval);
delete core.status.event.timeout;
core.doAction();
}
return;
}
@ -1134,15 +1138,17 @@ actions.prototype._keyUpAction = function (keycode) {
return;
}
if (core.status.event.data.type == 'wait') {
clearTimeout(core.status.event.interval);
var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0;
delete core.status.event.timeout;
core.setFlag('type', 0);
core.setFlag('keycode', keycode);
core.setFlag('timeout', timeout);
core.status.route.push("input:" + (1e8 * timeout + keycode));
core.events.__action_wait_afterGet(core.status.event.data.current);
core.doAction();
var executed = core.events.__action_wait_afterGet(core.status.event.data.current);
if (executed || !core.status.event.data.current.forceChild) {
core.status.route.push("input:" + (1e8 * timeout + keycode));
clearTimeout(core.status.event.interval);
delete core.status.event.timeout;
core.doAction();
}
return;
}
if (core.status.event.data.type == 'choices') {

View File

@ -2371,7 +2371,7 @@ events.prototype.__action_wait_getValue = function (value) {
}
events.prototype.__action_wait_afterGet = function (data) {
if (!data.data) return;
if (!data.data) return false;
var todo = [];
var stop = false;
data.data.forEach(function (one) {
@ -2396,20 +2396,32 @@ events.prototype.__action_wait_afterGet = function (data) {
if (one["break"]) stop = true;
}
}
if (one["case"] == "condition") {
var condition = false;
try { condition = core.calValue(one.condition); } catch (e) {}
if (condition) {
core.push(todo, one.action);
if (one["break"]) stop = true;
}
}
if (one["case"] == "timeout" && core.getFlag("type") == -1) {
core.push(todo, one.action);
if (one["break"]) stop = true;
}
})
if (todo.length > 0)
if (todo.length > 0) {
core.insertAction(todo);
return true;
}
return false;
}
events.prototype._precompile_wait = function (data) {
if (data.data) {
data.data.forEach(function (v) {
if (v.px) v.px = this.__precompile_array(v.px);
if (v.py) v.py = this.__precompile_array(v.py);
if (v.px != null) v.px = this.__precompile_array(v.px);
if (v.py != null) v.py = this.__precompile_array(v.py);
if (v.condition != null) v.condition = this.__precompile_array(v.condition);
v.action = this.precompile(v.action);
}, this);
}