Mercurial > libervia-backend
comparison src/plugins/plugin_misc_tarot.py @ 536:a31abb97310d
core, plugins: fixed bad namespace in stanza creation
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 01 Nov 2012 22:41:39 +0100 |
parents | 2a072735e459 |
children | da6eaa2af092 |
comparison
equal
deleted
inserted
replaced
535:790be337cc41 | 536:a31abb97310d |
---|---|
86 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]: | 86 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]: |
87 self.deck_ordered.append(TarotCard((suit, value))) | 87 self.deck_ordered.append(TarotCard((suit, value))) |
88 | 88 |
89 def createGameElt(self, to_jid, type="normal"): | 89 def createGameElt(self, to_jid, type="normal"): |
90 type = "normal" if to_jid.resource else "groupchat" | 90 type = "normal" if to_jid.resource else "groupchat" |
91 elt = domish.Element(('jabber:client','message')) | 91 elt = domish.Element((None,'message')) |
92 elt["to"] = to_jid.full() | 92 elt["to"] = to_jid.full() |
93 elt["type"] = type | 93 elt["type"] = type |
94 elt.addElement((NS_CG, CG_TAG)) | 94 elt.addElement((NS_CG, CG_TAG)) |
95 return elt | 95 return elt |
96 | 96 |
97 def __card_list_to_xml(self, cards_list, elt_name): | 97 def __card_list_to_xml(self, cards_list, elt_name): |
98 """Convert a card list to domish element""" | 98 """Convert a card list to domish element""" |
99 cards_list_elt = domish.Element(('',elt_name)) | 99 cards_list_elt = domish.Element((None,elt_name)) |
100 for card in cards_list: | 100 for card in cards_list: |
101 card_elt = domish.Element(('','card')) | 101 card_elt = domish.Element((None,'card')) |
102 card_elt['suit'] = card.suit | 102 card_elt['suit'] = card.suit |
103 card_elt['value'] = card.value | 103 card_elt['value'] = card.value |
104 cards_list_elt.addChild(card_elt) | 104 cards_list_elt.addChild(card_elt) |
105 return cards_list_elt | 105 return cards_list_elt |
106 | 106 |
111 cards_list.append((card['suit'], card['value'])) | 111 cards_list.append((card['suit'], card['value'])) |
112 return cards_list | 112 return cards_list |
113 | 113 |
114 def __create_started_elt(self, players): | 114 def __create_started_elt(self, players): |
115 """Create a game_started domish element""" | 115 """Create a game_started domish element""" |
116 started_elt = domish.Element(('','started')) | 116 started_elt = domish.Element((None,'started')) |
117 idx = 0 | 117 idx = 0 |
118 for player in players: | 118 for player in players: |
119 player_elt = domish.Element(('','player')) | 119 player_elt = domish.Element((None,'player')) |
120 player_elt.addContent(player) | 120 player_elt.addContent(player) |
121 player_elt['index'] = str(idx) | 121 player_elt['index'] = str(idx) |
122 idx+=1 | 122 idx+=1 |
123 started_elt.addChild(player_elt) | 123 started_elt.addChild(player_elt) |
124 return started_elt | 124 return started_elt |
125 | 125 |
126 def __ask_contrat(self): | 126 def __ask_contrat(self): |
127 """Create a element for asking contrat""" | 127 """Create a element for asking contrat""" |
128 contrat_elt = domish.Element(('','contrat')) | 128 contrat_elt = domish.Element((None,'contrat')) |
129 form = data_form.Form('form', title=_('contrat selection')) | 129 form = data_form.Form('form', title=_('contrat selection')) |
130 field = data_form.Field('list-single', 'contrat', options=map(data_form.Option, self.contrats), required=True) | 130 field = data_form.Field('list-single', 'contrat', options=map(data_form.Option, self.contrats), required=True) |
131 form.addField(field) | 131 form.addField(field) |
132 contrat_elt.addChild(form.toElement()) | 132 contrat_elt.addChild(form.toElement()) |
133 return contrat_elt | 133 return contrat_elt |
136 """Create an element to give scores | 136 """Create an element to give scores |
137 @param scores: unicode (can contain line feed) | 137 @param scores: unicode (can contain line feed) |
138 @param winners: list of unicode nicks of winners | 138 @param winners: list of unicode nicks of winners |
139 @param loosers: list of unicode nicks of loosers""" | 139 @param loosers: list of unicode nicks of loosers""" |
140 | 140 |
141 score_elt = domish.Element(('','score')) | 141 score_elt = domish.Element((None,'score')) |
142 form = data_form.Form('form', title=_('scores')) | 142 form = data_form.Form('form', title=_('scores')) |
143 for line in scores.split('\n'): | 143 for line in scores.split('\n'): |
144 field = data_form.Field('fixed', value = line) | 144 field = data_form.Field('fixed', value = line) |
145 form.addField(field) | 145 form.addField(field) |
146 score_elt.addChild(form.toElement()) | 146 score_elt.addChild(form.toElement()) |
147 for winner in winners: | 147 for winner in winners: |
148 winner_elt = domish.Element(('','winner')) | 148 winner_elt = domish.Element((None,'winner')) |
149 winner_elt.addContent(winner) | 149 winner_elt.addContent(winner) |
150 score_elt.addChild(winner_elt) | 150 score_elt.addChild(winner_elt) |
151 for looser in loosers: | 151 for looser in loosers: |
152 looser_elt = domish.Element(('','looser')) | 152 looser_elt = domish.Element((None,'looser')) |
153 looser_elt.addContent(looser) | 153 looser_elt.addContent(looser) |
154 score_elt.addChild(looser_elt) | 154 score_elt.addChild(looser_elt) |
155 return score_elt | 155 return score_elt |
156 | 156 |
157 def __invalid_cards_elt(self, played_cards, invalid_cards, game_phase): | 157 def __invalid_cards_elt(self, played_cards, invalid_cards, game_phase): |
158 """Create a element for invalid_cards error | 158 """Create a element for invalid_cards error |
159 @param list_cards: list of Card | 159 @param list_cards: list of Card |
160 @param game_phase: phase of the game ['ecart', 'play']""" | 160 @param game_phase: phase of the game ['ecart', 'play']""" |
161 error_elt = domish.Element(('','error')) | 161 error_elt = domish.Element((None,'error')) |
162 played_elt = self.__card_list_to_xml(played_cards, 'played') | 162 played_elt = self.__card_list_to_xml(played_cards, 'played') |
163 invalid_elt = self.__card_list_to_xml(invalid_cards, 'invalid') | 163 invalid_elt = self.__card_list_to_xml(invalid_cards, 'invalid') |
164 error_elt['type'] = 'invalid_cards' | 164 error_elt['type'] = 'invalid_cards' |
165 error_elt['phase'] = game_phase | 165 error_elt['phase'] = game_phase |
166 error_elt.addChild(played_elt) | 166 error_elt.addChild(played_elt) |