mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-09-30 23:01:05 -05:00
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:
21
js/battle.js
21
js/battle.js
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user