Refactor battle.switchSides

The details of maintaining the current battle state while switching
sides is now handled in battle.js rather than client-battle.js, to
help the replay player support it more easily.
This commit is contained in:
Guangcong Luo
2015-11-06 06:08:42 -05:00
parent 50f475ca5b
commit 63cd9ae162
2 changed files with 21 additions and 20 deletions

View File

@@ -2536,8 +2536,25 @@ var Battle = (function () {
}
this.activityWait(effectElem);
};
Battle.prototype.switchSides = function () {
this.sidesSwitched = !this.sidesSwitched;
Battle.prototype.switchSides = function (replay) {
if (replay) {
this.reset(true);
this.setSidesSwitched(!this.sidesSwitched);
this.play();
} else if (this.done) {
this.reset(true);
this.setSidesSwitched(!this.sidesSwitched);
this.fastForwardTo(-1);
} else {
var turn = this.turn;
this.reset(true);
this.setSidesSwitched(!this.sidesSwitched);
if (turn) this.fastForwardTo(turn);
this.play(true);
}
};
Battle.prototype.setSidesSwitched = function (sidesSwitched) {
this.sidesSwitched = sidesSwitched;
if (this.sidesSwitched) {
this.mySide = this.p2;
this.yourSide = this.p1;

View File

@@ -669,13 +669,7 @@
if (!sideData.id) return;
this.side = sideData.id;
if (this.battle.sidesSwitched !== !!(this.side === 'p2')) {
this.battle.reset(true);
this.battle.switchSides();
if (midBattle) {
this.battle.fastForwardTo(-1);
} else {
this.battle.play();
}
this.battle.switchSides(!midBattle);
this.$chat = this.$chatFrame.find('.inner');
}
},
@@ -716,17 +710,7 @@
this.send('/savereplay');
},
switchSides: function () {
if (this.battle.done) {
this.battle.reset(true);
this.battle.switchSides();
this.battle.fastForwardTo(-1);
} else {
var turn = this.battle.turn;
this.battle.reset(true);
this.battle.switchSides();
if (turn) this.battle.fastForwardTo(turn);
this.battle.play(true);
}
this.battle.switchSides();
},
instantReplay: function () {
this.hideTooltip();