Add /hand command to resync hand

This commit is contained in:
uecasm 2013-11-15 00:14:22 +13:00
parent 7e7be6c54e
commit 5da2e97f53
2 changed files with 30 additions and 12 deletions

View File

@ -163,6 +163,17 @@ function chatsubmit_click(game_id, parent_element) {
// this could also be an IP address
ajax = cah.Ajax.build(cah.$.AjaxOperation.BAN).withNickname(text.split(' ')[0]);
break;
case 'hand':
if (game_id !== null) {
var game = cah.currentGames[game_id];
if (game) {
game.removeAllCards();
}
ajax = cah.Ajax.build(cah.$.AjaxOperation.GET_CARDS).withGameId(game_id);
} else {
cah.log.error("This command only works in a game.");
}
break;
case 'names':
ajax = cah.Ajax.build(cah.$.AjaxOperation.NAMES);
break;

View File

@ -462,6 +462,24 @@ cah.Game.prototype.removeCardFromHand = function(card) {
this.resizeHandCards_();
};
/**
* Remove all cards from the screen.
*/
cah.Game.prototype.removeAllCards = function() {
var handCount = this.hand_.length;
for ( var i = 0; i < handCount; i++) {
this.removeCardFromHand(this.hand_[0]);
}
this.handSelectedCard_ = null;
$(".confirm_card", this.element_).attr("disabled", "disabled");
$(".game_black_card", this.element_).empty();
for ( var index in this.roundCards_) {
$(this.roundCards_[index]).off(".round");
}
this.roundCards_ = {};
$(".game_white_cards", this.element_).empty();
};
/**
* Set the round white cards.
*
@ -1160,19 +1178,8 @@ cah.Game.prototype.stateChange = function(data) {
switch (this.state_) {
case cah.$.GameState.LOBBY:
var handCount = this.hand_.length;
for ( var i = 0; i < handCount; i++) {
this.removeCardFromHand(this.hand_[0]);
}
this.handSelectedCard_ = null;
this.removeAllCards();
this.judge_ = null;
$(".confirm_card", this.element_).attr("disabled", "disabled");
$(".game_black_card", this.element_).empty();
for ( var index in this.roundCards_) {
$(this.roundCards_[index]).off(".round");
}
this.roundCards_ = {};
$(".game_white_cards", this.element_).empty();
this.showOptions_();