Throw out yaml as the python yaml library is badly documented and out of date; use JSON everywhere instead
This commit is contained in:
parent
fe47f51bab
commit
1b96a9ceb8
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ generated
|
|||||||
dominiontabs.egg-info
|
dominiontabs.egg-info
|
||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
|
*~
|
||||||
|
|||||||
0
card_db/en_us/cards.json
Normal file
0
card_db/en_us/cards.json
Normal file
File diff suppressed because it is too large
Load Diff
17
card_db/en_us/mapping.json
Normal file
17
card_db/en_us/mapping.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"Action": "Action",
|
||||||
|
"Victory": "Victory",
|
||||||
|
"Attack": "Attack",
|
||||||
|
"Treasure": "Treasure",
|
||||||
|
"Reaction": "Reaction",
|
||||||
|
"Duration": "Duration",
|
||||||
|
"Prize": "Prize",
|
||||||
|
"Shelter": "Shelter",
|
||||||
|
"Ruins": "Ruins",
|
||||||
|
"Looter": "Looter",
|
||||||
|
"Curse": "Curse",
|
||||||
|
"Blank": "Blank",
|
||||||
|
"Reserve": "Reserve",
|
||||||
|
"Traveller": "Traveller",
|
||||||
|
"Event": "Event"
|
||||||
|
}
|
||||||
@ -1,15 +0,0 @@
|
|||||||
"Action": "Action"
|
|
||||||
"Victory": "Victory"
|
|
||||||
"Attack": "Attack"
|
|
||||||
"Treasure": "Treasure"
|
|
||||||
"Reaction": "Reaction"
|
|
||||||
"Duration": "Duration"
|
|
||||||
"Prize": "Prize"
|
|
||||||
"Shelter": "Shelter"
|
|
||||||
"Ruins": "Ruins"
|
|
||||||
"Looter": "Looter"
|
|
||||||
"Curse": "Curse"
|
|
||||||
"Blank": "Blank"
|
|
||||||
"Reserve": "Reserve"
|
|
||||||
"Traveller": "Traveller"
|
|
||||||
"Event": "Event"
|
|
||||||
2619
card_db/it/cards.json
Normal file
2619
card_db/it/cards.json
Normal file
File diff suppressed because it is too large
Load Diff
18
card_db/it/mapping.json
Normal file
18
card_db/it/mapping.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"Azione": "Action",
|
||||||
|
"Vittoria": "Victory",
|
||||||
|
"Attacco": "Attack",
|
||||||
|
"Tesoro": "Treasure",
|
||||||
|
"Reazione": "Reaction",
|
||||||
|
"Durata": "Duration",
|
||||||
|
"Premio": "Prize",
|
||||||
|
"Looter": "Looter",
|
||||||
|
"Shelter": "Shelter",
|
||||||
|
"Ruins": "Ruins",
|
||||||
|
"Maledizione": "Curse",
|
||||||
|
"alchimia": "alchemy",
|
||||||
|
"intrigo": "intrigue",
|
||||||
|
"nuovi orizzonti": "hinterlands",
|
||||||
|
"prosperità": "prosperity"
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
"Azione": "Action"
|
|
||||||
"Vittoria": "Victory"
|
|
||||||
"Attacco": "Attack"
|
|
||||||
"Tesoro": "Treasure"
|
|
||||||
"Reazione": "Reaction"
|
|
||||||
"Durata": "Duration"
|
|
||||||
"Premio": "Prize"
|
|
||||||
"Looter": "Looter"
|
|
||||||
"Shelter": "Shelter"
|
|
||||||
"Ruins": "Ruins"
|
|
||||||
"Maledizione": "Curse"
|
|
||||||
"alchimia": "alchemy"
|
|
||||||
"intrigo": "intrigue"
|
|
||||||
"nuovi orizzonti": "hinterlands"
|
|
||||||
"prosperità": "prosperity"
|
|
||||||
@ -3,6 +3,8 @@ import csv
|
|||||||
import re
|
import re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import os.path
|
import os.path
|
||||||
|
import json
|
||||||
|
import codecs
|
||||||
|
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
from reportlab.lib.pagesizes import LETTER, A4
|
from reportlab.lib.pagesizes import LETTER, A4
|
||||||
@ -13,8 +15,6 @@ from reportlab.pdfbase.ttfonts import TTFont
|
|||||||
from reportlab.pdfbase import pdfmetrics
|
from reportlab.pdfbase import pdfmetrics
|
||||||
from reportlab.lib.enums import TA_JUSTIFY
|
from reportlab.lib.enums import TA_JUSTIFY
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
|
||||||
def split(l, n):
|
def split(l, n):
|
||||||
i = 0
|
i = 0
|
||||||
@ -24,16 +24,26 @@ def split(l, n):
|
|||||||
yield l[i:]
|
yield l[i:]
|
||||||
|
|
||||||
|
|
||||||
class Card:
|
class Card(object):
|
||||||
|
|
||||||
def __init__(self, name, cardset, types, cost, description='', potcost=0):
|
class CardJSONEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, Card):
|
||||||
|
return obj.__dict__
|
||||||
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def decode_json(obj):
|
||||||
|
return Card(**obj)
|
||||||
|
|
||||||
|
def __init__(self, name, cardset, types, cost, description='', potcost=0, extra=''):
|
||||||
self.name = name.strip()
|
self.name = name.strip()
|
||||||
self.cardset = cardset.strip()
|
self.cardset = cardset.strip()
|
||||||
self.types = types
|
self.types = types
|
||||||
self.cost = cost
|
self.cost = cost
|
||||||
self.potcost = potcost
|
self.potcost = potcost
|
||||||
self.description = description
|
self.description = description
|
||||||
self.extra = ""
|
self.extra = extra
|
||||||
|
|
||||||
def getType(self):
|
def getType(self):
|
||||||
return DominionTabs.getType(self.types)
|
return DominionTabs.getType(self.types)
|
||||||
@ -83,7 +93,7 @@ class BlankCard(Card):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class CardType:
|
class CardType(object):
|
||||||
|
|
||||||
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
||||||
self.typeNames = typeNames
|
self.typeNames = typeNames
|
||||||
@ -865,10 +875,10 @@ class DominionTabs:
|
|||||||
help="print crop marks on both sides, rather than tab outlines on one")
|
help="print crop marks on both sides, rather than tab outlines on one")
|
||||||
parser.add_option("--linewidth", type="float", default=.1,
|
parser.add_option("--linewidth", type="float", default=.1,
|
||||||
help="width of lines for card outlines/crop marks")
|
help="width of lines for card outlines/crop marks")
|
||||||
parser.add_option("--read_yaml", action="store_true", dest="read_yaml",
|
parser.add_option("--read_json", action="store_true", dest="read_json",
|
||||||
help="read yaml version of card definitions and extras")
|
help="read json version of card definitions and extras")
|
||||||
parser.add_option("--write_yaml", action="store_true", dest="write_yaml",
|
parser.add_option("--write_json", action="store_true", dest="write_json",
|
||||||
help="write yaml version of card definitions and extras")
|
help="write json version of card definitions and extras")
|
||||||
parser.add_option("--tabs-only", action="store_true", dest="tabs_only",
|
parser.add_option("--tabs-only", action="store_true", dest="tabs_only",
|
||||||
help="draw only tabs to be printed on labels, no divider outlines")
|
help="draw only tabs to be printed on labels, no divider outlines")
|
||||||
parser.add_option("--order", type="choice", choices=["expansion", "global"], dest="order",
|
parser.add_option("--order", type="choice", choices=["expansion", "global"], dest="order",
|
||||||
@ -1095,17 +1105,21 @@ class DominionTabs:
|
|||||||
TTFont('MinionPro-Regular', 'OptimusPrincepsSemiBold.ttf'))
|
TTFont('MinionPro-Regular', 'OptimusPrincepsSemiBold.ttf'))
|
||||||
pdfmetrics.registerFont(
|
pdfmetrics.registerFont(
|
||||||
TTFont('MinionPro-Bold', 'OptimusPrinceps.ttf'))
|
TTFont('MinionPro-Bold', 'OptimusPrinceps.ttf'))
|
||||||
if options.read_yaml:
|
if options.read_json:
|
||||||
cardfile = open(
|
print 'reading JSON'
|
||||||
os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), "r")
|
cardfile = codecs.open(
|
||||||
cards = yaml.load(cardfile)
|
os.path.join(self.filedir, "card_db", options.language, "cards.json"), "r", "utf-8")
|
||||||
|
cards = json.load(cardfile, object_hook=Card.decode_json)
|
||||||
|
print 'read {} cards'.format(len(cards))
|
||||||
else:
|
else:
|
||||||
cards = self.read_card_defs(
|
cards = self.read_card_defs(
|
||||||
os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
||||||
self.read_card_extras(os.path.join(
|
self.read_card_extras(os.path.join(
|
||||||
self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
|
self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
|
||||||
DominionTabs.language_mapping = yaml.load(
|
DominionTabs.language_mapping = json.load(
|
||||||
open(os.path.join(self.filedir, "card_db", options.language, "mapping.yaml")))
|
codecs.open(os.path.join(self.filedir, "card_db", options.language, "mapping.json"),
|
||||||
|
"r",
|
||||||
|
"utf-8"))
|
||||||
|
|
||||||
baseCards = [
|
baseCards = [
|
||||||
card.name for card in cards if card.cardset.lower() == 'base']
|
card.name for card in cards if card.cardset.lower() == 'base']
|
||||||
@ -1178,10 +1192,15 @@ class DominionTabs:
|
|||||||
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
||||||
cards.append(c)
|
cards.append(c)
|
||||||
|
|
||||||
if options.write_yaml:
|
if options.write_json:
|
||||||
out = yaml.dump(cards)
|
fpath = os.path.join(self.filedir, "card_db", options.language, "cards.json")
|
||||||
open(os.path.join(
|
with codecs.open(fpath, 'w', encoding='utf-8') as ofile:
|
||||||
self.filedir, "card_db", options.language, "cards.yaml"), 'w').write(out)
|
json.dump(cards,
|
||||||
|
ofile,
|
||||||
|
cls=Card.CardJSONEncoder,
|
||||||
|
ensure_ascii=False,
|
||||||
|
indent=True,
|
||||||
|
sort_keys=True)
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
3
setup.py
3
setup.py
@ -11,8 +11,7 @@ setup(
|
|||||||
scripts=["dominion_tabs.py"],
|
scripts=["dominion_tabs.py"],
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=["reportlab>=2.5",
|
install_requires=["reportlab>=2.5",
|
||||||
"Pillow>=2.1.0",
|
"Pillow>=2.1.0"],
|
||||||
"PyYAML"],
|
|
||||||
package_data={
|
package_data={
|
||||||
'': ['*.txt', '*.png']
|
'': ['*.txt', '*.png']
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user