diff frontends/src/quick_frontend/quick_app.py @ 1360:8ea8fa13c351 frontends_multi_profiles

frontends (quick_frontend, primitivus): fixes room games: - add quick_frontend.quick_games for registering the signals and registering the UI classes - rename the signals handlers to fit the convention (e.g.: tarotGameScoreHandler) - rename card_game to game_tarot, quick_card_game to quick_game_tarot, CardGame to TarotGame
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:43:48 +0100
parents 56c14cb29e0f
children d3e9848b9574
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Wed Mar 11 12:36:22 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Wed Mar 11 12:43:48 2015 +0100
@@ -26,7 +26,7 @@
 
 from sat_frontends.tools import jid
 from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager
-from sat_frontends.quick_frontend import quick_chat
+from sat_frontends.quick_frontend import quick_chat, quick_games
 from sat_frontends.quick_frontend.constants import Const as C
 
 import sys
@@ -252,25 +252,14 @@
         self.registerSignal("roomUserLeft", iface="plugin")
         self.registerSignal("roomUserChangedNick", iface="plugin")
         self.registerSignal("roomNewSubject", iface="plugin")
-        self.registerSignal("tarotGameStarted", iface="plugin")
-        self.registerSignal("tarotGameNew", iface="plugin")
-        self.registerSignal("tarotGameChooseContrat", iface="plugin")
-        self.registerSignal("tarotGameShowCards", iface="plugin")
-        self.registerSignal("tarotGameYourTurn", iface="plugin")
-        self.registerSignal("tarotGameScore", iface="plugin")
-        self.registerSignal("tarotGameCardsPlayed", iface="plugin")
-        self.registerSignal("tarotGameInvalidCards", iface="plugin")
-        self.registerSignal("quizGameStarted", iface="plugin")
-        self.registerSignal("quizGameNew", iface="plugin")
-        self.registerSignal("quizGameQuestion", iface="plugin")
-        self.registerSignal("quizGamePlayerBuzzed", iface="plugin")
-        self.registerSignal("quizGamePlayerSays", iface="plugin")
-        self.registerSignal("quizGameAnswerResult", iface="plugin")
-        self.registerSignal("quizGameTimerExpired", iface="plugin")
-        self.registerSignal("quizGameTimerRestarted", iface="plugin")
         self.registerSignal("chatStateReceived", iface="plugin")
         self.registerSignal("personalEvent", iface="plugin")
 
+        # FIXME: do it dynamically
+        quick_games.Tarot.registerSignals(self)
+        quick_games.Quiz.registerSignals(self)
+        quick_games.Radiocol.registerSignals(self)
+
         self.current_action_ids = set() # FIXME: to be removed
         self.current_action_ids_cb = {} # FIXME: to be removed
         self.media_dir = self.bridge.getConfig('', 'media_dir')
@@ -576,107 +565,6 @@
         chat_widget.setSubject(subject)
         log.debug("new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject})
 
-    def tarotGameStartedHandler(self, room_jid_s, referee, players, profile):
-        log.debug(_("Tarot Game Started \o/"))
-        room_jid = jid.JID(room_jid_s)
-        chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile)
-        chat_widget.startGame("Tarot", referee, players)
-        log.debug("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s" % {'referee': referee, 'room_jid': room_jid, 'players': [str(player) for player in players]})
-
-    def tarotGameNewHandler(self, room_jid_s, hand, profile):
-        log.debug(_("New Tarot Game"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").newGame(hand)
-
-    def tarotGameChooseContratHandler(self, room_jid_s, xml_data, profile):
-        """Called when the player has to select his contrat"""
-        log.debug(_("Tarot: need to select a contrat"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").chooseContrat(xml_data)
-
-    def tarotGameShowCardsHandler(self, room_jid_s, game_stage, cards, data, profile):
-        log.debug(_("Show cards"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").showCards(game_stage, cards, data)
-
-    def tarotGameYourTurnHandler(self, room_jid_s, profile):
-        log.debug(_("My turn to play"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").myTurn()
-
-    def tarotGameScoreHandler(self, room_jid_s, xml_data, winners, loosers, profile):
-        """Called when the game is finished and the score are updated"""
-        log.debug(_("Tarot: score received"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").showScores(xml_data, winners, loosers)
-
-    def tarotGameCardsPlayedHandler(self, room_jid_s, player, cards, profile):
-        log.debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards})
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").cardsPlayed(player, cards)
-
-    def tarotGameInvalidCardsHandler(self, room_jid_s, phase, played_cards, invalid_cards, profile):
-        log.debug(_("Cards played are not valid: %s") % invalid_cards)
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
-
-    def quizGameStartedHandler(self, room_jid_s, referee, players, profile):
-        log.debug(_("Quiz Game Started \o/"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.startGame("Quiz", referee, players)
-            log.debug(_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee': referee, 'room_jid': room_jid_s, 'players': [str(player) for player in players]})
-
-    def quizGameNewHandler(self, room_jid_s, data, profile):
-        log.debug(_("New Quiz Game"))
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGameNewHandler(data)
-
-    def quizGameQuestionHandler(self, room_jid_s, question_id, question, timer, profile):
-        """Called when a new question is asked"""
-        log.debug(_(u"Quiz: new question: %s") % question)
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGameQuestionHandler(question_id, question, timer)
-
-    def quizGamePlayerBuzzedHandler(self, room_jid_s, player, pause, profile):
-        """Called when a player pushed the buzzer"""
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGamePlayerBuzzedHandler(player, pause)
-
-    def quizGamePlayerSaysHandler(self, room_jid_s, player, text, delay, profile):
-        """Called when a player say something"""
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGamePlayerSaysHandler(player, text, delay)
-
-    def quizGameAnswerResultHandler(self, room_jid_s, player, good_answer, score, profile):
-        """Called when a player say something"""
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGameAnswerResultHandler(player, good_answer, score)
-
-    def quizGameTimerExpiredHandler(self, room_jid_s, profile):
-        """Called when nobody answered the question in time"""
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGameTimerExpiredHandler()
-
-    def quizGameTimerRestartedHandler(self, room_jid_s, time_left, profile):
-        """Called when the question is not answered, and we still have time"""
-        chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile)
-        if chat_widget:
-            chat_widget.getGame("Quiz").quizGameTimerRestartedHandler(time_left)
-
     def chatStateReceivedHandler(self, from_jid_s, state, profile):
         """Called when a new chat state is received.