Mercurial > libervia-backend
comparison plugins/plugin_misc_tarot.py @ 102:94011f553cd0
misc bugfixes
- wix: added forgotten profile in gateways management
- xml_tools: removed XMLClass to the 2 methods as a direct methods
- plugin_xep_100 (gateways discovery): added error callback
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 22 Jun 2010 13:58:53 +0800 |
parents | 783e9d6980ec |
children | 7201851d9aed |
comparison
equal
deleted
inserted
replaced
101:783e9d6980ec | 102:94011f553cd0 |
---|---|
30 import random | 30 import random |
31 | 31 |
32 from zope.interface import implements | 32 from zope.interface import implements |
33 | 33 |
34 from wokkel import disco, iwokkel, data_form | 34 from wokkel import disco, iwokkel, data_form |
35 from tools.xml_tools import XMLTools | 35 from tools.xml_tools import dataForm2xml |
36 | 36 |
37 try: | 37 try: |
38 from twisted.words.protocols.xmlstream import XMPPHandler | 38 from twisted.words.protocols.xmlstream import XMPPHandler |
39 except ImportError: | 39 except ImportError: |
40 from wokkel.subprotocols import XMPPHandler | 40 from wokkel.subprotocols import XMPPHandler |
53 "main": "Tarot", | 53 "main": "Tarot", |
54 "handler": "yes", | 54 "handler": "yes", |
55 "description": _("""Implementation of Tarot card game""") | 55 "description": _("""Implementation of Tarot card game""") |
56 } | 56 } |
57 | 57 |
58 suits_order = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] #I have swith the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) | 58 suits_order = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] #I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) |
59 values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"] | 59 values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"] |
60 | 60 |
61 class Card(): | 61 class Card(): |
62 """This class is used to represent a car logically""" | 62 """This class is used to represent a car logically""" |
63 #TODO: move this in a library in tools, and share this with frontends (e.g. card_game in wix use the same class) | 63 #TODO: move this in a library in tools, and share this with frontends (e.g. card_game in wix use the same class) |
589 elif elt.name == 'hand': #a new hand has been received | 589 elif elt.name == 'hand': #a new hand has been received |
590 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile) | 590 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile) |
591 | 591 |
592 elif elt.name == 'contrat': #it's time to choose contrat | 592 elif elt.name == 'contrat': #it's time to choose contrat |
593 form = data_form.Form.fromElement(elt.firstChildElement()) | 593 form = data_form.Form.fromElement(elt.firstChildElement()) |
594 xml_data = XMLTools.dataForm2xml(form) | 594 xml_data = dataForm2xml(form) |
595 self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile) | 595 self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile) |
596 | 596 |
597 elif elt.name == 'contrat_choosed': | 597 elif elt.name == 'contrat_choosed': |
598 #TODO: check we receive the contrat from the right person | 598 #TODO: check we receive the contrat from the right person |
599 #TODO: use proper XEP-0004 way for answering form | 599 #TODO: use proper XEP-0004 way for answering form |
731 for winner in elt.elements(name='winner', uri=''): | 731 for winner in elt.elements(name='winner', uri=''): |
732 winners.append(unicode(winner)) | 732 winners.append(unicode(winner)) |
733 for looser in elt.elements(name='looser', uri=''): | 733 for looser in elt.elements(name='looser', uri=''): |
734 loosers.append(unicode(looser)) | 734 loosers.append(unicode(looser)) |
735 form = data_form.Form.fromElement(form_elt) | 735 form = data_form.Form.fromElement(form_elt) |
736 xml_data = XMLTools.dataForm2xml(form) | 736 xml_data = dataForm2xml(form) |
737 self.host.bridge.tarotGameScore(room_jid.userhost(), xml_data, winners, loosers, profile) | 737 self.host.bridge.tarotGameScore(room_jid.userhost(), xml_data, winners, loosers, profile) |
738 elif elt.name == 'error': | 738 elif elt.name == 'error': |
739 if elt['type'] == 'invalid_cards': | 739 if elt['type'] == 'invalid_cards': |
740 played_cards = self.__xml_to_list(elt.elements(name='played',uri='').next()) | 740 played_cards = self.__xml_to_list(elt.elements(name='played',uri='').next()) |
741 invalid_cards = self.__xml_to_list(elt.elements(name='invalid',uri='').next()) | 741 invalid_cards = self.__xml_to_list(elt.elements(name='invalid',uri='').next()) |