事件:停止全部动画

This commit is contained in:
ckcz123 2021-09-02 18:54:25 +08:00
parent c38bc1a203
commit 02fd7f2f2a
8 changed files with 32 additions and 11 deletions

View File

@ -1806,9 +1806,9 @@ showFloorImage: fn(loc?: [number]|[[number]], floorId?: string, callback?: fn())
stairExists: fn(x: number, y: number, floorId?: string) -> bool
某个点是否存在楼梯
stopAnimate: fn(id: number, doCallback?: bool)
stopAnimate: fn(id?: number, doCallback?: bool)
立刻停止一个动画播放
id: 播放动画的编号即drawAnimate或drawHeroAnimate的返回值
id: 播放动画的编号即drawAnimate或drawHeroAnimate的返回值;不填视为停止所有动画
doCallback: 是否执行该动画的回调函数
terrainExists: fn(x: number, y: number, id?: string, floorId?: string) -> bool

View File

@ -3081,8 +3081,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!type": "fn(name: string, callback?: fn()) -> number"
},
"stopAnimate": {
"!doc": "立刻停止一个动画播放<br/>id: 播放动画的编号即drawAnimate或drawHeroAnimate的返回值<br/>doCallback: 是否执行该动画的回调函数",
"!type": "fn(id: number, doCallback?: bool)"
"!doc": "立刻停止一个动画播放<br/>id: 播放动画的编号即drawAnimate或drawHeroAnimate的返回值;不填视为所有动画br/>doCallback: 是否执行该动画的回调函数",
"!type": "fn(id?: number, doCallback?: bool)"
},
"getPlayingAnimates": {
"!doc": "获得当前正在播放的所有指定动画的id列表<br/>name: 动画名;不填代表返回全部正在播放的动画<br/>返回值: 一个数组每一项为一个正在播放的动画可用core.stopAnimate停止播放。",

View File

@ -869,6 +869,7 @@ action
| unfollow_s
| animate_s
| animate_1_s
| stopAnimate_s
| vibrate_s
| showImage_s
| showImage_1_s
@ -2081,6 +2082,17 @@ var code = '{"type": "animate", "name": "'+EvalString_0+'", "loc": "hero"'+Bool_
return code;
*/;
stopAnimate_s
: '停止所有动画' Newline
/* stopAnimate_s
tooltip : stopAnimate停止所有动画
helpUrl : /_docs/#/instruction
colour : this.soundColor
var code = '{"type": "stopAnimate"},\n';
return code;
*/;
setViewport_s
: '设置视角' '左上角坐标' 'x' PosString? ',' 'y' PosString? '移动方式' MoveMode_List '动画时间' Int '不等待执行完毕' Bool Newline

View File

@ -559,6 +559,9 @@ ActionParser.prototype.parseAction = function() {
data.name,data.loc[0],data.loc[1],data.alignWindow||false,data.async||false,this.next]);
}
break;
case "stopAnimate": // 停止所有动画
this.next = MotaActionBlocks['stopAnimate_s'].xmlText([this.next]);
break;
case "setViewport": // 设置视角
if (data.dxy) {
this.next = MotaActionBlocks['setViewport_1_s'].xmlText([

View File

@ -199,6 +199,7 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['vibrate_s'].xmlText(),
MotaActionBlocks['animate_s'].xmlText(),
MotaActionBlocks['animate_1_s'].xmlText(),
MotaActionBlocks['stopAnimate_s'].xmlText(),
MotaActionBlocks['setViewport_s'].xmlText(),
MotaActionBlocks['setViewport_1_s'].xmlText(),
MotaActionBlocks['lockViewport_s'].xmlText(),

View File

@ -1528,6 +1528,11 @@ events.prototype._action_animate = function (data, x, y, prefix) {
}
}
events.prototype._action_stopAnimate = function (data, x, y, prefix) {
core.stopAnimate();
core.doAction();
}
events.prototype._action_setViewport = function (data, x, y, prefix) {
if (data.dxy != null) {
data.loc = [core.bigmap.offsetX / 32 + (core.calValue(data.dxy[0], prefix) || 0), core.bigmap.offsetY / 32 + (core.calValue(data.dxy[1], prefix) || 0)];
@ -3467,16 +3472,16 @@ events.prototype.setVolume = function (value, time, callback) {
time /= Math.max(core.status.replay.speed, 1);
var per_time = 10, step = 0, steps = parseInt(time / per_time);
if (steps <= 0) steps = 1;
var fade = setInterval(function () {
var animate = setInterval(function () {
step++;
set(currVolume + (value - currVolume) * step / steps);
if (step >= steps) {
delete core.animateFrame.asyncId[fade];
clearInterval(fade);
delete core.animateFrame.asyncId[animate];
clearInterval(animate);
if (callback) callback();
}
}, per_time);
core.animateFrame.asyncId[fade] = true;
core.animateFrame.asyncId[animate] = true;
}
////// 画面震动 //////

View File

@ -3034,7 +3034,7 @@ maps.prototype._drawAnimateFrame = function (name, animate, centerX, centerY, in
maps.prototype.stopAnimate = function (id, doCallback) {
for (var i = 0; i < core.status.animateObjs.length; i++) {
var obj = core.status.animateObjs[i];
if (obj.id == id) {
if (id == null || obj.id == id) {
if (doCallback) {
(function (callback) {
setTimeout(function () {
@ -3044,7 +3044,7 @@ maps.prototype.stopAnimate = function (id, doCallback) {
}
}
}
core.status.animateObjs = core.status.animateObjs.filter(function (x) { return x.id != id });
core.status.animateObjs = core.status.animateObjs.filter(function (x) { return id != null && x.id != id });
if (core.status.animateObjs.length == 0)
core.clearMap('animate');
}

2
runtime.d.ts vendored
View File

@ -1778,7 +1778,7 @@ declare class maps {
* @param id drawAnimate或drawHeroAnimate返回值
* @param doCallback
*/
stopAnimate(id: number, doCallback?: boolean): void
stopAnimate(id?: number, doCallback?: boolean): void
/** 获得当前正在播放的所有指定动画的id列表 */
getPlayingAnimates(name?: string) : Array<number>