Allow spectators to switch sides

This commit is contained in:
urkerab 2015-09-23 13:35:44 +01:00
parent 294efc0f4b
commit 660d4e1619
2 changed files with 22 additions and 3 deletions

View File

@ -2647,6 +2647,7 @@ var Battle = (function () {
if (this.turnCallback) this.turnCallback(this);
if (this.fastForward > -1 && turnnum >= this.fastForward) {
this.fastForwardOff();
if (this.endCallback) this.endCallback(this);
}
return;
}

View File

@ -189,7 +189,12 @@
} else if (this.battle.playbackState === 2 || this.battle.playbackState === 3) {
// battle is playing or paused
this.$controls.html('<p><button name="skipTurn">Skip turn <i class="fa fa-step-forward"></i></button><button name="goToEnd">Go to last turn <i class="fa fa-fast-forward"></i></button></p>');
if (this.side) {
// is a player
this.$controls.html('<p><button name="skipTurn">Skip turn <i class="fa fa-step-forward"></i></button><button name="goToEnd">Go to last turn <i class="fa fa-fast-forward"></i></button></p>');
} else {
this.$controls.html('<p><button name="switchSides">Switch sides <i class="fa fa-random"></i></button> <button name="skipTurn">Skip turn <i class="fa fa-step-forward"></i></button> <button name="goToEnd">Go to last turn <i class="fa fa-fast-forward"></i></button></p>');
}
return;
}
@ -225,7 +230,7 @@
// was a player
this.$controls.html('<div class="controls"><p><em><button name="instantReplay"><i class="fa fa-undo"></i> Instant Replay</button> <button name="saveReplay"><i class="fa fa-upload"></i> Share replay</button></p><p><button name="closeAndMainMenu"><strong>Main menu</strong><br /><small>(closes this battle)</small></button> <button name="closeAndRematch"><strong>Rematch</strong><br /><small>(closes this battle)</small></button></p></div>');
} else {
this.$controls.html('<div class="controls"><p><em><button name="instantReplay"><i class="fa fa-undo"></i> Instant Replay</button> <button name="saveReplay"><i class="fa fa-upload"></i> Share replay</button></p></div>');
this.$controls.html('<div class="controls"><p><em><button name="switchSides">Switch sides <i class="fa fa-random"></i></button> <button name="instantReplay"><i class="fa fa-undo"></i> Instant Replay</button> <button name="saveReplay"><i class="fa fa-upload"></i> Share replay</button></p></div>');
}
} else if (!this.battle.mySide.initialized || !this.battle.yourSide.initialized) {
@ -264,7 +269,7 @@
} else {
// full battle
this.$controls.html('<p><em>Waiting for players...</em></p>');
this.$controls.html('<p><em><button name="switchSides">Switch sides <i class="fa fa-random"></i></button> Waiting for players...</em></p>');
}
@ -704,6 +709,19 @@
saveReplay: function () {
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();
this.battle.switchSides();
if (turn) this.battle.fastForwardTo(turn);
this.battle.play();
}
},
instantReplay: function () {
this.hideTooltip();
this.request = null;