Added a Wagic card db class

This commit is contained in:
Correl Roush 2010-07-03 01:30:42 -04:00
parent ae2b642f53
commit 3ef6d0196b

View file

@ -1,3 +1,4 @@
import os
import re
from mtg import *
@ -65,7 +66,37 @@ class TextDB(Database):
return None
return Card(card['name'], card['type'], card['attributes'], card['cost'], card['power'], card['toughness'], card['sets'], card['rarity'], card['text'])
class WagicDB(Database):
def __init__(self, wagicPath):
self.path = wagicPath
self.db = {}
self.loadDb()
def loadDb(self):
for root, dirs, files in os.walk(self.path + '/Res/sets'):
if '_cards.dat' not in files: continue
set = root.split('/')[-1]
with open(root + '/_cards.dat', 'r') as f:
for line in f:
if not line.startswith('primitive='): continue
primitive = line.split('=')[1].strip()
if not primitive in self.db.keys():
self.db[primitive] = []
self.db[primitive].append(set)
def getCard(self, name, baseCard):
card = baseCard
unsupported = [set for set in card.sets if set not in self.db[card.name]]
#if unsupported:
# print '{0}: Unsupported sets: {1}'.format(card.name, unsupported)
supported = [set for set in card.sets if set in self.db[card.name]]
card.sets = supported
return card
if __name__ == '__main__':
db = TextDB('db.txt')
c = db.getCard('Aura Gnarlid')
print c
deck = Deck()
deck.load('decks/BlackSiege.txt', db)
wagic = Deck()
w = WagicDB('/home/correlr/Download/wth/PSP/GAME/WTH')
for card in deck:
wagic.append(w.getCard(card.name, card))