From 98559886b1c293e55b75122c76792ee8f7cb530e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 9 Jun 2015 01:30:14 +0100 Subject: ui: handle the number of played cards properly the number is stored in the cao object and can be retrieved by the mobile / desktop part. Signed-off-by: Olivier Gayot --- cao-common.js | 15 +++++++++++++++ cao-mobile.js | 6 ++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cao-common.js b/cao-common.js index 1b1b309..050490c 100644 --- a/cao-common.js +++ b/cao-common.js @@ -18,6 +18,7 @@ var CAO = function() { this.on_card_played = function() { /* to override */ }; this.on_cards_collected = function() { /* to override */ }; this.on_updated_score = function(new_score) { /* to override */ }; + this.on_change_nbr_played_cards = function(nbr) { /* to override */ }; var request_queue = []; @@ -26,6 +27,8 @@ var CAO = function() { var self = this; var ws; + var nbr_played_cards = 0; + var played_cards = []; var white_cards = {}; var black_card; @@ -39,6 +42,18 @@ var CAO = function() { return judge; }; + this.reset_nbr_played_cards = function() { + nbr_played_cards = 0; + + self.on_change_nbr_played_cards(nbr_played_cards); + }; + + this.incr_nbr_played_cards = function() { + ++nbr_played_cards; + + self.on_change_nbr_played_cards(nbr_played_cards); + }; + /* map_handle_response_ok {{{ */ map_handle_response_ok['join_game'] = function(result) { diff --git a/cao-mobile.js b/cao-mobile.js index 58c5354..8d39169 100644 --- a/cao-mobile.js +++ b/cao-mobile.js @@ -50,10 +50,6 @@ $(document).ready(function() { } }; - cao.on_card_played = function(card_number) { - $played_card_number.text(($played_card_number.text() + 1).toString()); - }; - cao.on_show_white_card = function(idx, desc) { var identifier = 'white-card-' + idx; var content = ''; @@ -111,6 +107,8 @@ $(document).ready(function() { $score_value.text(score); }; + cao.on_change_nbr_played_cards = function(nbr) { + $played_card_number.text(nbr); }; cao.run(); -- cgit v1.2.3