From 32c9d58b6534aaf30372a4db58518a55bb8e534a Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 25 Jan 2018 01:56:00 +0800 Subject: [PATCH] Replay Control --- images/forward.png | Bin 0 -> 662 bytes images/pause.png | Bin 0 -> 269 bytes images/play.png | Bin 0 -> 340 bytes images/rewind.png | Bin 0 -> 689 bytes images/stop.png | Bin 0 -> 239 bytes libs/core.js | 166 +++++++++++++++++++++++++++++++++-------- libs/events.js | 12 +-- libs/floors/sample1.js | 2 +- main.js | 43 ++++++++++- 9 files changed, 185 insertions(+), 38 deletions(-) create mode 100644 images/forward.png create mode 100644 images/pause.png create mode 100644 images/play.png create mode 100644 images/rewind.png create mode 100644 images/stop.png diff --git a/images/forward.png b/images/forward.png new file mode 100644 index 0000000000000000000000000000000000000000..6701f077e302bbbd9cf8bae601cbf3ffd3c3843b GIT binary patch literal 662 zcmV;H0%`q;P)QO=(`cYVAUa{?|v>7Ufbm6y(YAS z?~M1J`<-(S-*A8g3I2Cbt3xG6&amd2U_EaasxR6-R#VPZ7IdDOpB>6qOFc2bw~p^n znfea^{Q$tg6T7zmF3o;whIzFILyi_!Wpzftz@(k`W(eRo2E_UUW&hgyPkhzkZI!8i z@F$(2FfX8#9r}PpKv7M(udDLNzOD?k!7*6$QRRlu8d-#~omwo^-eutRv!<6S=N5SamTBOICG_QJ8hYh>1T#wj z20PPuu1{Fk56JRztJ}Bv>qTF>Cwgrl4hEs|R!Mhky9@xp9@co}%hB|9 z82|uH4ZUXXw$i{dfi7nsm)9(KYKz1dEiJ|mJ}Ot%Uv!heQZyRR^$BsRl{m1u1ekys z7W@X9-WhmJFx{~W-mGa@+ywqG=vp@K-RD3A2HrOaK4%vyMsXlk0_+6>;{($B+<~~D zg}8KBmcK-q8a07ZAetu!WYs86gr^OmPe&C8S|pJ5cmGtG`fqe7Bo?punk+`BkYuOh w7n1gsjDs7{C>bkR&Y57M3*A(*1PK!S1r?Xa*9qfXy#N3J07*qoM6N<$f?tLh`Tzg` literal 0 HcmV?d00001 diff --git a/images/pause.png b/images/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..db4f3aeaa0ee0a3674d183ea267a924931c3ce7e GIT binary patch literal 269 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z1UW&N@xaqX50GvsOx5MX8Jz329(+12m4;u@9SCpw%nxSuFB*;so%d3|1e$tT{N%{*_Wa37l? ztCH2Z{K)IvcS5NL)~d*9mrtYi(!L~%iy%#E;^2WRdk16{@7>FVdQ I&MBb@0PV0{ZU6uP literal 0 HcmV?d00001 diff --git a/images/play.png b/images/play.png new file mode 100644 index 0000000000000000000000000000000000000000..34cfd72f6b7b9e66b4152f0f446cf068b81320f2 GIT binary patch literal 340 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z1UW&N@xaqX5XSs5-ZvO!&^_$FM?czeKV&0%+CMXs}Hu`yq=hnub z(=U%JR8&)Y7V5%n==?=cmHU8{?Xw06#Z&uPa)cP{)wfS=6FqSLrsJ%z29=b~jA+I` zF)~Y%Su5H~)-u$s>kwU(&gzku(x(x@_{S&i>XS?BH8g&H@ZVJ3)Ou7{MljjMcFzy% z2K{wQ_5Ii_6xupoeLtGmuvdFsO86higyVnxG}7Y#$ZaS+s`>9#LBmhSOHMw5%szgb dX3VHR$!l1;-9qYLY7x+L44$rjF6*2UngCmPeE|Rf literal 0 HcmV?d00001 diff --git a/images/rewind.png b/images/rewind.png new file mode 100644 index 0000000000000000000000000000000000000000..bafb4ee1bf9e142f54cb5fdc37dfeb110314ce9c GIT binary patch literal 689 zcmV;i0#5yjP)YxY?aj2jm zbdf5E&`Yd1wz})!CL;Axunu*Qh!rY0C`dc`amgS~da137AmRr#2+}0?x>QMvNv}z; zp!tn|o_l}Kz5F>28foNzk5v1h<-Cf4oKRsrW1F|jab1qrs}K`|5x38rtX)7=qQlui zQ7!->K*L(t`XtdYQ;J2C=_a)GvcT#2qnyg@hKz0HOS$lJx_1t}S-(2z-2~|_eTf21 z8-d>fomXFP5iO1ZyGpngXlVsLRV83u%kIFKyNgPs5*JNo4~Q01KwFTxMi3~P^m-6| zj8eJW@dicpLC|toVgo%X4b6PXUQ}g(3im}q{u;~iMuFa-#Y+n8x#F#x{+b;H4lgxC zeYp;7UT%3=f!)rORm2}d*%WY2Rps!9J776e-9G*!2wYxM7HlAzeA$NjcYx-1~Gw;uwSA2=^6%y+ X0ob!c_$!*600000NkvXXu0mjfHSRF> literal 0 HcmV?d00001 diff --git a/images/stop.png b/images/stop.png new file mode 100644 index 0000000000000000000000000000000000000000..8a2a12196254bd1285fefc61ab3bebca897b2252 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z1UW&N@xaqX5GGvsP8;Bk8xF1lw$^W=2FJ2unh+*TYBULv5Y_gB7zOZC1)z^bp4%nfEVvP#&$ z+tFZpQ0`Z1fmFoO@`~zRO$+%uPxIz8>{n@EVB$~!5>pt;kJ{dp-qFsqfiYOs;f+l2 bs+Dp@&-HCeH)y{D+RNbS>gTe~DWM4fs}oDh literal 0 HcmV?d00001 diff --git a/libs/core.js b/libs/core.js index e5a4cafe..b5d3efeb 100644 --- a/libs/core.js +++ b/libs/core.js @@ -102,7 +102,8 @@ function core() { 'pausing': false, 'animate': false, // 正在某段动画中 'toReplay': [], - 'totalList': [] + 'totalList': [], + 'speed': 1.0 }, // event事件 @@ -603,7 +604,18 @@ core.prototype.onkeyDown = function(e) { ////// 放开某个键时 ////// core.prototype.onkeyUp = function(e) { - if (core.isset(core.status.replay)&&core.status.replay.replaying) return; + if (core.isset(core.status.replay)&&core.status.replay.replaying) { + if (e.keyCode==27) // ESCAPE + core.stopReplay(); + else if (e.keyCode==90) // Z + core.rewindReplay(); + else if (e.keyCode==88) // X + core.forwardReplay(); + else if (e.keyCode==32) // SPACE + core.triggerReplay(); + return; + } + var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] if(isArrow && !core.status.lockControl){ for(var ii =0;ii= core.values.animateSpeed * 2 / animateValue) { animateCurrent++; animateTime = 0; @@ -2502,7 +2514,7 @@ core.prototype.moveBlock = function(x,y,steps,time,immediateHide,callback) { moveSteps.shift(); } } - }, time/16); + }, time / 16 / core.status.replay.speed); } ////// 显示/隐藏某个块时的动画效果 ////// @@ -2547,7 +2559,7 @@ core.prototype.animateBlock = function (x,y,type,time,callback) { core.status.replay.animate=false; if (core.isset(callback)) callback(); } - }, time/10); + }, time / 10 / core.status.replay.speed); } ////// 将某个块从禁用变成启用状态 ////// @@ -3493,22 +3505,79 @@ core.prototype.debug = function() { core.drawTip("作弊成功"); } -////// 回放 ////// -core.prototype.replay = function (list) { +////// 开始播放 ////// +core.prototype.startReplay = function (list) { + core.status.replay.replaying=true; + core.status.replay.pausing=false; + core.status.replay.speed=1.0; + core.status.replay.toReplay = core.clone(list); + core.status.replay.totalList = core.clone(list); + core.updateStatusBar(); + core.drawTip("开始播放"); + this.replay(); + return; +} - if (core.isset(list) && (list instanceof Array)) { - core.status.replay.replaying=true; - core.status.replay.toReplay = core.clone(list); - this.replay(); - return; - } +////// 更改播放状态 ////// +core.prototype.triggerReplay = function () { + if (core.status.replay.pausing) this.resumeReplay(); + else this.pauseReplay(); +} + +////// 暂停播放 ////// +core.prototype.pauseReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.pausing = true; + core.updateStatusBar(); + core.drawTip("暂停播放"); +} + +////// 恢复播放 ////// +core.prototype.resumeReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.pausing = false; + core.updateStatusBar(); + core.drawTip("恢复播放"); + core.replay(); +} + +////// 加速播放 ////// +core.prototype.forwardReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.speed = parseInt(10*core.status.replay.speed + 1)/10; + if (core.status.replay.speed>2.5) core.status.replay.speed=2.5; + core.drawTip("x"+core.status.replay.speed+"倍"); +} + +////// 减速播放 ////// +core.prototype.rewindReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.speed = parseInt(10*core.status.replay.speed - 1)/10; + if (core.status.replay.speed<0.3) core.status.replay.speed=0.3; + core.drawTip("x"+core.status.replay.speed+"倍"); +} + +////// 停止播放 ////// +core.prototype.stopReplay = function () { + if (!core.status.replay.replaying) return; + core.status.replay.toReplay = []; + core.status.replay.totalList = []; + core.status.replay.replaying=false; + core.status.replay.pausing=false; + core.status.replay.speed=1.0; + core.updateStatusBar(); + core.drawTip("停止播放并恢复游戏"); +} + +////// 回放 ////// +core.prototype.replay = function () { if (!core.status.replay.replaying) return; // 没有回放 if (core.status.replay.pausing) return; // 暂停状态 if (core.status.replay.animate) return; // 正在某段动画中 if (core.status.replay.toReplay.length==0) { // 回放完毕 - core.status.replay.replaying=false; + core.stopReplay(); core.insertAction("录像回放完毕!"); return; } @@ -3576,7 +3645,7 @@ core.prototype.replay = function (list) { var selection = parseInt(selections.shift()); if (isNaN(selection) || selection<0 || selection>=choices.length || !core.events.clickShop(6, topIndex+selection)) { clearInterval(shopInterval); - core.status.replay.replaying=false; + core.stopReplay(); core.drawTip("录像文件出错"); return; } @@ -3603,7 +3672,7 @@ core.prototype.replay = function (list) { } } - core.status.replay.replaying=false; + core.stopReplay(); core.insertAction("录像文件出错"); } @@ -4111,6 +4180,7 @@ core.prototype.readFile = function (success, error) { return; } core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); + core.platform.fileInput.value = ''; } } @@ -4407,16 +4477,52 @@ core.prototype.updateStatusBar = function () { } core.statusBar.hard.innerHTML = core.status.hard; - if (core.hasItem('book')) { + + + // 回放 + if (core.status.replay.replaying) { + core.statusBar.image.book.src = core.status.replay.pausing?core.statusBar.icons.play.src:core.statusBar.icons.pause.src; core.statusBar.image.book.style.opacity = 1; - } else { - core.statusBar.image.book.style.opacity = 0.3; - } - if (core.hasItem('fly')) { + + core.statusBar.image.fly.src = core.statusBar.icons.stop.src; core.statusBar.image.fly.style.opacity = 1; - } else { - core.statusBar.image.fly.style.opacity = 0.3; + + //core.statusBar.image.toolbox.src = core.statusBar.icons.forward.src; + core.statusBar.image.toolbox.style.opacity = 0; + + core.statusBar.image.shop.style.opacity = 0; + + core.statusBar.image.save.src = core.statusBar.icons.rewind.src; + core.statusBar.image.save.style.opacity = 1; + + core.statusBar.image.load.src = core.statusBar.icons.forward.src; + core.statusBar.image.load.style.opacity = 1; + + core.statusBar.image.settings.style.opacity = 0; + } + else { + core.statusBar.image.book.src = core.statusBar.icons.book.src; + core.statusBar.image.book.style.opacity = core.hasItem('book')?1:0.3; + + core.statusBar.image.fly.src = core.statusBar.icons.fly.src; + core.statusBar.image.fly.style.opacity = core.hasItem('fly')?1:0.3; + + core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src; + core.statusBar.image.toolbox.style.opacity = 1; + + core.statusBar.image.shop.style.opacity = 1; + + core.statusBar.image.save.src = core.statusBar.icons.save.src; + core.statusBar.image.save.style.opacity = 1; + + core.statusBar.image.load.src = core.statusBar.icons.load.src; + core.statusBar.image.load.style.opacity = 1; + + core.statusBar.image.settings.src = core.statusBar.icons.settings.src; + core.statusBar.image.settings.style.opacity = 1; + } + core.updateFg(); } diff --git a/libs/events.js b/libs/events.js index 369ab144..a0e30a13 100644 --- a/libs/events.js +++ b/libs/events.js @@ -115,7 +115,7 @@ events.prototype.setInitData = function (hard) { events.prototype.win = function(reason) { core.ui.closePanel(); var replaying = core.status.replay.replaying; - core.status.replay.replaying=false; + core.stopReplay(); core.waitHeroToStop(function() { core.removeGlobalAnimate(0,0,true); core.clearMap('all'); // 清空全地图 @@ -131,9 +131,8 @@ events.prototype.win = function(reason) { events.prototype.lose = function(reason) { core.ui.closePanel(); var replaying = core.status.replay.replaying; - core.status.replay.replaying=false; + core.stopReplay(); core.waitHeroToStop(function() { - core.status.replay.replaying=false; core.drawText([ "\t[结局1]你死了。\n如题。" ], function () { @@ -481,7 +480,7 @@ events.prototype.doAction = function() { }, 500) } else { - core.status.replay.replaying=false; + core.stopReplay(); core.drawTip("录像文件出错"); } } @@ -1047,9 +1046,10 @@ events.prototype.clickFly = function(x,y) { var index=core.status.hero.flyRange.indexOf(core.status.floorId); var stair=core.status.event.data