Deck color bars, variable mana costs (X/Y/Z), and pretty snow mana icons
This commit is contained in:
parent
774dbda97d
commit
f358941909
6 changed files with 46 additions and 16 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
2
lib/mtg
2
lib/mtg
|
@ -1 +1 @@
|
|||
Subproject commit 352f59288d0f6937824436dccd02e55fb234df66
|
||||
Subproject commit d5206fc6df410836b0b24d1e8d9eae34e4a1ea65
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
{% load get_range %}
|
||||
|
||||
{% if cost.x %}<span class="mana symbol">X</span>{% endif %}
|
||||
{% if cost.y %}<span class="mana symbol">Y</span>{% endif %}
|
||||
{% if cost.z %}<span class="mana symbol">Z</span>{% endif %}
|
||||
{% if cost.any > 0 or cost.converted == 0 %}
|
||||
<span class="mana">{{ cost.any }}</span>
|
||||
<span class="mana symbol">{{ cost.any }}</span>
|
||||
{% endif %}
|
||||
{% for i in cost.snow|get_range %}
|
||||
{# use the unicode snowflake symbol #}
|
||||
<span class="mana symbol">❄</span>
|
||||
{% endfor %}
|
||||
{% for type, mana in cost.mana.mana.items %}
|
||||
{% for i in mana|get_range %}
|
||||
<span class="mana {{ type }}"></span>
|
||||
<span class="mana symbol {{ type }}"></span>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
<ul>
|
||||
{% for deck in decks %}
|
||||
<li>
|
||||
<a href="{% url mtgweb.decks.views.detail deck.id %}">{{ deck }}</a>
|
||||
{% for color, count in deck.colors.items %}
|
||||
<div class="manabar">
|
||||
{% for color, count in deck.colors.0.items %}
|
||||
{% if count > 0 %}
|
||||
<span class="mana {{ color }}"></span>
|
||||
<span class="mana {{ color }}" style="width: {{ count|mult:100|div:deck.colors.1 }}%"></span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<a href="{% url mtgweb.decks.views.detail deck.id %}">{{ deck }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue