Compare commits
No commits in common. "9d8f3bc90e7f58e53c1e47b615f4ca8928a11945" and "ee5f26590dc77cd252fa0ceb00d88b4665e2a9bf" have entirely different histories.
9d8f3bc90e
...
ee5f26590d
4 changed files with 5 additions and 44 deletions
10
decode.py
10
decode.py
|
@ -13,7 +13,7 @@ from cbow import CBOW
|
||||||
from namediff import Namediff
|
from namediff import Namediff
|
||||||
|
|
||||||
def main(fname, oname = None, verbose = True, encoding = 'std',
|
def main(fname, oname = None, verbose = True, encoding = 'std',
|
||||||
gatherer = False, for_forum = False, for_mse = False, for_json = False,
|
gatherer = False, for_forum = False, for_mse = False,
|
||||||
creativity = False, vdump = False, for_html = False):
|
creativity = False, vdump = False, for_html = False):
|
||||||
|
|
||||||
# there is a sane thing to do here (namely, produce both at the same time)
|
# there is a sane thing to do here (namely, produce both at the same time)
|
||||||
|
@ -104,9 +104,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std',
|
||||||
|
|
||||||
|
|
||||||
for card in cards:
|
for card in cards:
|
||||||
if for_json:
|
if for_mse:
|
||||||
writer.write(card.to_json())
|
|
||||||
elif for_mse:
|
|
||||||
writer.write(card.to_mse().encode('utf-8'))
|
writer.write(card.to_mse().encode('utf-8'))
|
||||||
fstring = ''
|
fstring = ''
|
||||||
if card.json:
|
if card.json:
|
||||||
|
@ -292,14 +290,12 @@ if __name__ == '__main__':
|
||||||
help='verbose output')
|
help='verbose output')
|
||||||
parser.add_argument('-mse', '--mse', action='store_true',
|
parser.add_argument('-mse', '--mse', action='store_true',
|
||||||
help='use Magic Set Editor 2 encoding; will output as .mse-set file')
|
help='use Magic Set Editor 2 encoding; will output as .mse-set file')
|
||||||
parser.add_argument('-j', '--json', action='store_true',
|
|
||||||
help='use JSON encoding; will output as .json file')
|
|
||||||
parser.add_argument('-html', '--html', action='store_true', help='create a .html file with pretty forum formatting')
|
parser.add_argument('-html', '--html', action='store_true', help='create a .html file with pretty forum formatting')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
main(args.infile, args.outfile, verbose = args.verbose, encoding = args.encoding,
|
main(args.infile, args.outfile, verbose = args.verbose, encoding = args.encoding,
|
||||||
gatherer = args.gatherer, for_forum = args.forum, for_mse = args.mse, for_json = args.json,
|
gatherer = args.gatherer, for_forum = args.forum, for_mse = args.mse,
|
||||||
creativity = args.creativity, vdump = args.dump, for_html = args.html)
|
creativity = args.creativity, vdump = args.dump, for_html = args.html)
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
@ -63,7 +63,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std',
|
||||||
# This should give a random but consistent ordering, to make comparing changes
|
# This should give a random but consistent ordering, to make comparing changes
|
||||||
# between the output of different versions easier.
|
# between the output of different versions easier.
|
||||||
if not stable:
|
if not stable:
|
||||||
random.seed(a=None)
|
random.seed(1371367)
|
||||||
random.shuffle(cards)
|
random.shuffle(cards)
|
||||||
|
|
||||||
def writecards(writer):
|
def writecards(writer):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# card representation
|
# card representation
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
import json
|
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
import transforms
|
import transforms
|
||||||
|
@ -392,15 +391,6 @@ def fields_from_format(src_text, fmt_ordered, fmt_labeled, fieldsep):
|
||||||
# again, bsides are handled by the constructor
|
# again, bsides are handled by the constructor
|
||||||
return parsed, valid and fields_check_valid(fields), fields
|
return parsed, valid and fields_check_valid(fields), fields
|
||||||
|
|
||||||
class CardEncoder(json.JSONEncoder):
|
|
||||||
def default(self, obj):
|
|
||||||
if isinstance(obj, Manatext):
|
|
||||||
return obj.format()
|
|
||||||
if isinstance(obj, Manacost):
|
|
||||||
return obj.format()
|
|
||||||
# Let the base class default method raise the TypeError
|
|
||||||
return json.JSONEncoder.default(self, obj)
|
|
||||||
|
|
||||||
# Here's the actual Card class that other files should use.
|
# Here's the actual Card class that other files should use.
|
||||||
|
|
||||||
class Card:
|
class Card:
|
||||||
|
@ -575,31 +565,6 @@ class Card:
|
||||||
for idx, value in values:
|
for idx, value in values:
|
||||||
self.__dict__[field_other] += [(idx, value)]
|
self.__dict__[field_other] += [(idx, value)]
|
||||||
|
|
||||||
def to_json(self):
|
|
||||||
fields = {}
|
|
||||||
for key in self.fields:
|
|
||||||
fields[key] = self.fields[key][0][1]
|
|
||||||
fields["name"] = titlecase(transforms.name_unpass_1_dashes(self.__dict__[field_name]))
|
|
||||||
mtext = self.__dict__[field_text].text
|
|
||||||
mtext = transforms.text_unpass_1_choice(mtext, delimit = False)
|
|
||||||
mtext = transforms.text_unpass_2_counters(mtext)
|
|
||||||
mtext = transforms.text_unpass_3_uncast(mtext)
|
|
||||||
mtext = transforms.text_unpass_4_unary(mtext)
|
|
||||||
mtext = transforms.text_unpass_5_symbols(mtext, False, False)
|
|
||||||
mtext = sentencecase(mtext)
|
|
||||||
#mtext = transforms.text_unpass_6_cardname(mtext, fields["name"])
|
|
||||||
mtext = transforms.text_unpass_7_newlines(mtext)
|
|
||||||
mtext = transforms.text_unpass_8_unicode(mtext)
|
|
||||||
newtext = Manatext('')
|
|
||||||
newtext.text = mtext
|
|
||||||
newtext.costs = self.__dict__[field_text].costs
|
|
||||||
fields["text"] = newtext.format(for_forum = False, for_html = False)
|
|
||||||
if self.__dict__[field_pt]:
|
|
||||||
fields["pt"] = utils.from_unary(self.__dict__[field_pt])
|
|
||||||
if self.__dict__[field_loyalty]:
|
|
||||||
fields["loyalty"] = utils.from_unary(self.__dict__[field_loyalty])
|
|
||||||
return json.dumps(fields, cls=CardEncoder)
|
|
||||||
|
|
||||||
# Output functions that produce various formats. encode() is specific to
|
# Output functions that produce various formats. encode() is specific to
|
||||||
# the NN representation, use str() or format() for output intended for human
|
# the NN representation, use str() or format() for output intended for human
|
||||||
# readers.
|
# readers.
|
||||||
|
|
|
@ -68,7 +68,7 @@ def mtg_open_json(fname, verbose = False):
|
||||||
|
|
||||||
# filters to ignore some undesirable cards, only used when opening json
|
# filters to ignore some undesirable cards, only used when opening json
|
||||||
def default_exclude_sets(cardset):
|
def default_exclude_sets(cardset):
|
||||||
return cardset == 'Unglued' or cardset == 'Unhinged' or cardset == "Unstable" or cardset == "HasCon 2017" or cardset == 'Celebration'
|
return cardset == 'Unglued' or cardset == 'Unhinged' or cardset == 'Celebration'
|
||||||
|
|
||||||
def default_exclude_types(cardtype):
|
def default_exclude_types(cardtype):
|
||||||
return cardtype in ['conspiracy']
|
return cardtype in ['conspiracy']
|
||||||
|
|
Loading…
Reference in a new issue