From 8f38aaf09bf781471562db7d8f73bd76df71e7c3 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 2 Jul 2010 00:28:12 -0400 Subject: [PATCH] Load card sets in from db --- database.py | 9 +++++---- mtg.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/database.py b/database.py index 6efe9ae..8972ed4 100644 --- a/database.py +++ b/database.py @@ -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') diff --git a/mtg.py b/mtg.py index 30bf51f..1dae979 100644 --- a/mtg.py +++ b/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]