Mercurial > libervia-web
comparison browser_side/card_game.py @ 439:d52f529a6d42
browser side: use of new log system (first draft):
- configuration is hardcoded in libervia.py, it will change in the (hopefuly) near future
- log level is DEBUG for the moment, will be changed to INFO when configuration will not be hardcoded anymore
- the basic log backend is used, in the future, a console.debug/info/etc should be used instead. A log widget which HTML colors is also an option
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 08 May 2014 17:21:34 +0200 |
parents | b96b8b666d17 |
children |
comparison
equal
deleted
inserted
replaced
438:582c435dab6b | 439:d52f529a6d42 |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 import pyjd # this is dummy in pyjs | 20 import pyjd # this is dummy in pyjs |
21 from sat.core.log import getLogger | |
22 log = getLogger(__name__) | |
21 from pyjamas.ui.AbsolutePanel import AbsolutePanel | 23 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
22 from pyjamas.ui.DockPanel import DockPanel | 24 from pyjamas.ui.DockPanel import DockPanel |
23 from pyjamas.ui.SimplePanel import SimplePanel | 25 from pyjamas.ui.SimplePanel import SimplePanel |
24 from pyjamas.ui.Image import Image | 26 from pyjamas.ui.Image import Image |
25 from pyjamas.ui.Label import Label | 27 from pyjamas.ui.Label import Label |
170 self.addClickListener(self) | 172 self.addClickListener(self) |
171 | 173 |
172 def loadCards(self): | 174 def loadCards(self): |
173 """Load all the cards in memory""" | 175 """Load all the cards in memory""" |
174 def _getTarotCardsPathsCb(paths): | 176 def _getTarotCardsPathsCb(paths): |
175 print "_getTarotCardsPathsCb" | 177 log.debug("_getTarotCardsPathsCb") |
176 for file_ in paths: | 178 for file_ in paths: |
177 print "path:", file_ | 179 log.debug("path:", file_) |
178 card = CardWidget(self, file_) | 180 card = CardWidget(self, file_) |
179 print "card:", card | 181 log.debug("card:", card) |
180 self.cards[(card.suit, card.value)] = card | 182 self.cards[(card.suit, card.value)] = card |
181 self.deck.append(card) | 183 self.deck.append(card) |
182 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) | 184 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) |
183 self.cards = {} | 185 self.cards = {} |
184 self.deck = [] | 186 self.deck = [] |
275 if phase == "play": | 277 if phase == "play": |
276 self.state = "play" | 278 self.state = "play" |
277 elif phase == "ecart": | 279 elif phase == "ecart": |
278 self.state = "ecart" | 280 self.state = "ecart" |
279 else: | 281 else: |
280 print 'INTERNAL ERROR: unmanaged game phase' | 282 log.error("INTERNAL ERROR: unmanaged game phase") # FIXME: raise an exception here |
281 | 283 |
282 for suit, value in played_cards: | 284 for suit, value in played_cards: |
283 self.hand.append(self.cards[(suit, value)]) | 285 self.hand.append(self.cards[(suit, value)]) |
284 | 286 |
285 self.hand.sort() | 287 self.hand.sort() |
315 def getPlayerLocation(self, nick): | 317 def getPlayerLocation(self, nick): |
316 """return player location (top,bottom,left or right)""" | 318 """return player location (top,bottom,left or right)""" |
317 for location in ['top', 'left', 'bottom', 'right']: | 319 for location in ['top', 'left', 'bottom', 'right']: |
318 if getattr(self, '%s_nick' % location) == nick: | 320 if getattr(self, '%s_nick' % location) == nick: |
319 return location | 321 return location |
320 print ("ERROR: This line should not be reached") | 322 log.error("This line should not be reached") |
321 | 323 |
322 def tarotGameCardsPlayed(self, player, cards): | 324 def tarotGameCardsPlayed(self, player, cards): |
323 """A card has been played by player""" | 325 """A card has been played by player""" |
324 if not len(cards): | 326 if not len(cards): |
325 print ("WARNING: cards should not be empty") | 327 log.warning("cards should not be empty") |
326 return | 328 return |
327 if len(cards) > 1: | 329 if len(cards) > 1: |
328 print ("ERROR: can't manage several cards played") | 330 log.error("can't manage several cards played") |
329 if self.to_show: | 331 if self.to_show: |
330 self.to_show = [] | 332 self.to_show = [] |
331 self.updateToShow() | 333 self.updateToShow() |
332 suit, value = cards[0] | 334 suit, value = cards[0] |
333 player_pos = self.getPlayerLocation(player) | 335 player_pos = self.getPlayerLocation(player) |