Load card sets in from db
This commit is contained in:
parent
9f98b5e1c9
commit
8f38aaf09b
2 changed files with 7 additions and 5 deletions
|
@ -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
3
mtg.py
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue