From b278306b3e0399ff215ff77a8590ed360aa09b6d Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 30 Jul 2021 11:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E9=9D=A2=E6=8C=AF=E5=8A=A8=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=20&=20=E8=87=AA=E7=BB=98setFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _docs/api.md | 9 +++++--- _docs/instruction.md | 4 ++-- _server/CodeMirror/defs.js | 4 ++-- _server/MotaAction.g4 | 32 ++++++++++++++++++++++++---- _server/MotaActionParser.js | 7 ++++++- _server/editor_blocklyconfig.js | 1 + _server/editor_ui.js | 1 + libs/events.js | 37 ++++++++++++++++++++------------- libs/ui.js | 5 +++++ project/plugins.js | 4 ++-- runtime.d.ts | 9 +++++--- 11 files changed, 82 insertions(+), 31 deletions(-) diff --git a/_docs/api.md b/_docs/api.md index 9fd58bfe..ea875434 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -1192,10 +1192,13 @@ unregisterSystemEvent: fn(type: string) useFly: fn(fromUserAction?: bool) 点击楼层传送器时的打开操作 -vibrate: fn(time?: number, callback?: fn()) -视野左右抖动 +vibrate: fn(direction?: string, time?: number, speed?: number, power?: number, callback?: fn()) +视野抖动 例如:core.vibrate(); // 视野左右抖动1秒 -time: 抖动时长,单位为毫秒。必须为半秒的倍数,不填或小于1秒都视为1秒 +direction: 抖动方向;可填 horizontal(左右),vertical(上下),diagonal1(左上右下),diagonal2(左下右上) +time: 抖动时长,单位为毫秒 +speed: 抖动速度 +power: 抖动幅度 callback: 抖动平息后的回调函数,可选 visitFloor: fn(floorId?: string) diff --git a/_docs/instruction.md b/_docs/instruction.md index a19e1659..d9064df0 100644 --- a/_docs/instruction.md +++ b/_docs/instruction.md @@ -451,8 +451,8 @@ core.insertAction({"type": "changeFloor", "floorId": "MT" + core.rand2(20)}) 这个类别的指令会负责动画、视角、色调、天气、音频等其他一些细节。 -1. **画面震动:**会让画面左右震动,时间必须为500毫秒的倍数且至少1秒。 - * 实际执行`core.vibrate(time, callback)`函数。 +1. **画面震动:**会让画面左右震动。 + * 实际执行`core.vibrate(direction, time, speed, pwoer, callback)`函数。 2. **显示动画:**如题,可以双击选文件并预览(预览的坐标锁定为视野中心)和试听/修改音效。 * 如需从地图选点请右击指令块,坐标也可写hero令动画跟随勇士移动。 * 坐标不写则取当前点,如果勾选“相对窗口坐标”则坐标应填写为0—12或0—14表示视野中的相对坐标(如13×13样板填两个6表示视野中心)。 diff --git a/_server/CodeMirror/defs.js b/_server/CodeMirror/defs.js index fc944a0f..308ea708 100644 --- a/_server/CodeMirror/defs.js +++ b/_server/CodeMirror/defs.js @@ -3757,8 +3757,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [ "!type": "fn(data?: ?)" }, "vibrate": { - "!doc": "视野左右抖动
例如:core.vibrate(); // 视野左右抖动1秒
time: 抖动时长,单位为毫秒。必须为半秒的倍数,不填或小于1秒都视为1秒
callback: 抖动平息后的回调函数,可选", - "!type": "fn(time?: number, callback?: fn())" + "!doc": "视野抖动
例如:core.vibrate(); // 视野抖动1秒
direction: 抖动方向;可填 horizontal(左右),vertical(上下),diagonal1(左上右下),diagonal2(左下右上)
time: 抖动时长
speed: 抖动速度
power: 抖动幅度
callback: 抖动平息后的回调函数,可选", + "!type": "fn(direction?: string, time?: number, speed?: number, power?: number, callback?: fn())" }, "confirmRestart": { "!doc": "询问是否需要重新开始", diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index d5c24ddb..4e7d53bb 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -865,6 +865,7 @@ action | previewUI_s | clearMap_s | setAttribute_s + | setFilter_s | fillText_s | fillBoldText_s | drawTextContent_s @@ -2093,17 +2094,16 @@ return code; */; vibrate_s - : '画面震动' '时间' Int '不等待执行完毕' Bool Newline + : '画面震动' '方向' Vibrate_List '时间' Int '速度' Int '振幅' Int '不等待执行完毕' Bool Newline /* vibrate_s tooltip : vibrate: 画面震动 helpUrl : /_docs/#/instruction -default : [2000,false] +default : ["horizontal",2000,10,10,false] colour : this.soundColor -Int_0 = Int_0 ?(', "time": '+Int_0):''; var async = Bool_0?', "async": true':'' -var code = '{"type": "vibrate"' + Int_0 + async + '},\n'; +var code = '{"type": "vibrate", "direction": "'+Vibrate_List_0+'", "time": '+Int_0+', "speed": '+Int_1+', "power": '+Int_2+async+'},\n'; return code; */; @@ -3170,6 +3170,26 @@ var code = '{"type": "setAttribute"'+FontString_0+ColorString_0+ColorString_1+In return code; */; + +setFilter_s + : '设置画布特效' '虚化' Number '色相' Int '灰度' Number '反色' Bool '阴影' Number Newline + + +/* setFilter_s +tooltip : setFilter: 设置画布特效 +helpUrl : /_docs/#/instruction +default : [0,0,0,false,0] +previewBlock : true +colour : this.uiColor +if (Number_0 < 0) throw '虚化不得小于0;0为完全没有虚化'; +if (Int_0 < 0 || Int_0 >= 360) throw '色相需要在0~359之间'; +if (Number_1 < 0 || Number_1 > 1) throw '灰度需要在0~1之间'; +if (Number_2 < 0) throw '阴影不得小于0;0为完全没有阴影'; +var code = '{"type": "setFilter", "blur": '+Number_0+', "hue": '+Int_0+', "grayscale": '+Number_1+', "invert": '+Bool_0+', "shadow": '+Number_2+'},\n'; +return code; +*/; + + fillText_s : '绘制文本' 'x' PosString 'y' PosString '样式' ColorString? Colour '字体' FontString? '最大宽度' IntString? BGNL? EvalString Newline @@ -3983,6 +4003,10 @@ EquipValueType_List : '数值项'|'百分比项' /*EquipValueType_List ['value','percentage']*/; +Vibrate_List + : '左右'|'上下'|'左上-右下'|'左下-右上' + /*Vibrate_List ['horizontal','vertical','diagonal1','diagonal2']*/; + Colour : 'sdeirughvuiyasdeb'+ //为了被识别为复杂词法规则 ; diff --git a/_server/MotaActionParser.js b/_server/MotaActionParser.js index da116d1b..169211e6 100644 --- a/_server/MotaActionParser.js +++ b/_server/MotaActionParser.js @@ -550,7 +550,8 @@ ActionParser.prototype.parseAction = function() { } break; case "vibrate": // 画面震动 - this.next = MotaActionBlocks['vibrate_s'].xmlText([data.time||0, data.async||false, this.next]); + this.next = MotaActionBlocks['vibrate_s'].xmlText([data.direction||'horizontal', + data.time||0, data.speed, data.power, data.async||false, this.next]); break; case "showImage": // 显示图片 data.loc=data.loc||['',''] @@ -954,6 +955,10 @@ ActionParser.prototype.parseAction = function() { data.font,data.fillStyle,'rgba('+data.fillStyle+')',data.strokeStyle,'rgba('+data.strokeStyle+')', data.lineWidth,data.alpha,data.align,data.baseline,data.z,this.next]); break; + case "setFilter": + this.next = MotaActionBlocks['setFilter_s'].xmlText([ + data.blur, data.hue, data.grayscale, data.invert||false, data.shadow, this.next]); + break; case "fillText": // 绘制一行文本 data.style = this.Colour(data.style); this.next = MotaActionBlocks['fillText_s'].xmlText([ diff --git a/_server/editor_blocklyconfig.js b/_server/editor_blocklyconfig.js index fada7272..59f2bcf5 100644 --- a/_server/editor_blocklyconfig.js +++ b/_server/editor_blocklyconfig.js @@ -227,6 +227,7 @@ editor_blocklyconfig=(function(){ MotaActionBlocks['previewUI_s'].xmlText(), MotaActionBlocks['clearMap_s'].xmlText(), MotaActionBlocks['setAttribute_s'].xmlText(), + MotaActionBlocks['setFilter_s'].xmlText(), MotaActionBlocks['fillText_s'].xmlText(), MotaActionBlocks['fillBoldText_s'].xmlText(), MotaActionBlocks['drawTextContent_s'].xmlText(), diff --git a/_server/editor_ui.js b/_server/editor_ui.js index 59202259..e7824c0f 100644 --- a/_server/editor_ui.js +++ b/_server/editor_ui.js @@ -374,6 +374,7 @@ editor_ui_wrapper = function (editor) { uievent.drawPreviewUI = function () { core.setAlpha('uievent', 1); core.clearMap('uievent'); + core.setFilter('uievent', null); // 绘制UI var background = uievent.elements.selectBackground.value; diff --git a/libs/events.js b/libs/events.js index b6ed4bdd..74347e85 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1072,9 +1072,10 @@ events.prototype.checkAutoEvents = function () { var todo = [], delay = []; core.status.autoEvents.forEach(function (autoEvent) { var symbol = autoEvent.symbol, x = autoEvent.x, y = autoEvent.y, floorId = autoEvent.floorId; - // 不在当前楼层 or 已经执行过 or 正在执行中 + // 不在当前楼层 or 已经执行过 or 已被分区 or 正在执行中 if (autoEvent.currentFloor && floorId != core.status.floorId) return; if (!autoEvent.multiExecute && core.autoEventExecuted(symbol)) return; + if ((flags.__removed__||[]).indexOf(floorId) >= 0) return; if (core.autoEventExecuting(symbol)) return; var prefix = floorId + "@" + x + "@" + y; try { @@ -2262,7 +2263,7 @@ events.prototype._action_hideHero = function (data, x, y, prefix) { } events.prototype._action_vibrate = function (data, x, y, prefix) { - this.__action_doAsyncFunc(data.async, core.vibrate, data.time); + this.__action_doAsyncFunc(data.async, core.vibrate, data.direction, data.time, data.speed, data.power); } events.prototype._action_sleep = function (data, x, y, prefix) { @@ -2537,6 +2538,10 @@ events.prototype._action_setAttribute = function (data, x, y, prefix) { this.__action_doUIEvent(data); } +events.prototype._action_setFilter = function (data, x, y, prefix) { + this.__action_doUIEvent(data); +} + events.prototype._action_drawImage = function (data, x, y, prefix) { this.__action_doUIEvent(data); } @@ -3125,41 +3130,45 @@ events.prototype.setVolume = function (value, time, callback) { } ////// 画面震动 ////// -events.prototype.vibrate = function (time, callback) { +events.prototype.vibrate = function (direction, time, speed, power, callback) { if (core.isReplaying()) { if (callback) callback(); return; } - if (!time || time < 1000) time = 1000; - // --- 将time调整为500的倍数(上整),不然会出错 - time /= Math.max(core.status.replay.speed, 1) - time = Math.ceil(time / 500) * 500; - var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0}; + if (!time) time = 1000; + speed = speed || 10; + power = power || 10; + var shakeInfo = {duration: parseInt(time / 10), speed: speed, power: power, direction: 1, shake: 0}; var animate = setInterval(function () { core.events._vibrate_update(shakeInfo); - core.control.addGameCanvasTranslate(shakeInfo.shake, 0); - if (shakeInfo.duration === 0) { + switch (direction) { + case 'vertical': core.addGameCanvasTranslate(0, shakeInfo.shake); break; + case 'diagonal1': core.addGameCanvasTranslate(shakeInfo.shake, shakeInfo.shake); break; + case 'diagonal2': core.addGameCanvasTranslate(-shakeInfo.shake, shakeInfo.shake); break; + default: core.addGameCanvasTranslate(shakeInfo.shake, 0); + } + if (shakeInfo.duration === 0 && shakeInfo.shake == 0) { delete core.animateFrame.asyncId[animate]; clearInterval(animate); if (callback) callback(); } - }, 50 / 3); + }, 10); core.animateFrame.asyncId[animate] = true; } events.prototype._vibrate_update = function (shakeInfo) { if (shakeInfo.duration >= 1 || shakeInfo.shake != 0) { - var delta = (shakeInfo.power * shakeInfo.speed * shakeInfo.direction) / 10.0; + var delta = shakeInfo.speed * shakeInfo.direction / 6; if (shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0) { shakeInfo.shake = 0; } else { shakeInfo.shake += delta; } - if (shakeInfo.shake > shakeInfo.power * 2) { + if (shakeInfo.shake > shakeInfo.power) { shakeInfo.direction = -1; } - if (shakeInfo.shake < -shakeInfo.power * 2) { + if (shakeInfo.shake < -shakeInfo.power) { shakeInfo.direction = 1; } if (shakeInfo.duration >= 1) { diff --git a/libs/ui.js b/libs/ui.js index 0ea36ac0..5e515ca7 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -521,6 +521,11 @@ ui.prototype._uievent_setAttribute = function (data) { } } +ui.prototype._uievent_setFilter = function (data) { + this._createUIEvent(); + this.setFilter('uievent',data); +} + ////// 计算某段文字的宽度 ////// ui.prototype.calWidth = function (name, text, font) { var ctx = this.getContextByName(name); diff --git a/project/plugins.js b/project/plugins.js index 1cfe137e..f3d14c06 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -1345,8 +1345,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = else if (step <= 12) core.drawHero('midFoot', 4 * o * (step - 8)); else if (step <= 16) core.drawHero('rightFoot', 4 * o * (step - 8)); // if (step == 8) { if (step == 8 || step == 16) { - core.setHeroLoc('x', x + o * core.utils.scan[direction].x, true); - core.setHeroLoc('y', y + o * core.utils.scan[direction].y, true); + core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true); + core.setHeroLoc('y', y + o * core.utils.scan2[direction].y, true); core.updateFollowers(); curr[1]--; if (curr[1] <= 0) moveSteps.shift(); diff --git a/runtime.d.ts b/runtime.d.ts index 2872d234..3ae707cb 100644 --- a/runtime.d.ts +++ b/runtime.d.ts @@ -1005,12 +1005,15 @@ declare class events { setVolume(value: number, time?: number, callback?: () => void): void /** - * 视野左右抖动 + * 视野抖动 * @example core.vibrate(); // 视野左右抖动1秒 - * @param time 抖动时长,单位为毫秒。必须为半秒的倍数,不填或小于1秒都视为1秒 + * @param direction 抖动方向 + * @param time 抖动时长,单位为毫秒 + * @param speed 抖动速度 + * @param power 抖动幅度 * @param callback 抖动平息后的回调函数,可选 */ - vibrate(time?: number, callback?: () => void): void + vibrate(direction?: string, time?: number, speed?: number, power?: number, callback?: () => void): void /** * 强制移动主角(包括后退),这个函数的作者已经看不懂这个函数了