Load card sets in from db

This commit is contained in:
Correl Roush 2010-07-02 00:28:12 -04:00
parent 9f98b5e1c9
commit 8f38aaf09b
2 changed files with 7 additions and 5 deletions

View file

@ -45,9 +45,10 @@ class TextDB(Database):
card['attributes'] = attributes
elif not card['power'] and not card['toughness'] and re.match('^\d+([+-]?\*)?\/\d+([+-]?\*)?$', line):
(card['power'], card['toughness']) = line.split('/')
elif not card['rarity'] and re.match('^([A-Z0-9]+-[{0}](, )?)+$'.format(' '.join(Card.rarities.keys())), line):
sets = line.split(', ')
currentSet = sets.pop()
elif re.match('^([A-Z0-9]+-[{0}](, )?)+$'.format(''.join(Card.rarities.keys())), line):
info = line.split(', ')
card['sets'] = [i.split('-').pop(0) for i in info]
currentSet = info.pop()
card['rarity'] = currentSet.split('-').pop()
else:
# Ability text
@ -62,7 +63,7 @@ class TextDB(Database):
inRecord = False
if not card:
return None
return Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['rarity'], card['text'])
return Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['sets'], card['rarity'], card['text'])
if __name__ == '__main__':
db = TextDB('db.txt')

3
mtg.py
View file

@ -172,13 +172,14 @@ class Card:
'M': 'Mythic Rare',
}
def __init__(self, name, type, attributes, cost=0, power=0, toughness=0, rarity=None, text=[], owner=None):
def __init__(self, name, type, attributes, cost=0, power=0, toughness=0, sets=None, rarity=None, text=[], owner=None):
self.name = name
self.type = type.lower()
self.attributes = [a.lower() for a in attributes]
self.cost = ManaCost(cost)
self.power = power
self.toughness = toughness
self.sets = sets
self.rarity = rarity
self.text = text
self.colors = [color for color, cost in self.cost.mana.mana.iteritems() if cost > 0]