Capture card ability text from the database

This commit is contained in:
Correl Roush 2010-07-01 17:34:11 -04:00
parent eeee15c738
commit 38179a2672
2 changed files with 10 additions and 5 deletions

View file

@ -31,23 +31,27 @@ class TextDB(Database):
'power': 0,
'toughness': 0,
'rarity': None,
'text': [],
}
elif card and line:
# Load the data into the card
if not card['cost'] and re.match('^X?\d*[{0}]*$'.format(' '.join(Mana.types.keys())), line):
card['cost'] = line
continue
if not card['type']:
elif not card['type']:
attributes = line.split(' -- ')
type = attributes.pop(0)
card['type'] = type
card['attributes'] = attributes
if not card['power'] and not card['toughness'] and re.match('^\d+([+-]?\*)?\/\d+([+-]?\*)?$', line):
elif not card['power'] and not card['toughness'] and re.match('^\d+([+-]?\*)?\/\d+([+-]?\*)?$', line):
(card['power'], card['toughness']) = line.split('/')
if not card['rarity'] and re.match('^([A-Z0-9]+-[{0}](, )?)+$'.format(' '.join(Card.rarities.keys())), line):
elif not card['rarity'] and re.match('^([A-Z0-9]+-[{0}](, )?)+$'.format(' '.join(Card.rarities.keys())), line):
sets = line.split(', ')
currentSet = sets.pop()
card['rarity'] = currentSet.split('-').pop()
else:
# Ability text
card['text'].append(line)
elif not line:
# Finished with current record
if card:
@ -58,7 +62,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'])
return Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['rarity'], card['text'])
if __name__ == '__main__':
db = TextDB('db.txt')

3
mtg.py
View file

@ -171,7 +171,7 @@ class Card:
'M': 'Mythic Rare',
}
def __init__(self, name, type, attributes, cost=0, power=0, toughness=0, rarity=None, owner=None):
def __init__(self, name, type, attributes, cost=0, power=0, toughness=0, rarity=None, text=[], owner=None):
self.name = name
self.type = type.lower()
self.attributes = [a.lower() for a in attributes]
@ -179,6 +179,7 @@ class Card:
self.power = power
self.toughness = toughness
self.rarity = rarity
self.text = text
self.is_tapped = False
self.abilities = []