diff --git a/analyzer/models.py b/analyzer/models.py index edcff37..91dda5c 100755 --- a/analyzer/models.py +++ b/analyzer/models.py @@ -1,3 +1,4 @@ +import re from django.db import models from mtgweb.lib.mtg import mtg @@ -29,16 +30,25 @@ class Deck(models.Model): def __unicode__(self): return self.name def colors(self): - mana = {} - symbols = 0 + symbols = {} + for symbol in mtg.Mana.types.keys(): + symbols[symbol] = 0 + total = 0 for card in self.cards.all(): + # Get symbols from card cost cost = mtg.ManaCost(card.cost) for color, count in cost.mana.mana.iteritems(): - if not color in mana.keys(): - mana[color] = 0 - mana[color] += count - symbols += count - return mana + symbols[color] += count + total += count + + # Get symbols from abilities + pattern = '{%s}' % mtg.ManaCost.symbolPattern + costs = [mtg.ManaCost(cost) for cost in re.findall(pattern, str(card.text))] + for cost in costs: + for color, count in cost.mana.mana.iteritems(): + symbols[color] += count + total += count + return (symbols, total) class Included(models.Model): card = models.ForeignKey(Card) deck = models.ForeignKey(Deck) diff --git a/cards/views.py b/cards/views.py index fc55933..16508d3 100755 --- a/cards/views.py +++ b/cards/views.py @@ -7,8 +7,7 @@ from mtgweb.lib.mtg.mtg import Mana, ManaCost import mtgweb.lib.mtg.database as database def prettify_mana(text): - manapattern = r'X?\d*(\((\d+|[{0}])/(\d+|[{0}])\))*[{0}]*'.format(''.join(Mana.types.keys())) - pattern = r'{%s}' % manapattern + pattern = r'{%s}' % ManaCost.symbolPattern while True: match = re.search(pattern, text) if not match: diff --git a/lib/mtg b/lib/mtg index 352f592..d5206fc 160000 --- a/lib/mtg +++ b/lib/mtg @@ -1 +1 @@ -Subproject commit 352f59288d0f6937824436dccd02e55fb234df66 +Subproject commit d5206fc6df410836b0b24d1e8d9eae34e4a1ea65 diff --git a/media/mtg.css b/media/mtg.css index 62404e5..2b6d3aa 100644 --- a/media/mtg.css +++ b/media/mtg.css @@ -32,7 +32,7 @@ header { margin-left: 160px; } /* Cards and mana symbols */ -.mana { +.mana.symbol { height: 1em; width: 1em; border-radius: 0.5em; @@ -102,3 +102,15 @@ header { padding: 3px; text-shadow: 2px 2px 2px #999; } + +.manabar { + display: inline-block; + width: 5em; + height: 1em; + border: 1px solid #999; +} +.manabar .mana { + height: 1em; + display: block; + float: left; +} diff --git a/templates/cards/manacost.html b/templates/cards/manacost.html index 69ad3a1..9978d91 100644 --- a/templates/cards/manacost.html +++ b/templates/cards/manacost.html @@ -1,10 +1,17 @@ {% load get_range %} +{% if cost.x %}X{% endif %} +{% if cost.y %}Y{% endif %} +{% if cost.z %}Z{% endif %} {% if cost.any > 0 or cost.converted == 0 %} - {{ cost.any }} + {{ cost.any }} {% endif %} +{% for i in cost.snow|get_range %} + {# use the unicode snowflake symbol #} + +{% endfor %} {% for type, mana in cost.mana.mana.items %} {% for i in mana|get_range %} - + {% endfor %} {% endfor %} diff --git a/templates/decks/index.html b/templates/decks/index.html index fe0e0ec..d75431d 100755 --- a/templates/decks/index.html +++ b/templates/decks/index.html @@ -6,12 +6,14 @@