Async events

This commit is contained in:
oc 2018-09-19 21:17:43 +08:00
parent 8e234d396c
commit feaa250a9c
3 changed files with 101 additions and 51 deletions

View File

@ -802,21 +802,22 @@ return code;
*/; */;
viberate_s viberate_s
: '画面震动' '时间' Int Newline : '画面震动' '时间' Int '异步' Bool Newline
/* viberate_s /* viberate_s
tooltip : viberate: 画面震动 tooltip : viberate: 画面震动
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=viberate%ef%bc%9a%e7%94%bb%e9%9d%a2%e9%9c%87%e5%8a%a8 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=viberate%ef%bc%9a%e7%94%bb%e9%9d%a2%e9%9c%87%e5%8a%a8
default : [2000] default : [2000,false]
colour : this.soundColor colour : this.soundColor
Int_0 = Int_0 ?(', "time": '+Int_0):''; Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "viberate"' + Int_0 + '},\n'; var async = Bool_0?', "async": true':''
var code = '{"type": "viberate"' + Int_0 + async + '},\n';
return code; return code;
*/; */;
animate_s animate_s
: '显示动画' IdString '位置' EvalString? '不等待绘制完毕' Bool Newline : '显示动画' IdString '位置' EvalString? '异步' Bool Newline
/* animate_s /* animate_s
@ -835,7 +836,8 @@ if (EvalString_0) {
throw new Error('此处只能填hero或者1,2形式的位置,或者不填代表当前事件点'); throw new Error('此处只能填hero或者1,2形式的位置,或者不填代表当前事件点');
} }
} }
var code = '{"type": "animate", "name": "'+IdString_0+'"'+EvalString_0+', "async": '+Bool_0+'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "animate", "name": "'+IdString_0+'"'+EvalString_0+async+'},\n';
return code; return code;
*/; */;
@ -865,28 +867,30 @@ return code;
*/; */;
animateImage_0_s animateImage_0_s
: '图片淡入' EvalString '起点像素位置' 'x' PosString 'y' PosString '动画时间' Int Newline : '图片淡入' EvalString '起点像素位置' 'x' PosString 'y' PosString '动画时间' Int '异步' Bool Newline
/* animateImage_0_s /* animateImage_0_s
tooltip : animageImage图片淡入 tooltip : animageImage图片淡入
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=animateimage%EF%BC%9A%E5%9B%BE%E7%89%87%E6%B7%A1%E5%85%A5%E6%B7%A1%E5%87%BA helpUrl : https://ckcz123.github.io/mota-js/#/event?id=animateimage%EF%BC%9A%E5%9B%BE%E7%89%87%E6%B7%A1%E5%85%A5%E6%B7%A1%E5%87%BA
default : ["bg.jpg","0","0",500] default : ["bg.jpg","0","0",500,false]
colour : this.printColor colour : this.printColor
var code = '{"type": "animateImage", "action": "show", "name": "'+EvalString_0+'", "loc": ['+PosString_0+','+PosString_1+'], "time": '+Int_0+'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "animateImage", "action": "show", "name": "'+EvalString_0+'", "loc": ['+PosString_0+','+PosString_1+'], "time": '+Int_0+async+'},\n';
return code; return code;
*/; */;
animateImage_1_s animateImage_1_s
: '图片淡出' EvalString '起点像素位置' 'x' PosString 'y' PosString '动画时间' Int Newline : '图片淡出' EvalString '起点像素位置' 'x' PosString 'y' PosString '动画时间' Int '异步' Bool Newline
/* animateImage_1_s /* animateImage_1_s
tooltip : animageImage图片淡出 tooltip : animageImage图片淡出
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=animateimage%EF%BC%9A%E5%9B%BE%E7%89%87%E6%B7%A1%E5%85%A5%E6%B7%A1%E5%87%BA helpUrl : https://ckcz123.github.io/mota-js/#/event?id=animateimage%EF%BC%9A%E5%9B%BE%E7%89%87%E6%B7%A1%E5%85%A5%E6%B7%A1%E5%87%BA
default : ["bg.jpg","0","0",500] default : ["bg.jpg","0","0",500,false]
colour : this.printColor colour : this.printColor
var code = '{"type": "animateImage", "action": "hide", "name": "'+EvalString_0+'", "loc": ['+PosString_0+','+PosString_1+'], "time": '+Int_0+'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "animateImage", "action": "hide", "name": "'+EvalString_0+'", "loc": ['+PosString_0+','+PosString_1+'], "time": '+Int_0+async+'},\n';
return code; return code;
*/; */;
@ -917,26 +921,27 @@ return code;
moveImage_0_s moveImage_0_s
: '图片移动' EvalString '起点像素位置' 'x' PosString 'y' PosString BGNL : '图片移动' EvalString '起点像素位置' 'x' PosString 'y' PosString BGNL
'终点像素位置' 'x' PosString 'y' PosString '移动时间' Int Newline '终点像素位置' 'x' PosString 'y' PosString '移动时间' Int '异步' Bool Newline
/* moveImage_0_s /* moveImage_0_s
tooltip : moveImage图片移动 tooltip : moveImage图片移动
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=moveimage%EF%BC%9A%E5%9B%BE%E7%89%87%E7%A7%BB%E5%8A%A8 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=moveimage%EF%BC%9A%E5%9B%BE%E7%89%87%E7%A7%BB%E5%8A%A8
default : ["bg.jpg","0","0","0","0",500] default : ["bg.jpg","0","0","0","0",500,false]
colour : this.printColor colour : this.printColor
var code = '{"type": "moveImage", "name": "'+EvalString_0+'", "from": ['+PosString_0+','+PosString_1+'], "to": ['+PosString_2+','+PosString_3+'], "time": '+Int_0+'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "moveImage", "name": "'+EvalString_0+'", "from": ['+PosString_0+','+PosString_1+'], "to": ['+PosString_2+','+PosString_3+'], "time": '+Int_0+async+'},\n';
return code; return code;
*/; */;
setFg_0_s setFg_0_s
: '更改画面色调' Number ',' Number ',' Number ',' Number '动画时间' Int? Newline : '更改画面色调' Number ',' Number ',' Number ',' Number '动画时间' Int? '异步' Bool Newline
/* setFg_0_s /* setFg_0_s
tooltip : setFg: 更改画面色调,动画时间可不填 tooltip : setFg: 更改画面色调,动画时间可不填
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setfg%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setfg%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83
default : [255,255,255,1,500] default : [255,255,255,1,500,false]
colour : this.soundColor colour : this.soundColor
var limit = function(v,min,max) { var limit = function(v,min,max) {
if(v>max) return max; if(v>max) return max;
@ -948,21 +953,23 @@ Number_1 = limit(Number_1,0,255);
Number_2 = limit(Number_2,0,255); Number_2 = limit(Number_2,0,255);
Number_3 = limit(Number_3,0,1); Number_3 = limit(Number_3,0,1);
Int_0 = Int_0 ?(', "time": '+Int_0):''; Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "setFg", "color": ['+Number_0+','+Number_1+','+Number_2+','+Number_3+']'+Int_0 +'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "setFg", "color": ['+Number_0+','+Number_1+','+Number_2+','+Number_3+']'+Int_0 +async+'},\n';
return code; return code;
*/; */;
setFg_1_s setFg_1_s
: '恢复画面色调' '动画时间' Int? Newline : '恢复画面色调' '动画时间' Int? '异步' Bool Newline
/* setFg_1_s /* setFg_1_s
tooltip : setFg: 恢复画面色调,动画时间可不填 tooltip : setFg: 恢复画面色调,动画时间可不填
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setfg%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setfg%EF%BC%9A%E6%9B%B4%E6%94%B9%E7%94%BB%E9%9D%A2%E8%89%B2%E8%B0%83
default : [500] default : [500,false]
colour : this.soundColor colour : this.soundColor
Int_0 = Int_0 ?(', "time": '+Int_0):''; Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "setFg"'+Int_0 +'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "setFg"'+Int_0 +async+'},\n';
return code; return code;
*/; */;
@ -1103,16 +1110,17 @@ return code;
*/; */;
setVolume_s setVolume_s
: '设置音量' Int '渐变时间' Int? Newline : '设置音量' Int '渐变时间' Int? '异步' Bool Newline
/* setVolume_s /* setVolume_s
tooltip : setVolume: 设置音量 tooltip : setVolume: 设置音量
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setvolume%EF%BC%9A%E8%AE%BE%E7%BD%AE%E9%9F%B3%E9%87%8F helpUrl : https://ckcz123.github.io/mota-js/#/event?id=setvolume%EF%BC%9A%E8%AE%BE%E7%BD%AE%E9%9F%B3%E9%87%8F
default : [90, 500] default : [90, 500, false]
colour : this.soundColor colour : this.soundColor
Int_1 = Int_1?(', "time": '+Int_1):"" Int_1 = Int_1?(', "time": '+Int_1):""
var code = '{"type": "setVolume", "value": '+Int_0+Int_1+'},\n'; var async = Bool_0?', "async": true':'';
var code = '{"type": "setVolume", "value": '+Int_0+Int_1+async+'},\n';
return code; return code;
*/; */;
@ -1803,10 +1811,10 @@ ActionParser.prototype.parseAction = function() {
var animate_loc = data.loc||''; var animate_loc = data.loc||'';
if(animate_loc && animate_loc!=='hero')animate_loc = animate_loc[0]+','+animate_loc[1]; if(animate_loc && animate_loc!=='hero')animate_loc = animate_loc[0]+','+animate_loc[1];
this.next = MotaActionBlocks['animate_s'].xmlText([ this.next = MotaActionBlocks['animate_s'].xmlText([
data.name,animate_loc,data.async||0,this.next]); data.name,animate_loc,data.async||false,this.next]);
break; break;
case "viberate": // 画面震动 case "viberate": // 画面震动
this.next = MotaActionBlocks['viberate_s'].xmlText([data.time||0, this.next]); this.next = MotaActionBlocks['viberate_s'].xmlText([data.time||0, data.async||false, this.next]);
break; break;
case "showImage": // 显示图片 case "showImage": // 显示图片
if(this.isset(data.name)){ if(this.isset(data.name)){
@ -1820,10 +1828,10 @@ ActionParser.prototype.parseAction = function() {
case "animateImage": // 显示图片 case "animateImage": // 显示图片
if(data.action == 'show'){ if(data.action == 'show'){
this.next = MotaActionBlocks['animateImage_0_s'].xmlText([ this.next = MotaActionBlocks['animateImage_0_s'].xmlText([
data.name,data.loc[0],data.loc[1],data.time,this.next]); data.name,data.loc[0],data.loc[1],data.time,data.async||false,this.next]);
} else if (data.action == 'hide') { } else if (data.action == 'hide') {
this.next = MotaActionBlocks['animateImage_1_s'].xmlText([ this.next = MotaActionBlocks['animateImage_1_s'].xmlText([
data.name,data.loc[0],data.loc[1],data.time,this.next]); data.name,data.loc[0],data.loc[1],data.time,data.async||false,this.next]);
} }
break; break;
case "showGif": // 显示动图 case "showGif": // 显示动图
@ -1837,7 +1845,7 @@ ActionParser.prototype.parseAction = function() {
break; break;
case "moveImage": // 移动图片 case "moveImage": // 移动图片
this.next = MotaActionBlocks['moveImage_0_s'].xmlText([ this.next = MotaActionBlocks['moveImage_0_s'].xmlText([
data.name, data.from[0], data.from[1], data.to[0], data.to[1], data.time, this.next data.name, data.from[0], data.from[1], data.to[0], data.to[1], data.time, data.async||false, this.next
]); ]);
break; break;
case "setFg": // 颜色渐变 case "setFg": // 颜色渐变
@ -1845,10 +1853,10 @@ ActionParser.prototype.parseAction = function() {
var alpha = data.color[3]; var alpha = data.color[3];
if (alpha==undefined || alpha==null) alpha=1; if (alpha==undefined || alpha==null) alpha=1;
this.next = MotaActionBlocks['setFg_0_s'].xmlText([ this.next = MotaActionBlocks['setFg_0_s'].xmlText([
data.color[0],data.color[1],data.color[2],alpha,data.time||0,this.next]); data.color[0],data.color[1],data.color[2],alpha,data.time||0,data.async||false,this.next]);
} else { } else {
this.next = MotaActionBlocks['setFg_1_s'].xmlText([ this.next = MotaActionBlocks['setFg_1_s'].xmlText([
data.time||0,this.next]); data.time||0,data.async||false,this.next]);
} }
break; break;
case "setWeather": // 更改天气 case "setWeather": // 更改天气
@ -1894,7 +1902,7 @@ ActionParser.prototype.parseAction = function() {
break break
case "setVolume": case "setVolume":
this.next = MotaActionBlocks['setVolume_s'].xmlText([ this.next = MotaActionBlocks['setVolume_s'].xmlText([
data.value, data.time, this.next]); data.value, data.time, data.async||false, this.next]);
break break
case "setValue": case "setValue":
this.next = MotaActionBlocks['setValue_s'].xmlText([ this.next = MotaActionBlocks['setValue_s'].xmlText([

View File

@ -741,7 +741,11 @@ name为可选的是要取消跟随的行走图文件名。
### viberate画面震动 ### viberate画面震动
使用 `{"type": "viberate", "time": 2000}` 可以造成画面震动效果后面time可以指定震动时间。 使用 `{"type": "viberate", "time": 2000, "async": true}` 可以造成画面震动效果。
time可以指定震动时间默认是2000毫秒。
async可选如果为true则会异步执行即不等待当前事件执行完毕立刻执行下一个事件
### animate显示动画 ### animate显示动画
@ -795,7 +799,7 @@ loc为图片左上角坐标以像素为单位进行计算。
``` js ``` js
"x,y": [ // 实际执行的事件列表 "x,y": [ // 实际执行的事件列表
{"type": "animateImage", "action": "show", "name": "bg.jpg", "loc": [231,297], "time": 500}, // 在(231,297)淡入bg.jpg动画时间500ms {"type": "animateImage", "action": "show", "name": "bg.jpg", "loc": [231,297], "time": 500}, // 在(231,297)淡入bg.jpg动画时间500ms
{"type": "animateImage", "action": "hide", "name": "1.png", "loc": [109,167], "time": 300}, // 在(109,167)淡出1.png动画时间300ms {"type": "animateImage", "action": "hide", "name": "1.png", "loc": [109,167], "time": 300, "async": true}, // 在(109,167)淡出1.png动画时间300ms,异步执行
] ]
``` ```
@ -807,6 +811,8 @@ loc为图片左上角坐标以像素为单位进行计算。
time为淡入淡出的时间如果是0则忽略此项。 time为淡入淡出的时间如果是0则忽略此项。
async可选如果为true则会异步执行即不等待当前事件执行完毕立刻执行下一个事件
!> 淡入淡出图片只是会在顶层绘制“淡入”和“淡出”效果动画结束即消失并不会实际对图片的显示造成影响。请与showImage事件合用。 !> 淡入淡出图片只是会在顶层绘制“淡入”和“淡出”效果动画结束即消失并不会实际对图片的显示造成影响。请与showImage事件合用。
如果多张图片的淡入淡出可以采用以下方式(仅供参考): 如果多张图片的淡入淡出可以采用以下方式(仅供参考):
@ -838,7 +844,7 @@ loc为动图左上角坐标以像素为单位进行计算。
``` js ``` js
"x,y": [ // 实际执行的事件列表 "x,y": [ // 实际执行的事件列表
{"type": "moveImage", "name": "bg.jpg", "from": [231,297], "to": [22,333], "time": 500}, {"type": "moveImage", "name": "bg.jpg", "from": [231,297], "to": [22,333], "time": 500, "async": true},
] ]
``` ```
@ -850,6 +856,8 @@ to为终点图片左上角坐标以像素为单位进行计算。
time为总移动的时间。 time为总移动的时间。
async可选如果为true则会异步执行即不等待当前事件执行完毕立刻执行下一个事件
!> 移动图片只是会在顶层绘制“移动”效果动画结束即消失并不会实际对图片的显示造成影响。请与showImage事件合用。 !> 移动图片只是会在顶层绘制“移动”效果动画结束即消失并不会实际对图片的显示造成影响。请与showImage事件合用。
### setFg更改画面色调 ### setFg更改画面色调
@ -859,7 +867,7 @@ time为总移动的时间。
``` js ``` js
"x,y": [ // 实际执行的事件列表 "x,y": [ // 实际执行的事件列表
{"type": "setFg", "color": [255,255,255,0.6], "time": 1000}, // 更改画面色调为纯白不透明度0.6动画时间1000毫秒 {"type": "setFg", "color": [255,255,255,0.6], "time": 1000}, // 更改画面色调为纯白不透明度0.6动画时间1000毫秒
{"type": "setFg", "color": [0,0,0]}, // 更改画面色调为纯黑不透明度1不指定动画时间使用默认时间 {"type": "setFg", "color": [0,0,0], "async": true}, // 更改画面色调为纯黑不透明度1不指定动画时间使用默认时间,且异步执行
{"type": "setFg"} // 如果不指定color则恢复原样。 {"type": "setFg"} // 如果不指定color则恢复原样。
] ]
``` ```
@ -872,6 +880,8 @@ color为需要更改画面色调的颜色。它是一个数组分别指定目
time为可选的如果指定则会作为更改画面色调的时间。 time为可选的如果指定则会作为更改画面色调的时间。
async可选如果为true则会异步执行即不等待当前事件执行完毕立刻执行下一个事件
### setWeather更改天气 ### setWeather更改天气
我们可以使用 `{"type": "setWeather"}` 来更改天气。 我们可以使用 `{"type": "setWeather"}` 来更改天气。
@ -1030,12 +1040,14 @@ time选项为该跳跃所需要用到的时间。
使用setVolume可以设置音量大小。 使用setVolume可以设置音量大小。
使用方法: `{"type": "setVolume", "value": 90, "time": 500}` 使用方法: `{"type": "setVolume", "value": 90, "time": 500, "async": true}`
value为音量大小在0到100之间默认为100。设置后BGM和SE都将使用该音量进行播放。 value为音量大小在0到100之间默认为100。设置后BGM和SE都将使用该音量进行播放。
可以设置time为音量渐变时间。 可以设置time为音量渐变时间。
async可选如果为true则会异步执行即不等待当前事件执行完毕立刻执行下一个事件
### win获得胜利 ### win获得胜利
`{"type": "win", "reason": "xxx"}` 将会直接调用events.js中的win函数并将reason作为结局传入。 `{"type": "win", "reason": "xxx"}` 将会直接调用events.js中的win函数并将reason作为结局传入。

View File

@ -594,10 +594,16 @@ events.prototype.doAction = function() {
} }
else { else {
if (core.isset(data.loc) && core.isset(core.material.images.images[data.name]) && (data.action=="show" || data.action=="hide")) { if (core.isset(data.loc) && core.isset(core.material.images.images[data.name]) && (data.action=="show" || data.action=="hide")) {
if (data.async) {
core.events.animateImage(data.action, core.material.images.images[data.name], data.loc, data.time);
this.doAction();
}
else {
core.events.animateImage(data.action, core.material.images.images[data.name], data.loc, data.time, function() { core.events.animateImage(data.action, core.material.images.images[data.name], data.loc, data.time, function() {
core.events.doAction(); core.events.doAction();
}); });
} }
}
else { else {
this.doAction(); this.doAction();
} }
@ -625,19 +631,31 @@ events.prototype.doAction = function() {
} }
else { else {
if (core.isset(data.from) && core.isset(data.to) && core.isset(core.material.images.images[data.name])) { if (core.isset(data.from) && core.isset(data.to) && core.isset(core.material.images.images[data.name])) {
if (data.async) {
core.events.moveImage(core.material.images.images[data.name], data.from, data.to, data.time);
this.doAction();
}
else {
core.events.moveImage(core.material.images.images[data.name], data.from, data.to, data.time, function() { core.events.moveImage(core.material.images.images[data.name], data.from, data.to, data.time, function() {
core.events.doAction(); core.events.doAction();
}); });
} }
}
else { else {
this.doAction(); this.doAction();
} }
} }
break; break;
case "setFg": // 颜色渐变 case "setFg": // 颜色渐变
if (data.async) {
core.setFg(data.color, data.time);
this.doAction();
}
else {
core.setFg(data.color, data.time, function() { core.setFg(data.color, data.time, function() {
core.events.doAction(); core.events.doAction();
}); });
}
break; break;
case "setWeather": // 更改天气 case "setWeather": // 更改天气
core.setWeather(data.name, data.level); core.setWeather(data.name, data.level);
@ -722,9 +740,15 @@ events.prototype.doAction = function() {
data.value = parseInt(data.value||0); data.value = parseInt(data.value||0);
if (data.value<0) data.value=0; if (data.value<0) data.value=0;
if (data.value>100) data.value=100; if (data.value>100) data.value=100;
if (data.async) {
this.setVolume(data.value/100, data.time);
this.doAction();
}
else {
this.setVolume(data.value/100, data.time, function() { this.setVolume(data.value/100, data.time, function() {
core.doAction(); core.events.doAction();
}); });
}
break; break;
case "setValue": case "setValue":
try { try {
@ -896,9 +920,15 @@ events.prototype.doAction = function() {
this.doAction(); this.doAction();
break; break;
case "viberate": case "viberate":
if (data.async) {
core.events.vibrate(data.time);
this.doAction();
}
else {
core.events.vibrate(data.time, function () { core.events.vibrate(data.time, function () {
core.events.doAction(); core.events.doAction();
}) })
}
break; break;
case "sleep": // 等待多少毫秒 case "sleep": // 等待多少毫秒
if (core.status.replay.replaying) if (core.status.replay.replaying)