Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1359:83127a4c89ce | 1360:8ea8fa13c351 |
---|---|
24 from sat.core import exceptions | 24 from sat.core import exceptions |
25 from sat.tools.misc import TriggerManager | 25 from sat.tools.misc import TriggerManager |
26 | 26 |
27 from sat_frontends.tools import jid | 27 from sat_frontends.tools import jid |
28 from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager | 28 from sat_frontends.quick_frontend.quick_widgets import QuickWidgetsManager |
29 from sat_frontends.quick_frontend import quick_chat | 29 from sat_frontends.quick_frontend import quick_chat, quick_games |
30 from sat_frontends.quick_frontend.constants import Const as C | 30 from sat_frontends.quick_frontend.constants import Const as C |
31 | 31 |
32 import sys | 32 import sys |
33 from collections import OrderedDict | 33 from collections import OrderedDict |
34 | 34 |
250 self.registerSignal("roomLeft", iface="plugin") | 250 self.registerSignal("roomLeft", iface="plugin") |
251 self.registerSignal("roomUserJoined", iface="plugin") | 251 self.registerSignal("roomUserJoined", iface="plugin") |
252 self.registerSignal("roomUserLeft", iface="plugin") | 252 self.registerSignal("roomUserLeft", iface="plugin") |
253 self.registerSignal("roomUserChangedNick", iface="plugin") | 253 self.registerSignal("roomUserChangedNick", iface="plugin") |
254 self.registerSignal("roomNewSubject", iface="plugin") | 254 self.registerSignal("roomNewSubject", iface="plugin") |
255 self.registerSignal("tarotGameStarted", iface="plugin") | |
256 self.registerSignal("tarotGameNew", iface="plugin") | |
257 self.registerSignal("tarotGameChooseContrat", iface="plugin") | |
258 self.registerSignal("tarotGameShowCards", iface="plugin") | |
259 self.registerSignal("tarotGameYourTurn", iface="plugin") | |
260 self.registerSignal("tarotGameScore", iface="plugin") | |
261 self.registerSignal("tarotGameCardsPlayed", iface="plugin") | |
262 self.registerSignal("tarotGameInvalidCards", iface="plugin") | |
263 self.registerSignal("quizGameStarted", iface="plugin") | |
264 self.registerSignal("quizGameNew", iface="plugin") | |
265 self.registerSignal("quizGameQuestion", iface="plugin") | |
266 self.registerSignal("quizGamePlayerBuzzed", iface="plugin") | |
267 self.registerSignal("quizGamePlayerSays", iface="plugin") | |
268 self.registerSignal("quizGameAnswerResult", iface="plugin") | |
269 self.registerSignal("quizGameTimerExpired", iface="plugin") | |
270 self.registerSignal("quizGameTimerRestarted", iface="plugin") | |
271 self.registerSignal("chatStateReceived", iface="plugin") | 255 self.registerSignal("chatStateReceived", iface="plugin") |
272 self.registerSignal("personalEvent", iface="plugin") | 256 self.registerSignal("personalEvent", iface="plugin") |
257 | |
258 # FIXME: do it dynamically | |
259 quick_games.Tarot.registerSignals(self) | |
260 quick_games.Quiz.registerSignals(self) | |
261 quick_games.Radiocol.registerSignals(self) | |
273 | 262 |
274 self.current_action_ids = set() # FIXME: to be removed | 263 self.current_action_ids = set() # FIXME: to be removed |
275 self.current_action_ids_cb = {} # FIXME: to be removed | 264 self.current_action_ids_cb = {} # FIXME: to be removed |
276 self.media_dir = self.bridge.getConfig('', 'media_dir') | 265 self.media_dir = self.bridge.getConfig('', 'media_dir') |
277 | 266 |
574 room_jid = jid.JID(room_jid_s) | 563 room_jid = jid.JID(room_jid_s) |
575 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | 564 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) |
576 chat_widget.setSubject(subject) | 565 chat_widget.setSubject(subject) |
577 log.debug("new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject}) | 566 log.debug("new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject}) |
578 | 567 |
579 def tarotGameStartedHandler(self, room_jid_s, referee, players, profile): | |
580 log.debug(_("Tarot Game Started \o/")) | |
581 room_jid = jid.JID(room_jid_s) | |
582 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) | |
583 chat_widget.startGame("Tarot", referee, players) | |
584 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]}) | |
585 | |
586 def tarotGameNewHandler(self, room_jid_s, hand, profile): | |
587 log.debug(_("New Tarot Game")) | |
588 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
589 if chat_widget: | |
590 chat_widget.getGame("Tarot").newGame(hand) | |
591 | |
592 def tarotGameChooseContratHandler(self, room_jid_s, xml_data, profile): | |
593 """Called when the player has to select his contrat""" | |
594 log.debug(_("Tarot: need to select a contrat")) | |
595 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
596 if chat_widget: | |
597 chat_widget.getGame("Tarot").chooseContrat(xml_data) | |
598 | |
599 def tarotGameShowCardsHandler(self, room_jid_s, game_stage, cards, data, profile): | |
600 log.debug(_("Show cards")) | |
601 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
602 if chat_widget: | |
603 chat_widget.getGame("Tarot").showCards(game_stage, cards, data) | |
604 | |
605 def tarotGameYourTurnHandler(self, room_jid_s, profile): | |
606 log.debug(_("My turn to play")) | |
607 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
608 if chat_widget: | |
609 chat_widget.getGame("Tarot").myTurn() | |
610 | |
611 def tarotGameScoreHandler(self, room_jid_s, xml_data, winners, loosers, profile): | |
612 """Called when the game is finished and the score are updated""" | |
613 log.debug(_("Tarot: score received")) | |
614 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
615 if chat_widget: | |
616 chat_widget.getGame("Tarot").showScores(xml_data, winners, loosers) | |
617 | |
618 def tarotGameCardsPlayedHandler(self, room_jid_s, player, cards, profile): | |
619 log.debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards}) | |
620 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
621 if chat_widget: | |
622 chat_widget.getGame("Tarot").cardsPlayed(player, cards) | |
623 | |
624 def tarotGameInvalidCardsHandler(self, room_jid_s, phase, played_cards, invalid_cards, profile): | |
625 log.debug(_("Cards played are not valid: %s") % invalid_cards) | |
626 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
627 if chat_widget: | |
628 chat_widget.getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) | |
629 | |
630 def quizGameStartedHandler(self, room_jid_s, referee, players, profile): | |
631 log.debug(_("Quiz Game Started \o/")) | |
632 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
633 if chat_widget: | |
634 chat_widget.startGame("Quiz", referee, players) | |
635 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]}) | |
636 | |
637 def quizGameNewHandler(self, room_jid_s, data, profile): | |
638 log.debug(_("New Quiz Game")) | |
639 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
640 if chat_widget: | |
641 chat_widget.getGame("Quiz").quizGameNewHandler(data) | |
642 | |
643 def quizGameQuestionHandler(self, room_jid_s, question_id, question, timer, profile): | |
644 """Called when a new question is asked""" | |
645 log.debug(_(u"Quiz: new question: %s") % question) | |
646 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
647 if chat_widget: | |
648 chat_widget.getGame("Quiz").quizGameQuestionHandler(question_id, question, timer) | |
649 | |
650 def quizGamePlayerBuzzedHandler(self, room_jid_s, player, pause, profile): | |
651 """Called when a player pushed the buzzer""" | |
652 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
653 if chat_widget: | |
654 chat_widget.getGame("Quiz").quizGamePlayerBuzzedHandler(player, pause) | |
655 | |
656 def quizGamePlayerSaysHandler(self, room_jid_s, player, text, delay, profile): | |
657 """Called when a player say something""" | |
658 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
659 if chat_widget: | |
660 chat_widget.getGame("Quiz").quizGamePlayerSaysHandler(player, text, delay) | |
661 | |
662 def quizGameAnswerResultHandler(self, room_jid_s, player, good_answer, score, profile): | |
663 """Called when a player say something""" | |
664 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
665 if chat_widget: | |
666 chat_widget.getGame("Quiz").quizGameAnswerResultHandler(player, good_answer, score) | |
667 | |
668 def quizGameTimerExpiredHandler(self, room_jid_s, profile): | |
669 """Called when nobody answered the question in time""" | |
670 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
671 if chat_widget: | |
672 chat_widget.getGame("Quiz").quizGameTimerExpiredHandler() | |
673 | |
674 def quizGameTimerRestartedHandler(self, room_jid_s, time_left, profile): | |
675 """Called when the question is not answered, and we still have time""" | |
676 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) | |
677 if chat_widget: | |
678 chat_widget.getGame("Quiz").quizGameTimerRestartedHandler(time_left) | |
679 | |
680 def chatStateReceivedHandler(self, from_jid_s, state, profile): | 568 def chatStateReceivedHandler(self, from_jid_s, state, profile): |
681 """Called when a new chat state is received. | 569 """Called when a new chat state is received. |
682 | 570 |
683 @param from_jid_s: JID of the contact who sent his state, or '@ALL@' | 571 @param from_jid_s: JID of the contact who sent his state, or '@ALL@' |
684 @param state: new state (string) | 572 @param state: new state (string) |