optional support for blank dividers with extra text. Some minor fixes and pep8.

This commit is contained in:
Sumpfork 2014-12-01 15:23:40 -08:00
parent 68f4d827a5
commit 88df1c2f3f
3 changed files with 92 additions and 66 deletions

View File

@ -336,7 +336,7 @@ ______________________
When you gain this, look through your discard pile (including this), reveal any number of Action cards from it, and shuffle them into your deck.
22 Mandarin Hinterlands Action $5 +3 Coins
Put a card from your hand on top of your deck.
----------------------
----------
When you gain this, put all Treasures you have in play on top of your deck in any order.
23 Margrave Hinterlands Action - Attack $5 +3 Cards
+1 Buy
@ -344,7 +344,7 @@ Each other player draws a card, then discards down to 3 cards in hand.
24 Stables Hinterlands Action $5 You may discard a Treasure. If you do, +3 Cards and +1 Action.
25 Border Village Hinterlands Action $6 +1 Card
+2 Actions
----------------------
----------
When you gain this, gain a card costing less than this.
26 Farmland Hinterlands Victory $6 2 <VP>
----------

View File

@ -9,3 +9,4 @@
"Ruins": "Ruins"
"Looter": "Looter"
"Curse": "Curse"
"Blank": "Blank"

View File

@ -14,6 +14,7 @@ from reportlab.lib.enums import TA_JUSTIFY
import yaml
def split(l, n):
i = 0
while i < len(l) - n:
@ -21,8 +22,9 @@ def split(l,n):
i += n
yield l[i:]
class Card:
def __init__(self,name,cardset,types,cost,description,potcost=0):
def __init__(self, name, cardset, types, cost, description='', potcost=0):
self.name = name.strip()
self.cardset = cardset.strip()
self.types = types
@ -38,19 +40,31 @@ class Card:
return '"' + self.name + '"'
def toString(self):
return self.name + ' ' + self.cardset + ' ' + '-'.join(self.types) + ' ' + `self.cost` + ' ' + self.description + ' ' + self.extra
return self.name + ' ' + self.cardset + ' ' + '-'.join(self.types)\
+ ' ' + self.cost + ' ' + self.description + ' ' + self.extra
def isExpansion(self):
return self.getType().getTypeNames() == ('Expansion',)
def setImage(self):
setImage = DominionTabs.getSetImage(self.cardset, self.name)
if setImage is None and self.cardset != 'base' and not self.isExpansion():
if setImage is None and self.cardset not in ['base', 'extra'] and not self.isExpansion():
print 'warning, no set image for set "%s" card "%s"' % (self.cardset, self.name)
DominionTabs.setImages[self.cardset] = 0
DominionTabs.promoImages[self.name.lower()] = 0
return setImage
def isBlank(self):
return False
class BlankCard(Card):
def __init__(self, num):
Card.__init__(self, str(num), 'extra', ('Blank',), 0)
def isBlank(self):
return True
class CardType:
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
@ -63,9 +77,13 @@ class CardType:
return self.typeNames
def getTabImageFile(self):
if not self.tabImageFile:
return None
return self.tabImageFile
def getNoCoinTabImageFile(self):
if not self.tabImageFile:
return None
return ''.join(os.path.splitext(self.tabImageFile)[0] + '_nc' + os.path.splitext(self.tabImageFile)[1])
def getTabTextHeightOffset(self):
@ -97,7 +115,8 @@ class DominionTabs:
CardType(('Victory', 'Reaction'), 'victory-reaction.png', 0, 1),
CardType(('Victory', 'Shelter'), 'shelter.png', 0, 1),
CardType(('Curse',), 'curse.png', 3),
CardType(('Expansion',), 'expansion.png', 4)
CardType(('Expansion',), 'expansion.png', 4),
CardType(('Blank',), '')
]
cardTypes = dict(((c.getTypeNames(), c) for c in cardTypes))
@ -131,7 +150,6 @@ class DominionTabs:
@classmethod
def getSetImage(cls, setName, cardName):
#print setName, cardName
if setName in cls.setImages:
return cls.setImages[setName]
if cardName.lower() in cls.promoImages:
@ -276,12 +294,14 @@ class DominionTabs:
textHeight = self.tabLabelHeight/2-7+card.getType().getTabTextHeightOffset()
# draw banner
self.canvas.drawImage(os.path.join(self.filedir,'images',card.getType().getNoCoinTabImageFile()),1,0,
img = card.getType().getNoCoinTabImageFile()
if img:
self.canvas.drawImage(os.path.join(self.filedir, 'images', img), 1, 0,
self.tabLabelWidth - 2, self.tabLabelHeight - 1,
preserveAspectRatio=False, anchor='n', mask='auto')
# draw cost
if not card.isExpansion():
if not card.isExpansion() and not card.isBlank():
if 'tab' in self.options.cost:
textInset = 4
textInset += self.drawCost(card, textInset, textHeight,
@ -455,36 +475,45 @@ class DominionTabs:
currentCard = ""
extra = ""
blank = 1
isBlank = False
blanks = {}
for line in f:
line = line.decode('utf-8')
m = cardName.match(line)
if m:
if currentCard:
#print 'found',currentCard
#print extra
#print '------------------'
if isBlank:
blanks[currentCard] = extra
else:
extras[currentCard] = extra
currentCard = m.groupdict()["name"]
if not currentCard:
currentCard = 'Blank' + str(blank)
blank += 1
extra = ""
if not self.options.expansions and currentCard and (currentCard not in (c.name for c in cards)):
if not currentCard:
currentCard = blank
blank += 1
isBlank = True
else:
isBlank = False
if not self.options.expansions\
and currentCard and (currentCard not in (c.name for c in cards)):
print currentCard + ' has extra description, but is not in cards'
else:
extra += ' ' + line.strip()
if currentCard and extra:
if currentCard.startswith('Blank'):
if isBlank:
blanks[currentCard] = extra.strip()
else:
extras[currentCard] = extra.strip()
if self.options.include_blanks:
for blank, extra in blanks.iteritems():
card = BlankCard(blank)
cards.append(card)
extras[card.name] = extra
for c in cards:
if c.name not in extras:
print c.name + ' missing from extras'
else:
c.extra = extras[c.name]
#print c.name + ' ::: ' + extra
baseactionRE = re.compile("^\s*(\+\d+\s+\w+)(?:[,.;])")
@ -522,7 +551,6 @@ class DominionTabs:
descriptions = [x for x in descriptions if x]
card.description = u'\n'.join(descriptions)
def read_card_defs(self, fname, fileobject=None):
cards = []
f = open(fname)
@ -548,8 +576,6 @@ class DominionTabs:
elif line:
assert currentCard
self.add_definition_line(currentCard, line)
#print currentCard
#print '----'
return cards
def drawSetNames(self, pageCards):
@ -646,8 +672,6 @@ class DominionTabs:
if pageNum + 1 == self.options.num_pages:
break
LOCATION_CHOICES = ["tab", "body-top", "hide"]
@classmethod
@ -655,7 +679,8 @@ class DominionTabs:
parser = OptionParser()
parser.add_option("--back_offset", type="float", dest="back_offset", default=0,
help="Points to offset the back page to the right; needed for some printers")
parser.add_option("--orientation",type="choice",choices=["horizontal","vertical"],dest="orientation",default="horizontal",
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
dest="orientation", default="horizontal",
help="horizontal or vertical, default:horizontal")
parser.add_option("--sleeved", action="store_true", dest="sleeved", help="use --size=sleeved instead")
parser.add_option("--size", type="string", dest="size", default='normal',
@ -714,7 +739,7 @@ class DominionTabs:
parser.add_option("--num_pages", type="int", default=-1,
help="stop generating after this many pages, -1 for all")
parser.add_option("--language", default='en_us', help="language of card texts")
parser.add_option("--include_blanks", action="store_true", help="include a few dividers with extra text")
options, args = parser.parse_args(argstring)
if not options.cost:
options.cost = ['tab']
@ -878,12 +903,12 @@ class DominionTabs:
cards = self.read_card_defs(os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
self.read_card_extras(os.path.join(self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
DominionTabs.language_mapping = yaml.load(open(os.path.join(self.filedir, "card_db", options.language, "mapping.yaml")))
print DominionTabs.language_mapping
baseCards = [card.name for card in cards if card.cardset.lower() == 'base']
def isBaseExpansionCard(card):
return card.cardset.lower() != 'base' and card.name in baseCards
if self.options.base_cards_with_expansion:
cards = [card for card in cards if card.cardset.lower() != 'base']
else: