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 django.db import models
|
||||||
from mtgweb.lib.mtg import mtg
|
from mtgweb.lib.mtg import mtg
|
||||||
|
|
||||||
|
@ -29,16 +30,25 @@ class Deck(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
def colors(self):
|
def colors(self):
|
||||||
mana = {}
|
symbols = {}
|
||||||
symbols = 0
|
for symbol in mtg.Mana.types.keys():
|
||||||
|
symbols[symbol] = 0
|
||||||
|
total = 0
|
||||||
for card in self.cards.all():
|
for card in self.cards.all():
|
||||||
|
# Get symbols from card cost
|
||||||
cost = mtg.ManaCost(card.cost)
|
cost = mtg.ManaCost(card.cost)
|
||||||
for color, count in cost.mana.mana.iteritems():
|
for color, count in cost.mana.mana.iteritems():
|
||||||
if not color in mana.keys():
|
symbols[color] += count
|
||||||
mana[color] = 0
|
total += count
|
||||||
mana[color] += count
|
|
||||||
symbols += count
|
# Get symbols from abilities
|
||||||
return mana
|
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):
|
class Included(models.Model):
|
||||||
card = models.ForeignKey(Card)
|
card = models.ForeignKey(Card)
|
||||||
deck = models.ForeignKey(Deck)
|
deck = models.ForeignKey(Deck)
|
||||||
|
|
|
@ -7,8 +7,7 @@ from mtgweb.lib.mtg.mtg import Mana, ManaCost
|
||||||
import mtgweb.lib.mtg.database as database
|
import mtgweb.lib.mtg.database as database
|
||||||
|
|
||||||
def prettify_mana(text):
|
def prettify_mana(text):
|
||||||
manapattern = r'X?\d*(\((\d+|[{0}])/(\d+|[{0}])\))*[{0}]*'.format(''.join(Mana.types.keys()))
|
pattern = r'{%s}' % ManaCost.symbolPattern
|
||||||
pattern = r'{%s}' % manapattern
|
|
||||||
while True:
|
while True:
|
||||||
match = re.search(pattern, text)
|
match = re.search(pattern, text)
|
||||||
if not match:
|
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;
|
margin-left: 160px;
|
||||||
}
|
}
|
||||||
/* Cards and mana symbols */
|
/* Cards and mana symbols */
|
||||||
.mana {
|
.mana.symbol {
|
||||||
height: 1em;
|
height: 1em;
|
||||||
width: 1em;
|
width: 1em;
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
|
@ -102,3 +102,15 @@ header {
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
text-shadow: 2px 2px 2px #999;
|
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 %}
|
{% 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 %}
|
{% if cost.any > 0 or cost.converted == 0 %}
|
||||||
<span class="mana">{{ cost.any }}</span>
|
<span class="mana symbol">{{ cost.any }}</span>
|
||||||
{% endif %}
|
{% 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 type, mana in cost.mana.mana.items %}
|
||||||
{% for i in mana|get_range %}
|
{% for i in mana|get_range %}
|
||||||
<span class="mana {{ type }}"></span>
|
<span class="mana symbol {{ type }}"></span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -6,12 +6,14 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for deck in decks %}
|
{% for deck in decks %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url mtgweb.decks.views.detail deck.id %}">{{ deck }}</a>
|
<div class="manabar">
|
||||||
{% for color, count in deck.colors.items %}
|
{% for color, count in deck.colors.0.items %}
|
||||||
{% if count > 0 %}
|
{% if count > 0 %}
|
||||||
<span class="mana {{ color }}"></span>
|
<span class="mana {{ color }}" style="width: {{ count|mult:100|div:deck.colors.1 }}%"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<a href="{% url mtgweb.decks.views.detail deck.id %}">{{ deck }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue