diff --git a/_docs/api.md b/_docs/api.md index a128c81c..abb6bf36 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -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 diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js index 96279c20..3d6e6d33 100644 --- a/_server/CodeMirror/defs.js +++ b/_server/CodeMirror/defs.js @@ -3081,8 +3081,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [ "!type": "fn(name: string, callback?: fn()) -> number" }, "stopAnimate": { - "!doc": "立刻停止一个动画播放
id: 播放动画的编号,即drawAnimate或drawHeroAnimate的返回值
doCallback: 是否执行该动画的回调函数", - "!type": "fn(id: number, doCallback?: bool)" + "!doc": "立刻停止一个动画播放
id: 播放动画的编号,即drawAnimate或drawHeroAnimate的返回值;不填视为所有动画br/>doCallback: 是否执行该动画的回调函数", + "!type": "fn(id?: number, doCallback?: bool)" }, "getPlayingAnimates": { "!doc": "获得当前正在播放的所有(指定)动画的id列表
name: 动画名;不填代表返回全部正在播放的动画
返回值: 一个数组,每一项为一个正在播放的动画;可用core.stopAnimate停止播放。", diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index aaa91f53..5ab58682 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -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 diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index aa2801b5..c89e9fab 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -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([ diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index 8ee847dd..48e1fea8 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -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(), diff --git a/libs/events.js b/libs/events.js index 6510e1be..f39f58eb 100644 --- a/libs/events.js +++ b/libs/events.js @@ -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; } ////// 画面震动 ////// diff --git a/libs/maps.js b/libs/maps.js index 5b6b5798..1f5e2d8b 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -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'); } diff --git a/runtime.d.ts b/runtime.d.ts index c79a589e..50200bf4 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -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