pep8
This commit is contained in:
parent
a7cc600ef7
commit
9a5dac3a55
159
dominion_tabs.py
159
dominion_tabs.py
@ -24,6 +24,7 @@ def split(l, n):
|
|||||||
|
|
||||||
|
|
||||||
class Card:
|
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.name = name.strip()
|
||||||
self.cardset = cardset.strip()
|
self.cardset = cardset.strip()
|
||||||
@ -62,6 +63,7 @@ class Card:
|
|||||||
|
|
||||||
|
|
||||||
class BlankCard(Card):
|
class BlankCard(Card):
|
||||||
|
|
||||||
def __init__(self, num):
|
def __init__(self, num):
|
||||||
Card.__init__(self, str(num), 'extra', ('Blank',), 0)
|
Card.__init__(self, str(num), 'extra', ('Blank',), 0)
|
||||||
|
|
||||||
@ -70,6 +72,7 @@ class BlankCard(Card):
|
|||||||
|
|
||||||
|
|
||||||
class CardType:
|
class CardType:
|
||||||
|
|
||||||
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
||||||
self.typeNames = typeNames
|
self.typeNames = typeNames
|
||||||
self.tabImageFile = tabImageFile
|
self.tabImageFile = tabImageFile
|
||||||
@ -95,6 +98,7 @@ class CardType:
|
|||||||
def getTabCostHeightOffset(self):
|
def getTabCostHeightOffset(self):
|
||||||
return self.tabCostHeightOffset
|
return self.tabCostHeightOffset
|
||||||
|
|
||||||
|
|
||||||
class DominionTabs:
|
class DominionTabs:
|
||||||
cardTypes = [
|
cardTypes = [
|
||||||
CardType(('Action',), 'action.png'),
|
CardType(('Action',), 'action.png'),
|
||||||
@ -188,11 +192,14 @@ class DominionTabs:
|
|||||||
|
|
||||||
def add_inline_images(self, text, fontsize):
|
def add_inline_images(self, text, fontsize):
|
||||||
path = os.path.join(self.filedir, 'images')
|
path = os.path.join(self.filedir, 'images')
|
||||||
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (path,fontsize*1.2)
|
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||||
|
path, fontsize * 1.2)
|
||||||
text = re.sub('(\d)\s(c|C)oin(s)?', replace, text)
|
text = re.sub('(\d)\s(c|C)oin(s)?', replace, text)
|
||||||
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (path,fontsize*1.2)
|
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||||
|
path, fontsize * 1.2)
|
||||||
text = re.sub('\?\s(c|C)oin(s)?', replace, text)
|
text = re.sub('\?\s(c|C)oin(s)?', replace, text)
|
||||||
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (path,fontsize*1.5)
|
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (
|
||||||
|
path, fontsize * 1.5)
|
||||||
text = re.sub('\<VP\>', replace, text)
|
text = re.sub('\<VP\>', replace, text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@ -206,7 +213,8 @@ class DominionTabs:
|
|||||||
self.canvas.translate(self.tabWidth, 0)
|
self.canvas.translate(self.tabWidth, 0)
|
||||||
self.canvas.scale(-1, 1)
|
self.canvas.scale(-1, 1)
|
||||||
if not self.options.cropmarks and not isBack:
|
if not self.options.cropmarks and not isBack:
|
||||||
#don't draw outline on back, in case lines don't line up with front
|
# don't draw outline on back, in case lines don't line up with
|
||||||
|
# front
|
||||||
if isExpansionDivider and self.options.centre_expansion_dividers:
|
if isExpansionDivider and self.options.centre_expansion_dividers:
|
||||||
outline = self.expansionTabOutline
|
outline = self.expansionTabOutline
|
||||||
else:
|
else:
|
||||||
@ -223,9 +231,11 @@ class DominionTabs:
|
|||||||
self.canvas.scale(-1, 1)
|
self.canvas.scale(-1, 1)
|
||||||
if cropmarksleft or cropmarksright:
|
if cropmarksleft or cropmarksright:
|
||||||
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
||||||
self.canvas.line(-2*cmw,self.tabBaseHeight,-cmw,self.tabBaseHeight)
|
self.canvas.line(-2 * cmw,
|
||||||
|
self.tabBaseHeight, -cmw, self.tabBaseHeight)
|
||||||
if y > 0:
|
if y > 0:
|
||||||
self.canvas.line(-2*cmw,self.tabHeight,-cmw,self.tabHeight)
|
self.canvas.line(-2 * cmw,
|
||||||
|
self.tabHeight, -cmw, self.tabHeight)
|
||||||
if mirror:
|
if mirror:
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
@ -269,9 +279,11 @@ class DominionTabs:
|
|||||||
potHeight = y - 3
|
potHeight = y - 3
|
||||||
potSize = 11
|
potSize = 11
|
||||||
|
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images','coin_small.png'),x,coinHeight,16,16,preserveAspectRatio=True,mask='auto')
|
self.canvas.drawImage(os.path.join(self.filedir, 'images', 'coin_small.png'),
|
||||||
|
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||||
if card.potcost:
|
if card.potcost:
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images','potion.png'),x+17,potHeight,potSize,potSize,preserveAspectRatio=True,mask=[255,255,255,255,255,255])
|
self.canvas.drawImage(os.path.join(self.filedir, 'images', 'potion.png'), x + 17,
|
||||||
|
potHeight, potSize, potSize, preserveAspectRatio=True, mask=[255, 255, 255, 255, 255, 255])
|
||||||
width += potSize
|
width += potSize
|
||||||
|
|
||||||
self.canvas.setFont('MinionPro-Bold', 12)
|
self.canvas.setFont('MinionPro-Bold', 12)
|
||||||
@ -283,7 +295,8 @@ class DominionTabs:
|
|||||||
|
|
||||||
def drawSetIcon(self, setImage, x, y):
|
def drawSetIcon(self, setImage, x, y):
|
||||||
# set image
|
# set image
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images',setImage), x, y, 14, 12, mask='auto')
|
self.canvas.drawImage(
|
||||||
|
os.path.join(self.filedir, 'images', setImage), x, y, 14, 12, mask='auto')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def nameWidth(self, name, fontSize):
|
def nameWidth(self, name, fontSize):
|
||||||
@ -293,7 +306,8 @@ class DominionTabs:
|
|||||||
if i != 0:
|
if i != 0:
|
||||||
w += pdfmetrics.stringWidth(' ', 'MinionPro-Regular', fontSize)
|
w += pdfmetrics.stringWidth(' ', 'MinionPro-Regular', fontSize)
|
||||||
w += pdfmetrics.stringWidth(part[0], 'MinionPro-Regular', fontSize)
|
w += pdfmetrics.stringWidth(part[0], 'MinionPro-Regular', fontSize)
|
||||||
w += pdfmetrics.stringWidth(part[1:],'MinionPro-Regular',fontSize-2)
|
w += pdfmetrics.stringWidth(part[1:],
|
||||||
|
'MinionPro-Regular', fontSize - 2)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def drawTab(self, card, rightSide):
|
def drawTab(self, card, rightSide):
|
||||||
@ -308,14 +322,17 @@ class DominionTabs:
|
|||||||
else:
|
else:
|
||||||
self.canvas.translate(0, self.tabHeight - self.tabLabelHeight)
|
self.canvas.translate(0, self.tabHeight - self.tabLabelHeight)
|
||||||
|
|
||||||
textWidth = self.tabLabelWidth - 6 # allow for 3 pt border on each side
|
# allow for 3 pt border on each side
|
||||||
textHeight = self.tabLabelHeight/2-7+card.getType().getTabTextHeightOffset()
|
textWidth = self.tabLabelWidth - 6
|
||||||
|
textHeight = self.tabLabelHeight / 2 - 7 + \
|
||||||
|
card.getType().getTabTextHeightOffset()
|
||||||
|
|
||||||
# draw banner
|
# draw banner
|
||||||
img = card.getType().getNoCoinTabImageFile()
|
img = card.getType().getNoCoinTabImageFile()
|
||||||
if img:
|
if 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 - 2, self.tabLabelHeight - 1,
|
self.tabLabelWidth -
|
||||||
|
2, self.tabLabelHeight - 1,
|
||||||
preserveAspectRatio=False, anchor='n', mask='auto')
|
preserveAspectRatio=False, anchor='n', mask='auto')
|
||||||
|
|
||||||
# draw cost
|
# draw cost
|
||||||
@ -376,6 +393,7 @@ class DominionTabs:
|
|||||||
words = line.split()
|
words = line.split()
|
||||||
if rightSide or not self.options.edge_align_name:
|
if rightSide or not self.options.edge_align_name:
|
||||||
w = textInset
|
w = textInset
|
||||||
|
|
||||||
def drawWordPiece(text, fontSize):
|
def drawWordPiece(text, fontSize):
|
||||||
self.canvas.setFont('MinionPro-Regular', fontSize)
|
self.canvas.setFont('MinionPro-Regular', fontSize)
|
||||||
if text != ' ':
|
if text != ' ':
|
||||||
@ -393,6 +411,7 @@ class DominionTabs:
|
|||||||
|
|
||||||
w = self.tabLabelWidth - textInsetRight - 3
|
w = self.tabLabelWidth - textInsetRight - 3
|
||||||
words.reverse()
|
words.reverse()
|
||||||
|
|
||||||
def drawWordPiece(text, fontSize):
|
def drawWordPiece(text, fontSize):
|
||||||
self.canvas.setFont('MinionPro-Regular', fontSize)
|
self.canvas.setFont('MinionPro-Regular', fontSize)
|
||||||
if text != ' ':
|
if text != ' ':
|
||||||
@ -481,7 +500,8 @@ class DominionTabs:
|
|||||||
|
|
||||||
# actual drawing
|
# actual drawing
|
||||||
if not self.options.tabs_only:
|
if not self.options.tabs_only:
|
||||||
self.drawOutline(x, y, rightSide, useExtra, card.getType().getTypeNames() == ('Expansion',))
|
self.drawOutline(
|
||||||
|
x, y, rightSide, useExtra, card.getType().getTypeNames() == ('Expansion',))
|
||||||
self.drawTab(card, rightSide)
|
self.drawTab(card, rightSide)
|
||||||
if not self.options.tabs_only:
|
if not self.options.tabs_only:
|
||||||
self.drawText(card, useExtra)
|
self.drawText(card, useExtra)
|
||||||
@ -549,7 +569,8 @@ class DominionTabs:
|
|||||||
# To solve:
|
# To solve:
|
||||||
|
|
||||||
# 1)
|
# 1)
|
||||||
# try to figure out if this a 'basic action' like +X Cards or +Y Actions
|
# try to figure out if this a 'basic action' like +X Cards or +Y
|
||||||
|
# Actions
|
||||||
descriptions = [card.description]
|
descriptions = [card.description]
|
||||||
while True:
|
while True:
|
||||||
m = self.baseactionRE.match(line, re.UNICODE)
|
m = self.baseactionRE.match(line, re.UNICODE)
|
||||||
@ -585,11 +606,13 @@ class DominionTabs:
|
|||||||
potcost = 0
|
potcost = 0
|
||||||
currentCard = Card(m.groupdict()["name"].strip(),
|
currentCard = Card(m.groupdict()["name"].strip(),
|
||||||
m.groupdict()["set"].lower().strip(),
|
m.groupdict()["set"].lower().strip(),
|
||||||
tuple([t.strip() for t in m.groupdict()["type"].split("-")]),
|
tuple(
|
||||||
|
[t.strip() for t in m.groupdict()["type"].split("-")]),
|
||||||
m.groupdict()["cost"],
|
m.groupdict()["cost"],
|
||||||
'',
|
'',
|
||||||
potcost)
|
potcost)
|
||||||
self.add_definition_line(currentCard, m.groupdict()["description"])
|
self.add_definition_line(
|
||||||
|
currentCard, m.groupdict()["description"])
|
||||||
cards.append(currentCard)
|
cards.append(currentCard)
|
||||||
elif line:
|
elif line:
|
||||||
assert currentCard
|
assert currentCard
|
||||||
@ -620,7 +643,8 @@ class DominionTabs:
|
|||||||
'width': self.paperheight}]
|
'width': self.paperheight}]
|
||||||
|
|
||||||
for layout in layouts:
|
for layout in layouts:
|
||||||
availableMargin = layout['totalMarginHeight'] - layout['minMarginHeight']
|
availableMargin = layout[
|
||||||
|
'totalMarginHeight'] - layout['minMarginHeight']
|
||||||
fontsize = availableMargin / fontHeightRelative
|
fontsize = availableMargin / fontHeightRelative
|
||||||
fontsize = min(maxFontsize, fontsize)
|
fontsize = min(maxFontsize, fontsize)
|
||||||
if fontsize >= minFontsize:
|
if fontsize >= minFontsize:
|
||||||
@ -656,7 +680,8 @@ class DominionTabs:
|
|||||||
cards = split(cards, self.numTabsVertical * self.numTabsHorizontal)
|
cards = split(cards, self.numTabsVertical * self.numTabsHorizontal)
|
||||||
self.odd = True
|
self.odd = True
|
||||||
for pageNum, pageCards in enumerate(cards):
|
for pageNum, pageCards in enumerate(cards):
|
||||||
#remember whether we start with odd or even divider for tab location
|
# remember whether we start with odd or even divider for tab
|
||||||
|
# location
|
||||||
pageStartOdd = self.odd
|
pageStartOdd = self.odd
|
||||||
if not self.options.tabs_only and self.options.order != "global":
|
if not self.options.tabs_only and self.options.order != "global":
|
||||||
self.drawSetNames(pageCards)
|
self.drawSetNames(pageCards)
|
||||||
@ -683,7 +708,8 @@ class DominionTabs:
|
|||||||
x = (self.numTabsHorizontal - 1 - i) % self.numTabsHorizontal
|
x = (self.numTabsHorizontal - 1 - i) % self.numTabsHorizontal
|
||||||
y = i / self.numTabsHorizontal
|
y = i / self.numTabsHorizontal
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
self.drawDivider(card,x,self.numTabsVertical-1-y,useExtra=True)
|
self.drawDivider(
|
||||||
|
card, x, self.numTabsVertical - 1 - y, useExtra=True)
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
self.odd = not self.odd
|
self.odd = not self.odd
|
||||||
self.canvas.showPage()
|
self.canvas.showPage()
|
||||||
@ -700,7 +726,8 @@ class DominionTabs:
|
|||||||
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
||||||
dest="orientation", default="horizontal",
|
dest="orientation", default="horizontal",
|
||||||
help="horizontal or vertical, 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("--sleeved", action="store_true",
|
||||||
|
dest="sleeved", help="use --size=sleeved instead")
|
||||||
parser.add_option("--size", type="string", dest="size", default='normal',
|
parser.add_option("--size", type="string", dest="size", default='normal',
|
||||||
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
||||||
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
||||||
@ -756,9 +783,12 @@ class DominionTabs:
|
|||||||
help='centre the tabs on expansion dividers')
|
help='centre the tabs on expansion dividers')
|
||||||
parser.add_option("--num_pages", type="int", default=-1,
|
parser.add_option("--num_pages", type="int", default=-1,
|
||||||
help="stop generating after this many pages, -1 for all")
|
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(
|
||||||
parser.add_option("--include_blanks", action="store_true", help="include a few dividers with extra text")
|
"--language", default='en_us', help="language of card texts")
|
||||||
parser.add_option("--exclude_events", action="store_true", default=False, help="exclude individual dividers for events")
|
parser.add_option("--include_blanks", action="store_true",
|
||||||
|
help="include a few dividers with extra text")
|
||||||
|
parser.add_option("--exclude_events", action="store_true",
|
||||||
|
default=False, help="exclude individual dividers for events")
|
||||||
|
|
||||||
options, args = parser.parse_args(argstring)
|
options, args = parser.parse_args(argstring)
|
||||||
if not options.cost:
|
if not options.cost:
|
||||||
@ -838,7 +868,8 @@ class DominionTabs:
|
|||||||
self.verticalBorderSpace = 0.01 * cm
|
self.verticalBorderSpace = 0.01 * cm
|
||||||
fixedMargins = True
|
fixedMargins = True
|
||||||
else:
|
else:
|
||||||
minmarginwidth, minmarginheight = self.parseDimensions(self.options.minmargin)
|
minmarginwidth, minmarginheight = self.parseDimensions(
|
||||||
|
self.options.minmargin)
|
||||||
self.tabLabelWidth = self.options.tabwidth * cm
|
self.tabLabelWidth = self.options.tabwidth * cm
|
||||||
self.tabLabelHeight = .9 * cm
|
self.tabLabelHeight = .9 * cm
|
||||||
self.horizontalBorderSpace = 0 * cm
|
self.horizontalBorderSpace = 0 * cm
|
||||||
@ -846,7 +877,8 @@ class DominionTabs:
|
|||||||
|
|
||||||
self.tabHeight = self.tabBaseHeight + self.tabLabelHeight
|
self.tabHeight = self.tabBaseHeight + self.tabLabelHeight
|
||||||
|
|
||||||
#note: this is convenient, but somewhat inaccurate as the border space isn't actually part of the tab width
|
# note: this is convenient, but somewhat inaccurate as the border space
|
||||||
|
# isn't actually part of the tab width
|
||||||
self.totalTabWidth = self.tabWidth + self.horizontalBorderSpace
|
self.totalTabWidth = self.tabWidth + self.horizontalBorderSpace
|
||||||
self.totalTabHeight = self.tabHeight + self.verticalBorderSpace
|
self.totalTabHeight = self.tabHeight + self.verticalBorderSpace
|
||||||
|
|
||||||
@ -855,10 +887,14 @@ class DominionTabs:
|
|||||||
|
|
||||||
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
||||||
# so it gets added back in to the page size here
|
# so it gets added back in to the page size here
|
||||||
numTabsVerticalP = int ((self.paperheight - 2*minmarginheight + self.verticalBorderSpace) / self.totalTabHeight)
|
numTabsVerticalP = int(
|
||||||
numTabsHorizontalP = int ((self.paperwidth - 2*minmarginwidth + self.horizontalBorderSpace) / self.totalTabWidth)
|
(self.paperheight - 2 * minmarginheight + self.verticalBorderSpace) / self.totalTabHeight)
|
||||||
numTabsVerticalL = int ((self.paperwidth - 2*minmarginwidth + self.verticalBorderSpace) / self.totalTabHeight)
|
numTabsHorizontalP = int(
|
||||||
numTabsHorizontalL = int ((self.paperheight - 2*minmarginheight + self.horizontalBorderSpace) / self.totalTabWidth)
|
(self.paperwidth - 2 * minmarginwidth + self.horizontalBorderSpace) / self.totalTabWidth)
|
||||||
|
numTabsVerticalL = int(
|
||||||
|
(self.paperwidth - 2 * minmarginwidth + self.verticalBorderSpace) / self.totalTabHeight)
|
||||||
|
numTabsHorizontalL = int(
|
||||||
|
(self.paperheight - 2 * minmarginheight + self.horizontalBorderSpace) / self.totalTabWidth)
|
||||||
|
|
||||||
if numTabsVerticalL * numTabsHorizontalL > numTabsVerticalP * numTabsHorizontalP and not fixedMargins:
|
if numTabsVerticalL * numTabsHorizontalL > numTabsVerticalP * numTabsHorizontalP and not fixedMargins:
|
||||||
self.numTabsVertical, self.numTabsHorizontal\
|
self.numTabsVertical, self.numTabsHorizontal\
|
||||||
@ -874,8 +910,10 @@ class DominionTabs:
|
|||||||
|
|
||||||
if not fixedMargins:
|
if not fixedMargins:
|
||||||
# dynamically max margins
|
# dynamically max margins
|
||||||
self.horizontalMargin = (self.paperwidth-self.numTabsHorizontal*self.totalTabWidth)/2
|
self.horizontalMargin = (
|
||||||
self.verticalMargin = (self.paperheight-self.numTabsVertical*self.totalTabHeight)/2
|
self.paperwidth - self.numTabsHorizontal * self.totalTabWidth) / 2
|
||||||
|
self.verticalMargin = (
|
||||||
|
self.paperheight - self.numTabsVertical * self.totalTabHeight) / 2
|
||||||
else:
|
else:
|
||||||
self.horizontalMargin = minmarginwidth
|
self.horizontalMargin = minmarginwidth
|
||||||
self.verticalMargin = minmarginheight
|
self.verticalMargin = minmarginheight
|
||||||
@ -895,7 +933,8 @@ class DominionTabs:
|
|||||||
(0, self.tabBaseHeight, 0, 0)]
|
(0, self.tabBaseHeight, 0, 0)]
|
||||||
|
|
||||||
self.expansionTabOutline = [(0, 0, self.tabWidth, 0),
|
self.expansionTabOutline = [(0, 0, self.tabWidth, 0),
|
||||||
(self.tabWidth,0,self.tabWidth,self.tabBaseHeight),
|
(self.tabWidth, 0, self.tabWidth,
|
||||||
|
self.tabBaseHeight),
|
||||||
(self.tabWidth, self.tabBaseHeight,
|
(self.tabWidth, self.tabBaseHeight,
|
||||||
self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight),
|
self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight),
|
||||||
(self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight,
|
(self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight,
|
||||||
@ -910,21 +949,30 @@ class DominionTabs:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
dirn = os.path.join(self.filedir, 'fonts')
|
dirn = os.path.join(self.filedir, 'fonts')
|
||||||
pdfmetrics.registerFont(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-Regular', os.path.join(dirn, 'MinionPro-Regular.ttf')))
|
||||||
|
pdfmetrics.registerFont(
|
||||||
|
TTFont('MinionPro-Bold', os.path.join(dirn, 'MinionPro-Bold.ttf')))
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Regular','OptimusPrincepsSemiBold.ttf'))
|
pdfmetrics.registerFont(
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Bold','OptimusPrinceps.ttf'))
|
TTFont('MinionPro-Regular', 'OptimusPrincepsSemiBold.ttf'))
|
||||||
|
pdfmetrics.registerFont(
|
||||||
|
TTFont('MinionPro-Bold', 'OptimusPrinceps.ttf'))
|
||||||
if options.read_yaml:
|
if options.read_yaml:
|
||||||
cardfile = open(os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), "r")
|
cardfile = open(
|
||||||
|
os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), "r")
|
||||||
cards = yaml.load(cardfile)
|
cards = yaml.load(cardfile)
|
||||||
else:
|
else:
|
||||||
cards = self.read_card_defs(os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
cards = self.read_card_defs(
|
||||||
self.read_card_extras(os.path.join(self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
|
os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
||||||
DominionTabs.language_mapping = yaml.load(open(os.path.join(self.filedir, "card_db", options.language, "mapping.yaml")))
|
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")))
|
||||||
|
|
||||||
baseCards = [card.name for card in cards if card.cardset.lower() == 'base']
|
baseCards = [
|
||||||
|
card.name for card in cards if card.cardset.lower() == 'base']
|
||||||
|
|
||||||
def isBaseExpansionCard(card):
|
def isBaseExpansionCard(card):
|
||||||
return card.cardset.lower() != 'base' and card.name in baseCards
|
return card.cardset.lower() != 'base' and card.name in baseCards
|
||||||
@ -935,9 +983,12 @@ class DominionTabs:
|
|||||||
cards = [card for card in cards if not isBaseExpansionCard(card)]
|
cards = [card for card in cards if not isBaseExpansionCard(card)]
|
||||||
|
|
||||||
if self.options.expansions:
|
if self.options.expansions:
|
||||||
self.options.expansions = [o.lower() for o in self.options.expansions]
|
self.options.expansions = [o.lower()
|
||||||
reverseMapping = {v: k for k, v in DominionTabs.language_mapping.iteritems()}
|
for o in self.options.expansions]
|
||||||
self.options.expansions = [reverseMapping.get(e, e) for e in self.options.expansions]
|
reverseMapping = {
|
||||||
|
v: k for k, v in DominionTabs.language_mapping.iteritems()}
|
||||||
|
self.options.expansions = [
|
||||||
|
reverseMapping.get(e, e) for e in self.options.expansions]
|
||||||
filteredCards = []
|
filteredCards = []
|
||||||
knownExpansions = set()
|
knownExpansions = set()
|
||||||
for c in cards:
|
for c in cards:
|
||||||
@ -959,14 +1010,17 @@ class DominionTabs:
|
|||||||
for c in cards:
|
for c in cards:
|
||||||
if isBaseExpansionCard(c):
|
if isBaseExpansionCard(c):
|
||||||
continue
|
continue
|
||||||
cardnamesByExpansion.setdefault(c.cardset, []).append(c.name.strip())
|
cardnamesByExpansion.setdefault(
|
||||||
|
c.cardset, []).append(c.name.strip())
|
||||||
for exp, names in cardnamesByExpansion.iteritems():
|
for exp, names in cardnamesByExpansion.iteritems():
|
||||||
c = Card(exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
c = Card(
|
||||||
|
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
||||||
cards.append(c)
|
cards.append(c)
|
||||||
|
|
||||||
if options.write_yaml:
|
if options.write_yaml:
|
||||||
out = yaml.dump(cards)
|
out = yaml.dump(cards)
|
||||||
open(os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), 'w').write(out)
|
open(os.path.join(
|
||||||
|
self.filedir, "card_db", options.language, "cards.yaml"), 'w').write(out)
|
||||||
|
|
||||||
# When sorting cards, want to always put "base" cards after all
|
# When sorting cards, want to always put "base" cards after all
|
||||||
# kingdom cards, and order the base cards in a set order - the
|
# kingdom cards, and order the base cards in a set order - the
|
||||||
@ -980,14 +1034,17 @@ class DominionTabs:
|
|||||||
return -1
|
return -1
|
||||||
|
|
||||||
if options.order == "global":
|
if options.order == "global":
|
||||||
sortKey = lambda x: (int(x.isExpansion()), baseIndex(x.name), x.name)
|
sortKey = lambda x: (
|
||||||
|
int(x.isExpansion()), baseIndex(x.name), x.name)
|
||||||
else:
|
else:
|
||||||
sortKey = lambda x: (x.cardset, int(x.isExpansion()), baseIndex(x.name), x.name)
|
sortKey = lambda x: (
|
||||||
|
x.cardset, int(x.isExpansion()), baseIndex(x.name), x.name)
|
||||||
cards.sort(key=sortKey)
|
cards.sort(key=sortKey)
|
||||||
|
|
||||||
if not f:
|
if not f:
|
||||||
f = "dominion_tabs.pdf"
|
f = "dominion_tabs.pdf"
|
||||||
self.canvas = canvas.Canvas(f, pagesize=(self.paperwidth, self.paperheight))
|
self.canvas = canvas.Canvas(
|
||||||
|
f, pagesize=(self.paperwidth, self.paperheight))
|
||||||
self.drawDividers(cards)
|
self.drawDividers(cards)
|
||||||
self.canvas.save()
|
self.canvas.save()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user