From 1cc55f5a112d98fdbfece6d85a129e3aabc10f44 Mon Sep 17 00:00:00 2001 From: oc Date: Mon, 22 Jan 2018 22:40:49 +0800 Subject: [PATCH] Prompt & Replay --- libs/core.js | 3 +++ libs/floors/sample1.js | 38 +++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/libs/core.js b/libs/core.js index fabce961..ca9fb2ae 100644 --- a/libs/core.js +++ b/libs/core.js @@ -3966,6 +3966,8 @@ core.prototype.encodeRoute = function (route) { ans+='T'; else if (t=='getNext') ans+='G'; + else if (t.indexOf('input:')==0) + ans+="P"+t.substring(6); } }); if (cnt>0) { @@ -4008,6 +4010,7 @@ core.prototype.decodeRoute = function (route) { case "S": ++index; ans.push("shop:"+shops[number]+":"+getNumber(true)); break; case "T": ans.push("turn"); break; case "G": ans.push("getNext"); break; + case "P": ans.push("input:"+number); break; } } return ans; diff --git a/libs/floors/sample1.js b/libs/floors/sample1.js index ee2d9b4e..9952e4a6 100644 --- a/libs/floors/sample1.js +++ b/libs/floors/sample1.js @@ -258,18 +258,34 @@ main.floors.sample1 = { "\t[老人,womanMagician]使用 {\"type\":\"function\"} 可以写自定义的JS脚本。\n本塔支持的所有主要API会在doc文档内给出。", "\t[老人,womanMagician]例如这个例子:即将弹出一个输入窗口,然后会将你的输入结果直接加到你的攻击力上。", {"type": "function", "function": function() { // 自己写JS脚本并执行 - var value = prompt("请输入你要加攻击力的数值:"); // 弹出一个输入框让用户输入数据 - if (value!=null) { - value=parseInt(value); - if (value>0) { // 检查 - core.setStatus("atk", core.getStatus("atk")+value); - // core.updateStatusBar(); // 和下面的 {"type": "update"} 等价,立即更新状态栏和地图显伤 - core.drawTip("操作成功,攻击+"+value); // 左上角气泡提示 - core.events.insertAction([ // 往当前事件列表前插入两条事件 - {"type": "update"}, // 更新状态栏和地图显伤 - "操作成功,攻击+"+value // 对话框提示 - ]); + + // 注意一下prompt对于录像是如何处理的 + var value; + if (core.status.replay.replaying) { + var action = core.status.replay.toReplay.shift(); + if (action.indexOf("input:")==0 ) { + value=parseInt(action.substring(6)); } + else { + core.status.replay.replaying=false; + core.drawTip("录像文件出错"); + return; + } + } + else { + value = prompt("请输入你要加攻击力的数值:"); + } + value = parseInt(value)||0; + core.status.route.push("input:"+value); + + if (value>0) { // 检查 + core.setStatus("atk", core.getStatus("atk")+value); + // core.updateStatusBar(); // 和下面的 {"type": "update"} 等价,立即更新状态栏和地图显伤 + core.drawTip("操作成功,攻击+"+value); // 左上角气泡提示 + core.events.insertAction([ // 往当前事件列表前插入两条事件 + {"type": "update"}, // 更新状态栏和地图显伤 + "操作成功,攻击+"+value // 对话框提示 + ]); } }}, "\t[老人,womanMagician]具体可参见样板中本事件的写法。"