comparison src/plugins/plugin_misc_tarot.py @ 1409:3265a2639182

massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author souliane <souliane@mailoo.org>
date Thu, 16 Apr 2015 14:57:57 +0200
parents 069ad98b360d
children d17772b0fe22
comparison
equal deleted inserted replaced
1408:8a7145138330 1409:3265a2639182
196 for card in played: 196 for card in played:
197 if card.points == 0.5: 197 if card.points == 0.5:
198 pl_waiting = players_data[player]['wait_for_low'] 198 pl_waiting = players_data[player]['wait_for_low']
199 played.remove(card) 199 played.remove(card)
200 players_data[pl_waiting]['levees'].append(card) 200 players_data[pl_waiting]['levees'].append(card)
201 log.debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": player, "card_waited": card, "player_waiting": pl_waiting}) 201 log.debug(_(u'Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": player, "card_waited": card, "player_waiting": pl_waiting})
202 return 202 return
203 return 203 return
204 204
205 if excuse not in played: 205 if excuse not in played:
206 # the Excuse is not on the table, nothing to do 206 # the Excuse is not on the table, nothing to do
227 for card_idx in range(len(owner_levees) - 1, -1, -1): 227 for card_idx in range(len(owner_levees) - 1, -1, -1):
228 if owner_levees[card_idx].points == 0.5: 228 if owner_levees[card_idx].points == 0.5:
229 low_card = owner_levees[card_idx] 229 low_card = owner_levees[card_idx]
230 del owner_levees[card_idx] 230 del owner_levees[card_idx]
231 players_data[winner]['levees'].append(low_card) 231 players_data[winner]['levees'].append(low_card)
232 log.debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": excuse_player, "card_waited": low_card, "player_waiting": winner}) 232 log.debug(_(u'Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": excuse_player, "card_waited": low_card, "player_waiting": winner})
233 break 233 break
234 if not low_card: # The player has no low card yet 234 if not low_card: # The player has no low card yet
235 # TODO: manage case when player never win a trick with low card 235 # TODO: manage case when player never win a trick with low card
236 players_data[excuse_player]['wait_for_low'] = winner 236 players_data[excuse_player]['wait_for_low'] = winner
237 log.debug(_("%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner': excuse_player, 'winner': winner}) 237 log.debug(_(u"%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner': excuse_player, 'winner': winner})
238 238
239 def __draw_game(self, game_data): 239 def __draw_game(self, game_data):
240 """The game is draw, no score change 240 """The game is draw, no score change
241 @param game_data: data of the game 241 @param game_data: data of the game
242 @return: tuple with (string victory message, list of winners, list of loosers)""" 242 @return: tuple with (string victory message, list of winners, list of loosers)"""
243 players_data = game_data['players_data'] 243 players_data = game_data['players_data']
244 scores_str = _('Draw game') 244 scores_str = _('Draw game')
245 scores_str += '\n' 245 scores_str += '\n'
246 for player in game_data['players']: 246 for player in game_data['players']:
247 scores_str += _("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': 0, 'total_score': players_data[player]['score']} 247 scores_str += _(u"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': 0, 'total_score': players_data[player]['score']}
248 log.debug(scores_str) 248 log.debug(scores_str)
249 249
250 return (scores_str, [], []) 250 return (scores_str, [], [])
251 251
252 def __calculate_scores(self, game_data): 252 def __calculate_scores(self, game_data):
311 if player_score[player] > 0: 311 if player_score[player] > 0:
312 winners.append(player) 312 winners.append(player)
313 else: 313 else:
314 loosers.append(player) 314 loosers.append(player)
315 315
316 scores_str = _('The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): (s)he %(victory)s') % {'attaquant': game_data['attaquant'], 'points': score, 'point_limit': point_limit, 'nb_bouts': nb_bouts, 'plural': 's' if nb_bouts > 1 else '', 'separator': ': ' if nb_bouts != 0 else '', 'bouts': ','.join(map(str, bouts)), 'victory': 'wins' if victory else 'looses'} 316 scores_str = _(u'The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): (s)he %(victory)s') % {'attaquant': game_data['attaquant'], 'points': score, 'point_limit': point_limit, 'nb_bouts': nb_bouts, 'plural': 's' if nb_bouts > 1 else '', 'separator': ': ' if nb_bouts != 0 else '', 'bouts': ','.join(map(str, bouts)), 'victory': 'wins' if victory else 'looses'}
317 scores_str += '\n' 317 scores_str += '\n'
318 for player in game_data['players']: 318 for player in game_data['players']:
319 scores_str += _("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': player_score[player], 'total_score': players_data[player]['score']} 319 scores_str += _(u"\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': player_score[player], 'total_score': players_data[player]['score']}
320 log.debug(scores_str) 320 log.debug(scores_str)
321 321
322 return (scores_str, winners, loosers) 322 return (scores_str, winners, loosers)
323 323
324 def __invalid_cards(self, game_data, cards): 324 def __invalid_cards(self, game_data, cards):
400 room_jid = session_data['room_jid'] 400 room_jid = session_data['room_jid']
401 referee_jid = self.games[room_jid]['referee'] 401 referee_jid = self.games[room_jid]['referee']
402 player = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile) 402 player = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile)
403 data = xml_tools.XMLUIResult2DataFormResult(raw_data) 403 data = xml_tools.XMLUIResult2DataFormResult(raw_data)
404 contrat = data['contrat'] 404 contrat = data['contrat']
405 log.debug(_('contrat [%(contrat)s] choosed by %(profile)s') % {'contrat': contrat, 'profile': profile}) 405 log.debug(_(u'contrat [%(contrat)s] choosed by %(profile)s') % {'contrat': contrat, 'profile': profile})
406 d = self.send(referee_jid, ('', 'contrat_choosed'), {'player': player}, content=contrat, profile=profile) 406 d = self.send(referee_jid, ('', 'contrat_choosed'), {'player': player}, content=contrat, profile=profile)
407 d.addCallback(lambda ignore: {}) 407 d.addCallback(lambda ignore: {})
408 del self._sessions[raw_data["session_id"]] 408 del self._sessions[raw_data["session_id"]]
409 return d 409 return d
410 410
433 @cards: cards played (list of tuples) 433 @cards: cards played (list of tuples)
434 @profile_key: profile 434 @profile_key: profile
435 """ 435 """
436 profile = self.host.memory.getProfileName(profile_key) 436 profile = self.host.memory.getProfileName(profile_key)
437 if not profile: 437 if not profile:
438 log.error(_("profile %s is unknown") % profile_key) 438 log.error(_(u"profile %s is unknown") % profile_key)
439 return 439 return
440 log.debug(_('Cards played by %(profile)s: [%(cards)s]') % {'profile': profile, 'cards': cards}) 440 log.debug(_(u'Cards played by %(profile)s: [%(cards)s]') % {'profile': profile, 'cards': cards})
441 elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), 'cards_played') 441 elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), 'cards_played')
442 self.send(jid.JID(referee), elem, {'player': player}, profile=profile) 442 self.send(jid.JID(referee), elem, {'player': player}, profile=profile)
443 443
444 def newRound(self, room_jid, profile): 444 def newRound(self, room_jid, profile):
445 game_data = self.games[room_jid] 445 game_data = self.games[room_jid]
501 elif elt.name == 'player_ready': # ready to play 501 elif elt.name == 'player_ready': # ready to play
502 player = elt['player'] 502 player = elt['player']
503 status = self.games[room_jid]['status'] 503 status = self.games[room_jid]['status']
504 nb_players = len(self.games[room_jid]['players']) 504 nb_players = len(self.games[room_jid]['players'])
505 status[player] = 'ready' 505 status[player] = 'ready'
506 log.debug(_('Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status}) 506 log.debug(_(u'Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status})
507 if status.values().count('ready') == nb_players: # everybody is ready, we can start the game 507 if status.values().count('ready') == nb_players: # everybody is ready, we can start the game
508 self.newRound(room_jid, profile) 508 self.newRound(room_jid, profile)
509 509
510 elif elt.name == 'hand': # a new hand has been received 510 elif elt.name == 'hand': # a new hand has been received
511 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile) 511 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile)
543 self.send(to_jid, self.__give_scores(*self.__draw_game(game_data)), profile=profile) 543 self.send(to_jid, self.__give_scores(*self.__draw_game(game_data)), profile=profile)
544 game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) # we change the dealer 544 game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) # we change the dealer
545 for player in game_data['players']: 545 for player in game_data['players']:
546 game_data['status'][player] = "init" 546 game_data['status'][player] = "init"
547 return 547 return
548 log.debug(_("%(player)s win the bid with %(contrat)s") % {'player': best_contrat[0], 'contrat': best_contrat[1]}) 548 log.debug(_(u"%(player)s win the bid with %(contrat)s") % {'player': best_contrat[0], 'contrat': best_contrat[1]})
549 game_data['contrat'] = best_contrat[1] 549 game_data['contrat'] = best_contrat[1]
550 550
551 if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre": 551 if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre":
552 self.__start_play(room_jid, game_data, profile) 552 self.__start_play(room_jid, game_data, profile)
553 game_data['attaquant'] = best_contrat[0] 553 game_data['attaquant'] = best_contrat[0]
615 # Did everybody played ? 615 # Did everybody played ?
616 played = [players_data[player]['played'] for player in game_data['players']] 616 played = [players_data[player]['played'] for player in game_data['players']]
617 if all(played): 617 if all(played):
618 # everybody has played 618 # everybody has played
619 winner = self.__winner(game_data) 619 winner = self.__winner(game_data)
620 log.debug(_('The winner of this trick is %s') % winner) 620 log.debug(_(u'The winner of this trick is %s') % winner)
621 # the winner win the trick 621 # the winner win the trick
622 self.__excuse_hack(game_data, played, winner) 622 self.__excuse_hack(game_data, played, winner)
623 players_data[elt['player']]['levees'].extend(played) 623 players_data[elt['player']]['levees'].extend(played)
624 # nothing left on the table 624 # nothing left on the table
625 for player in game_data['players']: 625 for player in game_data['players']:
661 if elt['type'] == 'invalid_cards': 661 if elt['type'] == 'invalid_cards':
662 played_cards = self.__xml_to_list(elt.elements(name='played', uri=NS_CG).next()) 662 played_cards = self.__xml_to_list(elt.elements(name='played', uri=NS_CG).next())
663 invalid_cards = self.__xml_to_list(elt.elements(name='invalid', uri=NS_CG).next()) 663 invalid_cards = self.__xml_to_list(elt.elements(name='invalid', uri=NS_CG).next())
664 self.host.bridge.tarotGameInvalidCards(room_jid.userhost(), elt['phase'], played_cards, invalid_cards, profile) 664 self.host.bridge.tarotGameInvalidCards(room_jid.userhost(), elt['phase'], played_cards, invalid_cards, profile)
665 else: 665 else:
666 log.error(_('Unmanaged error type: %s') % elt['type']) 666 log.error(_(u'Unmanaged error type: %s') % elt['type'])
667 else: 667 else:
668 log.error(_('Unmanaged card game element: %s') % elt.name) 668 log.error(_(u'Unmanaged card game element: %s') % elt.name)
669 669
670 def getSyncDataForPlayer(self, room_jid, nick): 670 def getSyncDataForPlayer(self, room_jid, nick):
671 return [] 671 return []