replay animate speed & step replay

This commit is contained in:
oc 2019-04-28 19:23:27 +08:00
parent e61d738f36
commit ccee812af7
6 changed files with 48 additions and 31 deletions

View File

@ -162,19 +162,21 @@ actions.prototype._sys_onkeyUp_replay = function (e) {
core.triggerReplay(); core.triggerReplay();
else if (e.keyCode == 65) // A else if (e.keyCode == 65) // A
core.rewindReplay(); core.rewindReplay();
else if (e.keyCode == 83) else if (e.keyCode == 83) // S
core.saveReplay(); core.saveReplay();
else if (e.keyCode == 67) else if (e.keyCode == 67) // C
core.bookReplay(); core.bookReplay();
else if (e.keyCode == 33 || e.keyCode == 34) else if (e.keyCode == 33 || e.keyCode == 34) // PgUp/PgDn
core.viewMapReplay(); core.viewMapReplay();
else if (e.keyCode >= 49 && e.keyCode <= 51) else if (e.keyCode == 78) // N
core.stepReplay();
else if (e.keyCode >= 49 && e.keyCode <= 51) // 1-3
core.setReplaySpeed(e.keyCode - 48); core.setReplaySpeed(e.keyCode - 48);
else if (e.keyCode == 52) else if (e.keyCode == 52) // 4
core.setReplaySpeed(6); core.setReplaySpeed(6);
else if (e.keyCode == 53) else if (e.keyCode == 53) // 5
core.setReplaySpeed(12); core.setReplaySpeed(12);
else if (e.keyCode == 54) else if (e.keyCode == 54) // 6
core.setReplaySpeed(24); core.setReplaySpeed(24);
return true; return true;
} }

View File

@ -1056,7 +1056,7 @@ control.prototype.chooseReplayFile = function () {
control.prototype.startReplay = function (list) { control.prototype.startReplay = function (list) {
if (!core.isPlaying()) return; if (!core.isPlaying()) return;
core.status.replay.replaying=true; core.status.replay.replaying=true;
core.status.replay.pausing=false; core.status.replay.pausing=true;
core.status.replay.speed=1.0; core.status.replay.speed=1.0;
core.status.replay.toReplay = core.clone(list); core.status.replay.toReplay = core.clone(list);
core.status.replay.totalList = core.status.route.concat(list); core.status.replay.totalList = core.status.route.concat(list);
@ -1092,16 +1092,24 @@ control.prototype.resumeReplay = function () {
core.replay(); core.replay();
} }
////// 单步播放 //////
control.prototype.stepReplay = function () {
if (!core.isPlaying() || !core.isReplaying()) return;
if (!core.status.replay.pausing) return core.drawTip("请先暂停录像");
if (core.isMoving() || core.status.replay.animate || core.status.event.id)
return core.drawTip("请等待当前事件的处理结束");
core.replay(true);
}
////// 加速播放 ////// ////// 加速播放 //////
control.prototype.speedUpReplay = function () { control.prototype.speedUpReplay = function () {
if (!core.isPlaying() || !core.isReplaying()) return; if (!core.isPlaying() || !core.isReplaying()) return;
if (core.status.replay.speed==12) core.status.replay.speed=24; var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
else if (core.status.replay.speed==6) core.status.replay.speed=12; for (var i = speeds.length - 2; i >= 0; i--) {
else if (core.status.replay.speed==3) core.status.replay.speed=6; if (speeds[i] <= core.status.replay.speed) {
else if (core.status.replay.speed==2.5) core.status.replay.speed=3; core.status.replay.speed = speeds[i+1];
else if (core.status.replay.speed==2) core.status.replay.speed=2.5; break;
else if (core.status.replay.speed<2) { }
core.status.replay.speed = parseInt(10*core.status.replay.speed + 2)/10;
} }
core.drawTip("x"+core.status.replay.speed+"倍"); core.drawTip("x"+core.status.replay.speed+"倍");
} }
@ -1109,15 +1117,13 @@ control.prototype.speedUpReplay = function () {
////// 减速播放 ////// ////// 减速播放 //////
control.prototype.speedDownReplay = function () { control.prototype.speedDownReplay = function () {
if (!core.isPlaying() || !core.isReplaying()) return; if (!core.isPlaying() || !core.isReplaying()) return;
if (core.status.replay.speed==24) core.status.replay.speed=12; var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
else if (core.status.replay.speed==12) core.status.replay.speed=6; for (var i = 1; i <= speeds.length; i++) {
else if (core.status.replay.speed==6) core.status.replay.speed=3; if (speeds[i] >= core.status.replay.speed) {
else if (core.status.replay.speed==3) core.status.replay.speed=2.5; core.status.replay.speed = speeds[i-1];
else if (core.status.replay.speed==2.5) core.status.replay.speed=2; break;
else { }
core.status.replay.speed = parseInt(10*core.status.replay.speed - 2)/10;
} }
if (core.status.replay.speed<0.2) core.status.replay.speed=0.2;
core.drawTip("x"+core.status.replay.speed+"倍"); core.drawTip("x"+core.status.replay.speed+"倍");
} }
@ -1218,9 +1224,10 @@ control.prototype.isReplaying = function () {
} }
////// 回放 ////// ////// 回放 //////
control.prototype.replay = function () { control.prototype.replay = function (force) {
if (!core.isPlaying() || !core.isReplaying() if (!core.isPlaying() || !core.isReplaying()
|| core.status.replay.pausing || core.status.replay.animate || core.status.event.id) return; || core.status.replay.animate || core.status.event.id) return;
if (core.status.replay.pausing && !force) return;
if (core.status.replay.toReplay.length==0) if (core.status.replay.toReplay.length==0)
return this._replay_finished(); return this._replay_finished();
this._replay_save(); this._replay_save();
@ -1412,9 +1419,9 @@ control.prototype._replayAction_shop = function (action) {
return true; return true;
} }
var choices = shop.choices; var choices = shop.choices;
var topIndex = core.__HALF_SIZE__ - parseInt(choices.length / 2);
core.status.event.selection = parseInt(selections.shift()); core.status.event.selection = parseInt(selections.shift());
core.events.openShop(shopId, false); core.events.openShop(shopId, false);
var topIndex = core.__HALF_SIZE__ - parseInt(choices.length / 2) + (core.status.event.ui.offset || 0);
var shopInterval = setInterval(function () { var shopInterval = setInterval(function () {
if (!core.actions._clickShop(core.__HALF_SIZE__, topIndex+core.status.event.selection)) { if (!core.actions._clickShop(core.__HALF_SIZE__, topIndex+core.status.event.selection)) {
clearInterval(shopInterval); clearInterval(shopInterval);
@ -2065,6 +2072,7 @@ control.prototype.setCurtain = function(color, time, callback) {
} }
control.prototype._setCurtain_animate = function (nowColor, color, time, callback) { control.prototype._setCurtain_animate = function (nowColor, color, time, callback) {
time /= Math.max(core.status.replay.speed, 1)
var per_time = 10, step = parseInt(time / per_time); var per_time = 10, step = parseInt(time / per_time);
var animate = setInterval(function() { var animate = setInterval(function() {
nowColor = [ nowColor = [

View File

@ -432,7 +432,7 @@ events.prototype._openDoor_animate = function (id, x, y, callback) {
} }
core.clearMap('event', 32 * x, 32 * y, 32, 32); core.clearMap('event', 32 * x, 32 * y, 32, 32);
core.drawImage('event', core.material.images.animates, 32 * state, 32 * door, 32, 32, 32 * x, 32 * y, 32, 32); core.drawImage('event', core.material.images.animates, 32 * state, 32 * door, 32, 32, 32 * x, 32 * y, 32, 32);
}, speed / core.status.replay.speed); }, speed / Math.max(core.status.replay.speed, 1));
} }
////// 开一个门后触发的事件 ////// ////// 开一个门后触发的事件 //////
@ -1884,7 +1884,7 @@ events.prototype.closeDoor = function (x, y, id, callback) {
} }
core.clearMap('event', 32 * x, 32 * y, 32, 32); core.clearMap('event', 32 * x, 32 * y, 32, 32);
core.drawImage('event', core.material.images.animates, 32 * (4-state), 32 * door, 32, 32, 32 * x, 32 * y, 32, 32); core.drawImage('event', core.material.images.animates, 32 * (4-state), 32 * door, 32, 32, 32 * x, 32 * y, 32, 32);
}, speed / core.status.replay.speed); }, speed / Math.max(core.status.replay.speed, 1));
core.animateFrame.asyncId[animate] = true; core.animateFrame.asyncId[animate] = true;
} }
@ -1958,7 +1958,8 @@ events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
var opacity = parseFloat(canvas.style.opacity), toOpacity = getOrDefault(opacityVal, opacity); var opacity = parseFloat(canvas.style.opacity), toOpacity = getOrDefault(opacityVal, opacity);
this._moveImage_moving(name, { this._moveImage_moving(name, {
fromX: fromX, fromY: fromY, toX: toX, toY: toY, opacity: opacity, toOpacity: toOpacity, time: time fromX: fromX, fromY: fromY, toX: toX, toY: toY, opacity: opacity, toOpacity: toOpacity,
time: time / Math.max(core.status.replay.speed, 1)
}, callback) }, callback)
} }
@ -2016,6 +2017,7 @@ events.prototype.setVolume = function (value, time, callback) {
return; return;
} }
var currVolume = core.musicStatus.volume; var currVolume = core.musicStatus.volume;
time /= Math.max(core.status.replay.speed, 1);
var per_time = 10, step = 0, steps = parseInt(time / per_time); var per_time = 10, step = 0, steps = parseInt(time / per_time);
var fade = setInterval(function () { var fade = setInterval(function () {
step++; step++;
@ -2037,6 +2039,7 @@ events.prototype.vibrate = function (time, callback) {
} }
if (!time || time < 1000) time = 1000; if (!time || time < 1000) time = 1000;
// --- 将time调整为500的倍数上整不然会出错 // --- 将time调整为500的倍数上整不然会出错
time /= Math.max(core.status.replay.speed, 1)
time = Math.ceil(time / 500) * 500; time = Math.ceil(time / 500) * 500;
var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0}; var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0};
var animate = setInterval(function () { var animate = setInterval(function () {

View File

@ -35,7 +35,7 @@ items.prototype._resetItems = function () {
if (core.flags.bombFourDirections) if (core.flags.bombFourDirections)
core.material.items.bomb.text = "可以炸掉勇士四周的怪物"; core.material.items.bomb.text = "可以炸掉勇士四周的怪物";
if (core.flags.snowFourDirections) if (core.flags.snowFourDirections)
core.material.items.bomb.text = "可以将四周的熔岩变成平地"; core.material.items.snow.text = "可以将四周的熔岩变成平地";
if (core.flags.equipment) { if (core.flags.equipment) {
core.material.items.sword1.cls = 'equips'; core.material.items.sword1.cls = 'equips';
core.material.items.sword2.cls = 'equips'; core.material.items.sword2.cls = 'equips';

View File

@ -238,7 +238,8 @@ maps.prototype.saveMap = function (floorId) {
if (!floorId) { if (!floorId) {
var map = {}; var map = {};
for (var id in maps) { for (var id in maps) {
map[id] = this.saveMap(id); var obj = this.saveMap(id);
if (Object.keys(obj).length > 0) map[id] = obj;
} }
return map; return map;
} }
@ -1688,6 +1689,7 @@ maps.prototype.jumpBlock = function (sx, sy, ex, ey, time, keep, callback) {
maps.prototype.__generateJumpInfo = function (sx, sy, ex, ey, time) { maps.prototype.__generateJumpInfo = function (sx, sy, ex, ey, time) {
var dx = ex - sx, dy = ey - sy, distance = Math.round(Math.sqrt(dx * dx + dy * dy)); var dx = ex - sx, dy = ey - sy, distance = Math.round(Math.sqrt(dx * dx + dy * dy));
var jump_peak = 6 + distance, jump_count = jump_peak * 2; var jump_peak = 6 + distance, jump_count = jump_peak * 2;
time /= Math.max(core.status.replay.speed, 1)
return { return {
x: sx, y: sy, ex: ex, ey: ey, px: 32 * sx, py: 32 * sy, opacity: 1, x: sx, y: sy, ex: ex, ey: ey, px: 32 * sx, py: 32 * sy, opacity: 1,
jump_peak: jump_peak, jump_count: jump_count, jump_peak: jump_peak, jump_count: jump_count,
@ -1751,6 +1753,7 @@ maps.prototype.animateBlock = function (loc, type, time, callback) {
return; return;
} }
this._animateBlock_drawList(list, isHide ? 1 : 0); this._animateBlock_drawList(list, isHide ? 1 : 0);
time /= Math.max(core.status.replay.speed, 1)
this._animateBlock_doAnimate(loc, list, isHide, 10 / time, callback); this._animateBlock_doAnimate(loc, list, isHide, 10 / time, callback);
} }

View File

@ -971,6 +971,7 @@ ui.prototype.drawScrollText = function (content, time, lineHeight, callback) {
ui.prototype._drawScrollText_animate = function (ctx, time, callback) { ui.prototype._drawScrollText_animate = function (ctx, time, callback) {
// 开始绘制到UI上 // 开始绘制到UI上
time /= Math.max(core.status.replay.speed, 1)
var per_pixel = 1, height = ctx.canvas.height, per_time = time * per_pixel / (this.PIXEL+height); var per_pixel = 1, height = ctx.canvas.height, per_time = time * per_pixel / (this.PIXEL+height);
var currH = this.PIXEL; var currH = this.PIXEL;
core.drawImage('ui', ctx.canvas, 0, currH); core.drawImage('ui', ctx.canvas, 0, currH);