From be5c13f717f308d3d9f13766a336b4db40b322aa Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 27 Dec 2018 20:34:38 +0800 Subject: [PATCH] Ctrl skip sleep --- _server/blockly/MotaAction.g4 | 9 +++++---- libs/actions.js | 8 ++++++++ libs/core.js | 1 + libs/events.js | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index c60f37a5..a32f326f 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -857,15 +857,16 @@ return code; */; sleep_s - : '等待' Int '毫秒' Newline + : '等待' Int '毫秒' '不可被Ctrl跳过' Bool Newline /* sleep_s tooltip : sleep: 等待多少毫秒 helpUrl : https://h5mota.com/games/template/docs/#/event?id=sleep%EF%BC%9A%E7%AD%89%E5%BE%85%E5%A4%9A%E5%B0%91%E6%AF%AB%E7%A7%92 -default : [500] +default : [500, false] colour : this.soundColor -var code = '{"type": "sleep", "time": '+Int_0+'},\n'; +Bool_0 = Bool_0?', "noSkip": true':''; +var code = '{"type": "sleep", "time": '+Int_0+Bool_0+'},\n'; return code; */; @@ -2354,7 +2355,7 @@ ActionParser.prototype.parseAction = function() { break; case "sleep": // 等待多少毫秒 this.next = MotaActionBlocks['sleep_s'].xmlText([ - data.time||0,this.next]); + data.time||0,data.noSkip||false,this.next]); break; case "wait": // 等待用户操作 this.next = MotaActionBlocks['wait_s'].xmlText([ diff --git a/libs/actions.js b/libs/actions.js index a538b37f..1ece88dc 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -698,6 +698,14 @@ actions.prototype.keyDownCtrl = function () { core.doAction(); return; } + if (core.status.event.id=='action' && core.status.event.data.type=='sleep' + && !core.status.event.data.current.noSkip) { + if (core.isset(core.timeout.sleepTimeout)) { + clearTimeout(core.timeout.sleepTimeout); + core.timeout.sleepTimeout = null; + core.events.doAction(); + } + } } ////// diff --git a/libs/core.js b/libs/core.js index ce1e6d42..d5d6c9df 100644 --- a/libs/core.js +++ b/libs/core.js @@ -20,6 +20,7 @@ function core() { 'getItemTipTimeout': null, 'turnHeroTimeout': null, 'onDownTimeout': null, + 'sleepTimeout': null, } this.interval = { 'heroMoveInterval': null, diff --git a/libs/events.js b/libs/events.js index ed5c4739..d58d217e 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1178,7 +1178,8 @@ events.prototype.doAction = function() { } break; case "sleep": // 等待多少毫秒 - setTimeout(function() { + core.timeout.sleepTimeout = setTimeout(function() { + core.timeout.sleepTimeout = null; core.events.doAction(); }, core.status.replay.replaying?20:data.time); break;