This commit is contained in:
ckcz123 2018-09-06 13:46:33 +08:00
parent 3308bb8e6a
commit f43ed04b1c
5 changed files with 75 additions and 8 deletions

View File

@ -235,6 +235,7 @@ action
| break_s
| continue_s
| input_s
| input2_s
| choices_s
| function_s
| pass_s
@ -1057,18 +1058,31 @@ return code;
*/;
input_s
: '接受用户输入,提示' ':' EvalString Newline
: '接受用户输入数字,提示' ':' EvalString Newline
/* input_s
tooltip : input接受用户输入, 事件只能接受非负整数输入, 所有非法的输入将全部变成0
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%EF%BC%9A%E6%8E%A5%E5%8F%97%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5
tooltip : input接受用户输入数字, 事件只能接受非负整数输入, 所有非法的输入将全部变成0
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%95%b0%e5%ad%97
default : ["请输入一个数"]
colour : this.dataColor
var code = '{"type": "input", "text": "'+EvalString_0+'"},\n';
return code;
*/;
input2_s
: '接受用户输入文本,提示' ':' EvalString Newline
/* input2_s
tooltip : input2接受用户输入文本, 允许用户输入任何形式的文本
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=input2%ef%bc%9a%e6%8e%a5%e5%8f%97%e7%94%a8%e6%88%b7%e8%be%93%e5%85%a5%e6%96%87%e6%9c%ac
default : ["请输入文本"]
colour : this.dataColor
var code = '{"type": "input2", "text": "'+EvalString_0+'"},\n';
return code;
*/;
if_s
: '如果' ':' expression BGNL? Newline action+ '否则' ':' BGNL? Newline action+ BEND Newline
@ -1773,6 +1787,10 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['input_s'].xmlText([
data.text,this.next]);
break;
case "input2":
this.next = MotaActionBlocks['input2_s'].xmlText([
data.text,this.next]);
break;
case "if": // 条件判断
this.next = MotaActionBlocks['if_s'].xmlText([
MotaActionBlocks['evalString_e'].xmlText([data.condition]),

View File

@ -88,6 +88,7 @@ editor_blockly = function () {
MotaActionBlocks['idString_1_e'].xmlText(['status','hp'])
]),
MotaActionBlocks['input_s'].xmlText(),
MotaActionBlocks['input2_s'].xmlText(),
MotaActionBlocks['update_s'].xmlText(),
MotaActionBlocks['updateEnemys_s'].xmlText(),
MotaActionBlocks['moveHero_s'].xmlText(),

View File

@ -995,13 +995,13 @@ value为音量大小在0到100之间默认为100。设置后BGM和SE都
该事件会显示失败页面,并重新开始游戏。
### input接受用户输入
### input接受用户输入数字
使用`{"type": "input"}`可以接受用户的输入。
使用`{"type": "input"}`可以接受用户的输入的数字
``` js
"x,y": [ // 实际执行的事件列表
{"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入内容
{"type": "input", "text": "请输入一个数"}, // 显示一个弹窗让用户输入数字
"你刚刚输入的数是${flag:input}" // 输入结果将被赋值为flag:input
]
```
@ -1014,6 +1014,25 @@ text为提示文字可以在这里给输入提示文字。这里同样可以
输入得到的结果将被赋值给flag:input可以供后续if来进行判断。
### input2接受用户输入文本
类似于input事件使用`{"type": "input2"}`可以接受用户的输入的文本。
``` js
"x,y": [ // 实际执行的事件列表
{"type": "input2", "text": "请输入你的ID"}, // 显示一个弹窗让用户输入文本
"你好,${flag:input},欢迎来到本塔" // 输入结果将被赋值为flag:input
]
```
text为提示文字可以在这里给输入提示文字。这里同样可以使用${ }来计算表达式的值。
当执行input2事件时将显示一个弹窗并提示用户输入一个内容。
该事件可以接收任何形式的文本输入,包括中文,空格,标点符号等等。如果用户点击取消按钮,则视为空字符串。
输入得到的结果也将被赋值给flag:input可以供后续使用。
### if条件判断
使用`{"type": "if"}`可以对条件进行判断,根据判断结果将会选择不同的分支执行。

View File

@ -750,6 +750,32 @@ events.prototype.doAction = function() {
this.doAction();
}
break;
case "input2":
{
var value;
if (core.status.replay.replaying) {
var action = core.status.replay.toReplay.shift();
try {
if (action.indexOf("input2:")!=0) throw new Error("Input2 Error. Current action: "+action);
value = core.decodeBase64(action.substring(7));
}
catch (e) {
console.log(e);
core.stopReplay();
core.drawTip("录像文件出错");
return;
}
}
else {
core.interval.onDownInterval = 'tmp';
value = prompt(core.replaceText(data.text));
if (!core.isset(value)) value="";
}
core.status.route.push("input2:"+core.encodeBase64(value));
core.setFlag("input", value);
this.doAction();
}
break;
case "if": // 条件判断
if (core.calValue(data.condition))
core.events.insertAction(data["true"])

View File

@ -336,6 +336,8 @@ utils.prototype.encodeRoute = function (route) {
ans+='G';
else if (t.indexOf('input:')==0)
ans+="P"+t.substring(6);
else if (t.indexOf('input2:')==0)
ans+="Q"+t.substring(7)+":";
else if (t=='no')
ans+='N';
else if (t.indexOf('move:')==0)
@ -370,7 +372,7 @@ utils.prototype.decodeRoute = function (route) {
}
var getString = function () {
var str="";
while (index<route.length && /\w/.test(route.charAt(index))) {
while (index<route.length && route.charAt(index)!=':') {
str+=route.charAt(index++);
}
index++;
@ -379,7 +381,7 @@ utils.prototype.decodeRoute = function (route) {
while (index<route.length) {
var c=route.charAt(index++);
var nxt=(c=='I'||c=='F'||c=='S')?getString():getNumber();
var nxt=(c=='I'||c=='F'||c=='S'||c=='Q')?getString():getNumber();
switch (c) {
case "U": for (var i=0;i<nxt;i++) ans.push("up"); break;
@ -393,6 +395,7 @@ utils.prototype.decodeRoute = function (route) {
case "T": ans.push("turn"); break;
case "G": ans.push("getNext"); break;
case "P": ans.push("input:"+nxt); break;
case "Q": ans.push("input2:"+nxt); break;
case "N": ans.push("no"); break;
case "M": ++index; ans.push("move:"+nxt+":"+getNumber()); break;
case "K": ans.push("key:"+nxt); break;