Merge branch 'splatteredbits-master'

Bring over three new optional command line args to generate without
rules, tab art and text instead of set icons.
This commit is contained in:
Sumpfork 2015-06-08 10:29:18 -07:00
commit 50613475af

89
dominion_tabs.py Normal file → Executable file
View File

@ -57,6 +57,14 @@ class Card:
DominionTabs.setImages[self.cardset] = 0 DominionTabs.setImages[self.cardset] = 0
DominionTabs.promoImages[self.name.lower()] = 0 DominionTabs.promoImages[self.name.lower()] = 0
return setImage return setImage
def setTextIcon(self):
setTextIcon = DominionTabs.getSetText(self.cardset, self.name)
if setTextIcon is None and self.cardset not in ['base', 'extra'] and not self.isExpansion():
print 'warning, no set text for set "%s" card "%s"' % (self.cardset, self.name)
DominionTabs.setTextIcons[self.cardset] = 0
DominionTabs.promoTextIcons[self.name.lower()] = 0
return setTextIcon
def isBlank(self): def isBlank(self):
return False return False
@ -170,6 +178,31 @@ class DominionTabs:
'envoy': 'envoy_set.png', 'envoy': 'envoy_set.png',
'prince': 'prince_set.png' 'prince': 'prince_set.png'
} }
setTextIcons = {
'dominion': 'D',
'intrigue': 'I',
'seaside': 'S',
'prosperity': 'P',
'alchemy': 'A',
'cornucopia': 'C',
'cornucopia extras': 'C',
'hinterlands': 'H',
'dark ages': 'DA',
'dark ages extras': 'DA',
'guilds': 'G',
'adventures': 'Ad',
'adventures extras': 'Ad'
}
promoTextIcons = {
'walled village': '',
'stash': '',
'governor': '',
'black market': '',
'envoy': '',
'prince': ''
}
@classmethod @classmethod
def getSetImage(cls, setName, cardName): def getSetImage(cls, setName, cardName):
@ -187,6 +220,14 @@ class DominionTabs:
return cls.promoImages[trans.lower()] return cls.promoImages[trans.lower()]
return None return None
@classmethod
def getSetText(cls, setName, cardName):
if setName in cls.setTextIcons:
return cls.setTextIcons[setName]
if cardName.lower() in cls.promoTextIcons:
return cls.promoTextIcons[cardName.lower()]
return None
def __init__(self): def __init__(self):
self.filedir = os.path.dirname(__file__) self.filedir = os.path.dirname(__file__)
self.odd = True self.odd = True
@ -325,12 +366,15 @@ class DominionTabs:
# allow for 3 pt border on each side # allow for 3 pt border on each side
textWidth = self.tabLabelWidth - 6 textWidth = self.tabLabelWidth - 6
textHeight = self.tabLabelHeight / 2 - 7 + \ textHeight = 7
if self.options.no_tab_artwork:
textHeight = 4
textHeight = self.tabLabelHeight / 2 - textHeight + \
card.getType().getTabTextHeightOffset() card.getType().getTabTextHeightOffset()
# draw banner # draw banner
img = card.getType().getNoCoinTabImageFile() img = card.getType().getNoCoinTabImageFile()
if img: if not self.options.no_tab_artwork and img:
self.canvas.drawImage(os.path.join(self.filedir, 'images', img), 1, 0, self.canvas.drawImage(os.path.join(self.filedir, 'images', img), 1, 0,
self.tabLabelWidth - self.tabLabelWidth -
2, self.tabLabelHeight - 1, 2, self.tabLabelHeight - 1,
@ -348,16 +392,28 @@ class DominionTabs:
textInset = 13 textInset = 13
# draw set image # draw set image
setImage = card.setImage() # always need to offset from right edge, to make sure it stays on
if setImage and 'tab' in self.options.set_icon: # banner
setImageHeight = 3 + card.getType().getTabTextHeightOffset() textInsetRight = 6
self.drawSetIcon(setImage, self.tabLabelWidth - 20, if self.options.use_text_set_icon:
setImageHeight) setImageHeight = card.getType().getTabTextHeightOffset()
textInsetRight = 20 #self.canvas.rect(self.tabLabelWidth - 20, setImageHeight, 20, 20, 1 )
setText = card.setTextIcon()
self.canvas.setFont('MinionPro-Oblique', 8)
if setText is None:
setText = ""
self.canvas.drawCentredString( self.tabLabelWidth - 10, textHeight + 2, setText)
textInsetRight = 15
else: else:
# always need to offset from right edge, to make sure it stays on setImage = card.setImage()
# banner if setImage and 'tab' in self.options.set_icon:
textInsetRight = 6 setImageHeight = 3 + card.getType().getTabTextHeightOffset()
self.drawSetIcon(setImage, self.tabLabelWidth - 20,
setImageHeight)
textInsetRight = 20
# draw name # draw name
fontSize = 12 fontSize = 12
@ -443,6 +499,9 @@ class DominionTabs:
if drewTopIcon: if drewTopIcon:
usedHeight += 15 usedHeight += 15
if self.options.no_card_rules:
return
# draw text # draw text
if useExtra and card.extra: if useExtra and card.extra:
descriptions = (card.extra,) descriptions = (card.extra,)
@ -792,6 +851,12 @@ class DominionTabs:
default=False, help="exclude individual dividers for events") default=False, help="exclude individual dividers for events")
parser.add_option("--cardlist", type="string", dest="cardlist", default=None, parser.add_option("--cardlist", type="string", dest="cardlist", default=None,
help="Path to file that enumerates each card to be printed on its own line.") help="Path to file that enumerates each card to be printed on its own line.")
parser.add_option("--no-tab-artwork", action="store_true", dest="no_tab_artwork",
help="don't show background artwork on tabs")
parser.add_option("--no-card-rules", action="store_true", dest="no_card_rules",
help="don't print the card's rules on the tab body")
parser.add_option("--use-text-set-icon", action="store_true", dest="use_text_set_icon",
help="use text/letters to represent a card's set instead of the set icon")
options, args = parser.parse_args(argstring) options, args = parser.parse_args(argstring)
if not options.cost: if not options.cost:
@ -965,6 +1030,8 @@ class DominionTabs:
TTFont('MinionPro-Regular', os.path.join(dirn, 'MinionPro-Regular.ttf'))) TTFont('MinionPro-Regular', os.path.join(dirn, 'MinionPro-Regular.ttf')))
pdfmetrics.registerFont( pdfmetrics.registerFont(
TTFont('MinionPro-Bold', os.path.join(dirn, 'MinionPro-Bold.ttf'))) TTFont('MinionPro-Bold', os.path.join(dirn, 'MinionPro-Bold.ttf')))
pdfmetrics.registerFont(
TTFont('MinionPro-Oblique', os.path.join(dirn, 'MinionPro-It.ttf')))
except: except:
raise raise
pdfmetrics.registerFont( pdfmetrics.registerFont(