Skip to content

Commit

Permalink
Use current player's theme when rendering cards (#13 task)
Browse files Browse the repository at this point in the history
The themes apparently look pretty crap, at least in Textual,
but fixing that is a separate issue.
  • Loading branch information
dgw committed Jul 15, 2015
1 parent bdf03b5 commit b4e4d12
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions unobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def draw(self, bot, trigger):
self.drawn = YES
c = self.get_card()
self.players[self.playerOrder[self.currentPlayer]].append(c)
bot.notice(STRINGS['DRAWN_CARD'] % self.render_cards([c]), trigger.nick)
bot.notice(STRINGS['DRAWN_CARD']
% self.render_cards([c], UnoBot.get_card_theme(bot, trigger.nick)), trigger.nick)

def pass_(self, bot, trigger):
if not self.deck:
Expand All @@ -234,13 +235,14 @@ def pass_(self, bot, trigger):
def show_on_turn(self, bot):
with lock:
pl = self.playerOrder[self.currentPlayer]
bot.say(STRINGS['TOP_CARD'] % (pl, self.render_cards([self.topCard])))
bot.say(STRINGS['TOP_CARD'] % (pl, self.render_cards([self.topCard], UnoBot.get_card_theme(bot, pl))))
self.send_cards(bot, self.playerOrder[self.currentPlayer])
self.send_next(bot)

def send_cards(self, bot, who):
cards = self.players[who]
bot.notice(STRINGS['YOUR_CARDS'] % (len(cards), self.render_cards(cards)), who)
bot.notice(STRINGS['YOUR_CARDS']
% (len(cards), self.render_cards(cards, UnoBot.get_card_theme(bot, who))), who)

def send_next(self, bot):
with lock:
Expand Down Expand Up @@ -328,16 +330,16 @@ def card_played(self, bot, card):
if 'D2' in card:
bot.say(STRINGS['D2'] % self.playerOrder[self.currentPlayer])
z = [self.get_card(), self.get_card()]
bot.notice(STRINGS['CARDS'] % self.render_cards(z),
self.playerOrder[self.currentPlayer])
bot.notice(STRINGS['CARDS'] % self.render_cards(z, UnoBot.get_card_theme(bot, self.playerOrder[
self.currentPlayer])), self.playerOrder[self.currentPlayer])
self.players[self.playerOrder[self.currentPlayer]].extend(z)
self.inc_player()
elif 'WD4' in card:
bot.say(STRINGS['WD4'] % self.playerOrder[self.currentPlayer])
z = [self.get_card(), self.get_card(), self.get_card(),
self.get_card()]
bot.notice(STRINGS['CARDS'] % self.render_cards(z),
self.playerOrder[self.currentPlayer])
bot.notice(STRINGS['CARDS'] % self.render_cards(z, UnoBot.get_card_theme(bot, self.playerOrder[
self.currentPlayer])), self.playerOrder[self.currentPlayer])
self.players[self.playerOrder[self.currentPlayer]].extend(z)
self.inc_player()
elif 'S' in card:
Expand Down Expand Up @@ -630,9 +632,8 @@ def convert_score_file(self, bot):
def set_card_theme(bot, trigger):
theme = trigger.group(3) or None
if not theme:
theme = bot.db.get_nick_value(trigger.nick, 'uno_theme') or THEME_NONE
theme = THEME_NAMES[theme]
bot.say(STRINGS['THEME_CURRENT'] % theme)
theme = UnoBot.get_card_theme(bot, trigger.nick)
bot.say(STRINGS['THEME_CURRENT'] % THEME_NAMES[theme])
return
theme = theme.lower()
if theme not in THEMES:
Expand All @@ -641,6 +642,10 @@ def set_card_theme(bot, trigger):
bot.db.set_nick_value(trigger.nick, 'uno_theme', THEMES[theme])
bot.say(STRINGS['THEME_SET'] % (trigger.nick, theme))

@staticmethod
def get_card_theme(bot, nick):
return bot.db.get_nick_value(tools.Identifier(nick), 'uno_theme') or THEME_NONE


unobot = UnoBot()

Expand Down

0 comments on commit b4e4d12

Please sign in to comment.