Add generic label and blank tabs support (#224)
* Add generic label support * add support for blank tabs
This commit is contained in:
parent
bd15b3eb68
commit
0f0587ea32
63
domdiv/card_db/labels_db.json
Normal file
63
domdiv/card_db/labels_db.json
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
[{
|
||||||
|
"gap-horizontal": 0.76,
|
||||||
|
"gap-vertical": 0.0,
|
||||||
|
"height": 1.27,
|
||||||
|
"margin-left": 0.75,
|
||||||
|
"margin-top": 1.27,
|
||||||
|
"names": [
|
||||||
|
"5167",
|
||||||
|
"5267",
|
||||||
|
"5667",
|
||||||
|
"5967",
|
||||||
|
"8167",
|
||||||
|
"8667",
|
||||||
|
"8867",
|
||||||
|
"8927",
|
||||||
|
"15267",
|
||||||
|
"15667",
|
||||||
|
"18167",
|
||||||
|
"18667",
|
||||||
|
"28667",
|
||||||
|
"48267",
|
||||||
|
"48467",
|
||||||
|
"48867",
|
||||||
|
"95667"
|
||||||
|
],
|
||||||
|
"pad-horizontal": 0.1,
|
||||||
|
"pad-vertical": 0.1,
|
||||||
|
"paper": "LETTER",
|
||||||
|
"tab-only": true,
|
||||||
|
"width": 4.45
|
||||||
|
},{
|
||||||
|
"gap-horizontal": 0.116,
|
||||||
|
"gap-vertical": 0.0,
|
||||||
|
"height": 1.69,
|
||||||
|
"margin-left": 1.02,
|
||||||
|
"margin-top": 1.08,
|
||||||
|
"names": [
|
||||||
|
"L4732",
|
||||||
|
"L7632"
|
||||||
|
],
|
||||||
|
"pad-horizontal": 0.1,
|
||||||
|
"pad-vertical": 0.1,
|
||||||
|
"paper": "A4",
|
||||||
|
"tab-only": true,
|
||||||
|
"width": 3.56
|
||||||
|
},{
|
||||||
|
"body-height": 1.055,
|
||||||
|
"gap-horizontal": 0.295,
|
||||||
|
"gap-vertical": 0.0,
|
||||||
|
"height": 1.06,
|
||||||
|
"margin-left": 0.95,
|
||||||
|
"margin-top": 2.15,
|
||||||
|
"names": [
|
||||||
|
"L4736",
|
||||||
|
"L6113"
|
||||||
|
],
|
||||||
|
"pad-horizontal": 0.1,
|
||||||
|
"pad-vertical": 0.1,
|
||||||
|
"paper": "A4",
|
||||||
|
"tab-only": false,
|
||||||
|
"width": 4.53
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -614,6 +614,10 @@ class DividerDrawer(object):
|
|||||||
return w
|
return w
|
||||||
|
|
||||||
def drawTab(self, card, rightSide, wrapper="no"):
|
def drawTab(self, card, rightSide, wrapper="no"):
|
||||||
|
# Skip blank cards
|
||||||
|
if card.isBlank():
|
||||||
|
return
|
||||||
|
|
||||||
# draw tab flap
|
# draw tab flap
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
if self.wantCentreTab(card):
|
if self.wantCentreTab(card):
|
||||||
@ -822,6 +826,9 @@ class DividerDrawer(object):
|
|||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
def drawText(self, card, divider_text="card", wrapper="no"):
|
def drawText(self, card, divider_text="card", wrapper="no"):
|
||||||
|
# Skip blank cards
|
||||||
|
if card.isBlank():
|
||||||
|
return
|
||||||
|
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
usedHeight = 0
|
usedHeight = 0
|
||||||
|
|||||||
@ -24,6 +24,7 @@ TAB_SIDE_CHOICES = ["left", "right", "left-alternate", "right-alternate",
|
|||||||
"centre", "full"]
|
"centre", "full"]
|
||||||
TEXT_CHOICES = ["card", "rules", "blank"]
|
TEXT_CHOICES = ["card", "rules", "blank"]
|
||||||
EDITION_CHOICES = ["1", "2", "latest", "all"]
|
EDITION_CHOICES = ["1", "2", "latest", "all"]
|
||||||
|
LABEL_CHOICES = ["8867", "L4732", "L4736"]
|
||||||
|
|
||||||
EXPANSION_CHOICES = ["adventures", "alchemy", "base", "cornucopia", "dark ages",
|
EXPANSION_CHOICES = ["adventures", "alchemy", "base", "cornucopia", "dark ages",
|
||||||
"dominion1stEdition", "dominion2ndEdition", "dominion2ndEditionUpgrade",
|
"dominion1stEdition", "dominion2ndEdition", "dominion2ndEditionUpgrade",
|
||||||
@ -312,8 +313,9 @@ def parse_opts(cmdline_args=None):
|
|||||||
help="Include four start decks with the Base cards.")
|
help="Include four start decks with the Base cards.")
|
||||||
group_select.add_argument(
|
group_select.add_argument(
|
||||||
"--include-blanks",
|
"--include-blanks",
|
||||||
action="store_true",
|
type=int,
|
||||||
help="Include a few dividers with extra text.")
|
default=0,
|
||||||
|
help="Number of blank dividers to include.")
|
||||||
group_select.add_argument(
|
group_select.add_argument(
|
||||||
"--exclude-events",
|
"--exclude-events",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@ -425,6 +427,12 @@ def parse_opts(cmdline_args=None):
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="In tabs-only mode, draw tabs on black background"
|
help="In tabs-only mode, draw tabs on black background"
|
||||||
)
|
)
|
||||||
|
group_printing.add_argument(
|
||||||
|
"--label",
|
||||||
|
dest="label_name",
|
||||||
|
default=None,
|
||||||
|
help="Use preset label dimentions. Specify a label name. "
|
||||||
|
"This will override settings that conflict with the preset label settings.")
|
||||||
group_printing.add_argument(
|
group_printing.add_argument(
|
||||||
"--info",
|
"--info",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@ -498,6 +506,47 @@ def clean_opts(options):
|
|||||||
# keyword to indicate no options. Same as --fan without any expansions given
|
# keyword to indicate no options. Same as --fan without any expansions given
|
||||||
options.fan = []
|
options.fan = []
|
||||||
|
|
||||||
|
if options.tabs_only and options.label_name is None:
|
||||||
|
# default is Avery 8867
|
||||||
|
options.label_name = "8867"
|
||||||
|
|
||||||
|
options.label = None
|
||||||
|
if options.label_name is not None:
|
||||||
|
# Load the Labels, and look for match
|
||||||
|
labels_db_filepath = os.path.join("card_db", "labels_db.json")
|
||||||
|
with get_resource_stream(labels_db_filepath) as labelfile:
|
||||||
|
label_info = json.loads(labelfile.read().decode('utf-8'))
|
||||||
|
assert label_info, "Could not load label information from database"
|
||||||
|
for label in label_info:
|
||||||
|
if options.label_name.upper() in [n.upper() for n in label['names']]:
|
||||||
|
options.label = label
|
||||||
|
break
|
||||||
|
|
||||||
|
assert options.label is not None, "Label '{}' not defined".format(options.label_name)
|
||||||
|
|
||||||
|
# Defaults for missing values
|
||||||
|
label = options.label
|
||||||
|
label['paper'] = label['paper'] if 'paper' in label else "LETTER"
|
||||||
|
label['tab-only'] = label['tab-only'] if 'tab-only' in label else True
|
||||||
|
label['body-height'] = label['body-height'] if 'body-height' in label else 0
|
||||||
|
label['gap-vertical'] = label['gap-vertical'] if 'gap-vertical' in label else 0.0
|
||||||
|
label['gap-horizontal'] = label['gap-horizontal'] if 'gap-horizontal' in label else 0.0
|
||||||
|
label['pad-vertical'] = label['pad-vertical'] if 'pad-vertical' in label else 0.1
|
||||||
|
label['pad-horizontal'] = label['pad-horizontal'] if 'pad-horizontal' in label else 0.1
|
||||||
|
|
||||||
|
# Option Overrides when using labels
|
||||||
|
options.linewidth = 0.0
|
||||||
|
options.papersize = label['paper']
|
||||||
|
if label['tab-only']:
|
||||||
|
options.tabs_only = True
|
||||||
|
if label['body-height'] < 4.0:
|
||||||
|
options.text_front = "blank"
|
||||||
|
options.text_back = "blank"
|
||||||
|
if label['body-height'] < 1.0:
|
||||||
|
options.count = False
|
||||||
|
options.types = False
|
||||||
|
options.label = label
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
@ -648,6 +697,17 @@ def read_card_data(options):
|
|||||||
# Add the new dividers
|
# Add the new dividers
|
||||||
cards.extend(new_cards)
|
cards.extend(new_cards)
|
||||||
|
|
||||||
|
# Add any blank cards
|
||||||
|
if options.include_blanks > 0:
|
||||||
|
for x in range(0, options.include_blanks):
|
||||||
|
c = Card(card_tag=u'Blank',
|
||||||
|
cardset='extras',
|
||||||
|
cardset_tag='extras',
|
||||||
|
cardset_tags=['extras'],
|
||||||
|
randomizer=False,
|
||||||
|
types=("Blank", ))
|
||||||
|
cards.append(c)
|
||||||
|
|
||||||
# Create Start Deck dividers. 4 sets. Adjust totals for other cards, too.
|
# Create Start Deck dividers. 4 sets. Adjust totals for other cards, too.
|
||||||
# Do early before propagating to various sets.
|
# Do early before propagating to various sets.
|
||||||
# The card database contains one prototype divider that needs to be either duplicated or deleted.
|
# The card database contains one prototype divider that needs to be either duplicated or deleted.
|
||||||
@ -922,6 +982,11 @@ def filter_sort_cards(cards, options):
|
|||||||
if options.expansions:
|
if options.expansions:
|
||||||
options.expansions.append("extras")
|
options.expansions.append("extras")
|
||||||
|
|
||||||
|
# Take care of any blank cards
|
||||||
|
if options.include_blanks > 0:
|
||||||
|
if options.expansions:
|
||||||
|
options.expansions.append("extras")
|
||||||
|
|
||||||
# FIX THIS: Combine all Prizes across all expansions
|
# FIX THIS: Combine all Prizes across all expansions
|
||||||
# if options.exclude_prizes:
|
# if options.exclude_prizes:
|
||||||
# cards = combine_cards(cards, 'Prize', 'prizes')
|
# cards = combine_cards(cards, 'Prize', 'prizes')
|
||||||
@ -1104,7 +1169,7 @@ def filter_sort_cards(cards, options):
|
|||||||
cardnamesByExpansion = defaultdict(dict)
|
cardnamesByExpansion = defaultdict(dict)
|
||||||
randomizerCountByExpansion = Counter()
|
randomizerCountByExpansion = Counter()
|
||||||
for c in cards:
|
for c in cards:
|
||||||
if cardSorter.isBaseExpansionCard(c):
|
if cardSorter.isBaseExpansionCard(c) or c.isBlank():
|
||||||
continue
|
continue
|
||||||
if c.randomizer:
|
if c.randomizer:
|
||||||
randomizerCountByExpansion[c.cardset] += 1
|
randomizerCountByExpansion[c.cardset] += 1
|
||||||
@ -1184,15 +1249,19 @@ def calculate_layout(options, cards=[]):
|
|||||||
options.tab_name_align = "left"
|
options.tab_name_align = "left"
|
||||||
|
|
||||||
fixedMargins = False
|
fixedMargins = False
|
||||||
if options.tabs_only:
|
options.label = options.label if 'label' in options else None
|
||||||
# fixed for Avery 8867 for now
|
if options.label is not None:
|
||||||
minmarginwidth = 0.86 * cm # was 0.76
|
# Set Margins
|
||||||
minmarginheight = 1.37 * cm # was 1.27
|
minmarginheight = (options.label['margin-top'] + options.label['pad-vertical']) * cm
|
||||||
labelHeight = 1.07 * cm # was 1.27
|
minmarginwidth = (options.label['margin-left'] + options.label['pad-horizontal']) * cm
|
||||||
labelWidth = 4.24 * cm # was 4.44
|
# Set Label size
|
||||||
horizontalBorderSpace = 0.96 * cm # was 0.76
|
labelHeight = (options.label['height'] - 2 * options.label['pad-vertical']) * cm
|
||||||
verticalBorderSpace = 0.20 * cm # was 0.01
|
labelWidth = (options.label['width'] - 2 * options.label['pad-horizontal']) * cm
|
||||||
dividerBaseHeight = 0
|
# Set spacing between labels
|
||||||
|
verticalBorderSpace = (options.label['gap-vertical'] + 2 * options.label['pad-vertical']) * cm
|
||||||
|
horizontalBorderSpace = (options.label['gap-horizontal'] + 2 * options.label['pad-horizontal']) * cm
|
||||||
|
# Fix up other settings
|
||||||
|
dividerBaseHeight = options.label['body-height'] * cm
|
||||||
dividerWidth = labelWidth
|
dividerWidth = labelWidth
|
||||||
fixedMargins = True
|
fixedMargins = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -61,11 +61,16 @@ def test_cardread():
|
|||||||
assert c.cardset_tag in valid_cardsets
|
assert c.cardset_tag in valid_cardsets
|
||||||
|
|
||||||
# Option modified card count
|
# Option modified card count
|
||||||
options = main.parse_opts(['--no-trash', '--curse10', '--start-decks'])
|
options = main.parse_opts(['--no-trash', '--curse10', '--start-decks', '--include-blanks', '7'])
|
||||||
|
options = main.clean_opts(options)
|
||||||
options.data_path = '.'
|
options.data_path = '.'
|
||||||
cards = main.read_card_data(options)
|
cards = main.read_card_data(options)
|
||||||
# Total delta cards is +21 from Trash: -1 * 3 sets = -3; Curse: +2 * 4 sets =+8; Start Decks: +4 * 4 sets = +16
|
# Total delta cards is +28 from
|
||||||
assert len(cards) == cardsExpected + 21
|
# Trash: -1 * 3 sets = -3
|
||||||
|
# Curse: +2 * 4 sets = +8
|
||||||
|
# Start Decks: +4 * 4 sets = +16
|
||||||
|
# Blanks: +7 = +7
|
||||||
|
assert len(cards) == cardsExpected + 28
|
||||||
|
|
||||||
|
|
||||||
def test_languages():
|
def test_languages():
|
||||||
|
|||||||
@ -124,6 +124,32 @@ def main(args):
|
|||||||
print(type_parts)
|
print(type_parts)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
# Get the labels_db information
|
||||||
|
# Store in a list in the order found.
|
||||||
|
###########################################################################
|
||||||
|
all_labels = []
|
||||||
|
|
||||||
|
# Get the card data
|
||||||
|
label_data = get_json_data(os.path.join(args.card_db_dir, "labels_db.json"))
|
||||||
|
|
||||||
|
with io.open(
|
||||||
|
os.path.join(args.output_dir, "labels_db.json"), 'w',
|
||||||
|
encoding='utf-8') as lang_out:
|
||||||
|
lang_out.write(six.u("[")) # Start of list
|
||||||
|
sep = ""
|
||||||
|
for label in label_data:
|
||||||
|
# Collect all the individual types
|
||||||
|
all_labels = list(set(label['names']) | set(all_labels))
|
||||||
|
lang_out.write(sep + json.dumps(
|
||||||
|
label, indent=4, ensure_ascii=False, sort_keys=True))
|
||||||
|
sep = ","
|
||||||
|
lang_out.write(six.u("\n]\n")) # End of List
|
||||||
|
|
||||||
|
all_labels.sort()
|
||||||
|
print("Labels: ")
|
||||||
|
print(all_labels)
|
||||||
|
print()
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Fix up all the xx/types_xx.json files
|
# Fix up all the xx/types_xx.json files
|
||||||
# Place entries in alphabetical order
|
# Place entries in alphabetical order
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user