From bf573675625547293a424c410311320adfc72754 Mon Sep 17 00:00:00 2001 From: oc Date: Sun, 30 Dec 2018 01:03:09 +0800 Subject: [PATCH] recover events --- _server/blockly/MotaAction.g4 | 6 +++--- libs/actions.js | 34 ++++++---------------------------- libs/control.js | 32 ++++---------------------------- libs/events.js | 15 +++++++++++++++ project/functions.js | 11 +---------- 5 files changed, 29 insertions(+), 69 deletions(-) diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 235bd9dc..62c99410 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -1565,7 +1565,7 @@ callBook_s /* callBook_s tooltip : callBook: 呼出怪物手册;返回游戏后将继续执行后面的事件 -helpUrl : https://h5mota.com/games/template/docs/#/event?id=waitAsync%ef%bc%9a%e7%ad%89%e5%be%85%e6%89%80%e6%9c%89%e5%bc%82%e6%ad%a5%e4%ba%8b%e4%bb%b6%e6%89%a7%e8%a1%8c%e5%ae%8c%e6%af%95 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=callBook%ef%bc%9a%e5%91%bc%e5%87%ba%e6%80%aa%e7%89%a9%e6%89%8b%e5%86%8c colour : this.soundColor var code = '{"type": "callBook"},\n'; return code; @@ -1578,7 +1578,7 @@ callSave_s /* callSave_s tooltip : callSave: 呼出存档页面;之后读此档将执行eachArrive -helpUrl : https://h5mota.com/games/template/docs/#/event?id=waitAsync%ef%bc%9a%e7%ad%89%e5%be%85%e6%89%80%e6%9c%89%e5%bc%82%e6%ad%a5%e4%ba%8b%e4%bb%b6%e6%89%a7%e8%a1%8c%e5%ae%8c%e6%af%95 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=callSave%ef%bc%9a%e5%91%bc%e5%87%ba%e5%ad%98%e6%a1%a3%e7%95%8c%e9%9d%a2 colour : this.soundColor var code = '{"type": "callSave"},\n'; return code; @@ -1591,7 +1591,7 @@ callLoad_s /* callLoad_s tooltip : callLoad: 呼出存档页面;返回游戏后将继续执行后面的事件 -helpUrl : https://h5mota.com/games/template/docs/#/event?id=waitAsync%ef%bc%9a%e7%ad%89%e5%be%85%e6%89%80%e6%9c%89%e5%bc%82%e6%ad%a5%e4%ba%8b%e4%bb%b6%e6%89%a7%e8%a1%8c%e5%ae%8c%e6%af%95 +helpUrl : https://h5mota.com/games/template/docs/#/event?id=callLoad%ef%bc%9a%e5%91%bc%e5%87%ba%e8%af%bb%e6%a1%a3%e7%95%8c%e9%9d%a2 colour : this.soundColor var code = '{"type": "callLoad"},\n'; return code; diff --git a/libs/actions.js b/libs/actions.js index d37b2fa3..1e54d657 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -886,13 +886,8 @@ actions.prototype.clickBook = function(x,y) { } // 返回 if (x>=10 && x<=12 && y==12) { - if (core.status.event.interval != null) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.events.recoverEvents(core.status.event.interval)) { + return; } else if (core.status.event.ui != null) { core.status.boxAnimateObjs = []; @@ -926,13 +921,8 @@ actions.prototype.keyDownBook = function (keycode) { ////// 怪物手册界面时,放开某个键的操作 ////// actions.prototype.keyUpBook = function (keycode) { if (keycode==27 || keycode==88) { - if (core.status.event.interval != null) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.events.recoverEvents(core.status.event.interval)) { + return; } else if (core.status.event.ui != null) { core.status.boxAnimateObjs = []; @@ -1663,13 +1653,7 @@ actions.prototype.clickSL = function(x,y) { } // 返回 if (x>=10 && x<=12 && y==12) { - if (core.status.event.interval != null) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.events.recoverEvents(core.status.event.interval)) { return; } core.ui.closePanel(); @@ -1784,13 +1768,7 @@ actions.prototype.keyUpSL = function (keycode) { var page = parseInt(index/10), offset=index%10; if (keycode==27 || keycode==88 || (core.status.event.id == 'save' && keycode==83) || (core.status.event.id == 'load' && keycode==68)) { - if (core.status.event.interval != null) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.events.recoverEvents(core.status.event.interval)) { return; } core.ui.closePanel(); diff --git a/libs/control.js b/libs/control.js index c29990e2..c9993ce0 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1967,13 +1967,7 @@ control.prototype.checkStatus = function (name, need, item) { control.prototype.openBook = function (need) { if (core.isReplaying()) return; - if (core.status.event.id == 'book' && core.isset(core.status.event.interval)) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.status.event.id == 'book' && core.events.recoverEvents(core.status.event.interval)) { return; } @@ -2050,13 +2044,7 @@ control.prototype.openQuickShop = function (need) { control.prototype.save = function(need) { if (core.isReplaying()) return; - if (core.status.event.id == 'save' && core.isset(core.status.event.interval)) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.status.event.id == 'save' && core.events.recoverEvents(core.status.event.interval)) { return; } @@ -2073,13 +2061,7 @@ control.prototype.save = function(need) { control.prototype.load = function (need) { if (core.isReplaying()) return; - if (core.status.event.id == 'load' && core.isset(core.status.event.interval)) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - core.doAction(); + if (core.status.event.id == 'load' && core.events.recoverEvents(core.status.event.interval)) { return; } @@ -2140,14 +2122,8 @@ control.prototype.doSL = function (id, type) { core.saves.saveIndex=id; core.setLocalStorage('saveIndex', core.saves.saveIndex); } - if (core.status.event.interval != null) { - var data = core.status.event.interval; - core.ui.closePanel(); - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; + if (core.events.recoverEvents(core.status.event.interval)) { core.drawTip("存档成功!"); - core.doAction(); return; } core.ui.closePanel(); diff --git a/libs/events.js b/libs/events.js index 1fc28cf1..ea445561 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1291,6 +1291,21 @@ events.prototype.insertAction = function (action, x, y, callback) { } } +////// 恢复一个事件 ////// +events.prototype.recoverEvents = function (data) { + if (core.isset(data)) { + core.ui.closePanel(); + core.lockControl(); + core.status.event.id = 'action'; + core.status.event.data = data; + setTimeout(function () { + core.doAction(); + }, 30); + return true; + } + return false; +} + ////// 获得面前的物品(轻按) ////// events.prototype.getNextItem = function() { if (!core.status.heroStop || !core.flags.enableGentleClick) return false; diff --git a/project/functions.js b/project/functions.js index f462b625..f4019573 100644 --- a/project/functions.js +++ b/project/functions.js @@ -146,16 +146,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 如果是读档,则进行检查 if (fromLoad) { - var data = core.getFlag("__events__"); - if (core.isset(data)) { - // 是事件中的存档... 恢复现场 - core.lockControl(); - core.status.event.id = 'action'; - core.status.event.data = data; - setTimeout(function () { - core.doAction(); - }, 30); - } + core.events.recoverEvents(core.getFlag("__events__")); } else { // 每次抵达楼层执行的事件