switch
This commit is contained in:
parent
45db852c98
commit
3b5e7a0e30
@ -238,6 +238,7 @@ action
|
||||
| win_s
|
||||
| lose_s
|
||||
| if_s
|
||||
| switch_s
|
||||
| while_s
|
||||
| break_s
|
||||
| continue_s
|
||||
@ -1236,6 +1237,33 @@ var code = ['{"type": "if", "condition": "',expression_0,'",\n',
|
||||
return code;
|
||||
*/;
|
||||
|
||||
switch_s
|
||||
: '多重分歧 条件判定' ':' expression BGNL? Newline switchCase_s+ BEND Newline
|
||||
|
||||
|
||||
/* switch_s
|
||||
tooltip : switch: 多重条件分歧
|
||||
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=choices%EF%BC%9A%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E9%80%89%E9%A1%B9
|
||||
default : ["判别值"]
|
||||
colour : this.eventColor
|
||||
var code = ['{"type": "switch", "condition": "',expression_0,'", "caseList": [\n',
|
||||
switchCase_s_0,
|
||||
'], },\n'].join('');
|
||||
return code;
|
||||
*/;
|
||||
|
||||
switchCase_s
|
||||
: '如果是' expression '的场合' BGNL? Newline action+
|
||||
|
||||
|
||||
/* switchCase_s
|
||||
tooltip : 选项的选择
|
||||
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=choices%EF%BC%9A%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E9%80%89%E9%A1%B9
|
||||
colour : this.subColor
|
||||
var code = '{"case": "'+expression_0+'", "action": [\n'+action_0+']},\n';
|
||||
return code;
|
||||
*/;
|
||||
|
||||
choices_s
|
||||
: '选项' ':' EvalString? BGNL? '标题' EvalString? '图像' IdString? BGNL? Newline choicesContext+ BEND Newline
|
||||
|
||||
@ -1983,6 +2011,15 @@ ActionParser.prototype.parseAction = function() {
|
||||
this.insertActionList(data["false"]),
|
||||
this.next]);
|
||||
break;
|
||||
case "switch": // 多重条件分歧
|
||||
var case_caseList = null;
|
||||
for(var ii=data.caseList.length-1,caseNow;caseNow=data.caseList[ii];ii--) {
|
||||
case_caseList=MotaActionBlocks['switchCase_s'].xmlText([
|
||||
this.isset(caseNow.case)?MotaActionBlocks['evalString_e'].xmlText([caseNow.case]):"值",this.insertActionList(caseNow.action),case_caseList]);
|
||||
}
|
||||
this.next = MotaActionBlocks['switch_s'].xmlText([
|
||||
MotaActionBlocks['evalString_e'].xmlText([data.condition]),case_caseList,this.next]);
|
||||
break;
|
||||
case "choices": // 提供选项
|
||||
var text_choices = null;
|
||||
for(var ii=data.choices.length-1,choice;choice=data.choices[ii];ii--) {
|
||||
|
||||
@ -108,6 +108,11 @@ editor_blockly = function () {
|
||||
],
|
||||
'事件控制':[
|
||||
MotaActionBlocks['if_s'].xmlText(),
|
||||
MotaActionFunctions.actionParser.parseList({"type": "switch", "condition": "判别量", "caseList": [
|
||||
{"action": [{"type": "comment", "text": "当判别值是值的场合执行此事件"}]},
|
||||
{"action": []},
|
||||
{"case": "'default'", "action": [{"type": "comment", "text": "当没有符合的值的场合执行此事件"}]},
|
||||
]}),
|
||||
MotaActionBlocks['while_s'].xmlText(),
|
||||
MotaActionBlocks['break_s'].xmlText(),
|
||||
MotaActionBlocks['continue_s'].xmlText(),
|
||||
|
||||
@ -907,6 +907,18 @@ events.prototype.doAction = function() {
|
||||
core.events.insertAction(data["false"])
|
||||
this.doAction();
|
||||
break;
|
||||
case "switch": // 条件选择
|
||||
var key = core.calValue(data.condition)
|
||||
console.log(key);
|
||||
for (var i = 0; i < data.caseList.length; i++) {
|
||||
console.log(core.calValue(data.caseList[i].case));
|
||||
if (core.calValue(data.caseList[i].case) == key || core.calValue(data.caseList[i].case) == "default") {
|
||||
core.events.insertAction(data.caseList[i].action);
|
||||
this.doAction();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "choices": // 提供选项
|
||||
if (core.status.replay.replaying) {
|
||||
if (core.status.replay.toReplay.length==0) { // 回放完毕
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user