diff --git a/encode.py b/encode.py index cfb7346..16fe354 100644 --- a/encode.py +++ b/encode.py @@ -1,6 +1,7 @@ import jdecode import re import codecs +import sys #badwords = [] @@ -428,7 +429,7 @@ def rename_uncast(s): # print s + '\n' # whew! by manual inspection of a few dozen texts, it looks like this about covers it. - return s + return s # run only after doing unary conversion @@ -467,6 +468,40 @@ def fix_x(s): return s +# run after fixing dashes, it makes the regexes better, but before replacing newlines +def reformat_choice(s): + # the idea is to take 'choose n ~\n=ability\n=ability\n' + # to '[n = ability = ability]\n' + + single_choices = re.findall(r'choose one', s) + + for choice in single_choices: + print choice + print s + # since we have two groups in that regex + newchoice = choice + # newchoice = newchoice.replace('choose one ~', unary_marker + (unary_counter * 1)) + # newchoice = newchoice.replace('\n', ' ') + # # the indexing cuts off the | we know is at the end + # newchoice = '[' + newchoice[:-1] + ']|' + s = s.replace(choice, newchoice) + + double_choices = re.findall(r'choose two ~[^|]*=[^\n|]*\|', s) + + for choice in double_choices: + # since we have two groups in that regex + newchoice = choice + newchoice = newchoice.replace('choose two ~', unary_marker + (unary_counter * 2)) + newchoice = newchoice.replace('\n', ' ') + # the indexing cuts off the | we know is at the end + newchoice = '[' + newchoice[:-1] + ']|' + s = s.replace(choice, newchoice) + + # sys.stdout.write('.') + + return s + + # do before removing newlines # might as well do this after countertype because we probably care more about # the location of the equip cost @@ -525,6 +560,7 @@ def encode(card): text = fix_x(text) text = replace_counters(text) text = rename_uncast(text) + text = reformat_choice(text) text = relocate_equip(text) text = replace_newlines(text) encoding += text