made decoding better
This commit is contained in:
parent
c5231ac947
commit
08dc3944f8
3 changed files with 79 additions and 45 deletions
|
@ -366,22 +366,36 @@ class Card:
|
||||||
# all be -1 if the card was parsed from (unordered) json.
|
# all be -1 if the card was parsed from (unordered) json.
|
||||||
|
|
||||||
def set_field_default(self, field, values):
|
def set_field_default(self, field, values):
|
||||||
|
first = True
|
||||||
for idx, value in values:
|
for idx, value in values:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
self.__dict__[field] = value
|
self.__dict__[field] = value
|
||||||
break # only use the first one...
|
else:
|
||||||
|
# stick it in other so we'll be know about it when we format the card
|
||||||
|
self.valid = False
|
||||||
|
self.__dict__[field_other] += [(idx, '<' + field + '> ' + str(value))]
|
||||||
|
|
||||||
def _set_loyalty(self, values):
|
def _set_loyalty(self, values):
|
||||||
|
first = True
|
||||||
for idx, value in values:
|
for idx, value in values:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
self.__dict__[field_loyalty] = value
|
self.__dict__[field_loyalty] = value
|
||||||
try:
|
try:
|
||||||
self.__dict__[field_loyalty + '_value'] = int(value)
|
self.__dict__[field_loyalty + '_value'] = int(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.__dict__[field_loyalty + '_value'] = None
|
self.__dict__[field_loyalty + '_value'] = None
|
||||||
# Technically '*' could still be valid, but it's unlikely...
|
# Technically '*' could still be valid, but it's unlikely...
|
||||||
break # only use the first one...
|
else:
|
||||||
|
self.valid = False
|
||||||
|
self.__dict__[field_other] += [(idx, '<loyalty> ' + str(value))]
|
||||||
|
|
||||||
def _set_pt(self, values):
|
def _set_pt(self, values):
|
||||||
|
first = True
|
||||||
for idx, value in values:
|
for idx, value in values:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
self.__dict__[field_pt] = value
|
self.__dict__[field_pt] = value
|
||||||
p_t = value.split('/') # hardcoded
|
p_t = value.split('/') # hardcoded
|
||||||
if len(p_t) == 2:
|
if len(p_t) == 2:
|
||||||
|
@ -397,19 +411,27 @@ class Card:
|
||||||
self.__dict__[field_pt + '_t_value'] = None
|
self.__dict__[field_pt + '_t_value'] = None
|
||||||
else:
|
else:
|
||||||
self.valid = False
|
self.valid = False
|
||||||
break # only use the first one...
|
else:
|
||||||
|
self.valid = False
|
||||||
|
self.__dict__[field_other] += [(idx, '<pt> ' + str(value))]
|
||||||
|
|
||||||
def _set_text(self, values):
|
def _set_text(self, values):
|
||||||
|
first = True
|
||||||
for idx, value in values:
|
for idx, value in values:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
mtext = value
|
mtext = value
|
||||||
self.__dict__[field_text] = mtext
|
self.__dict__[field_text] = mtext
|
||||||
fulltext = mtext.encode()
|
fulltext = mtext.encode()
|
||||||
if fulltext:
|
if fulltext:
|
||||||
self.__dict__[field_text + '_lines'] = map(Manatext, fulltext.split(utils.newline))
|
self.__dict__[field_text + '_lines'] = map(Manatext,
|
||||||
|
fulltext.split(utils.newline))
|
||||||
self.__dict__[field_text + '_words'] = re.sub(utils.unletters_regex,
|
self.__dict__[field_text + '_words'] = re.sub(utils.unletters_regex,
|
||||||
' ',
|
' ',
|
||||||
fulltext).split()
|
fulltext).split()
|
||||||
break # only use the first one...
|
else:
|
||||||
|
self.valid = False
|
||||||
|
self.__dict__[field_other] += [(idx, '<text> ' + str(value))]
|
||||||
|
|
||||||
def _set_other(self, values):
|
def _set_other(self, values):
|
||||||
# just record these, we could do somthing unset valid if we really wanted
|
# just record these, we could do somthing unset valid if we really wanted
|
||||||
|
@ -474,6 +496,8 @@ class Card:
|
||||||
outstr = ''
|
outstr = ''
|
||||||
if gatherer:
|
if gatherer:
|
||||||
cardname = self.__dict__[field_name].title()
|
cardname = self.__dict__[field_name].title()
|
||||||
|
if not cardname:
|
||||||
|
cardname = '_NONAME_'
|
||||||
if for_forum:
|
if for_forum:
|
||||||
outstr += '[b]'
|
outstr += '[b]'
|
||||||
outstr += cardname
|
outstr += cardname
|
||||||
|
@ -492,7 +516,12 @@ class Card:
|
||||||
|
|
||||||
outstr += '\n'
|
outstr += '\n'
|
||||||
|
|
||||||
outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title()
|
basetypes = self.__dict__[field_types]
|
||||||
|
if len(basetypes) < 1:
|
||||||
|
basetypes = ['_NOTYPE_']
|
||||||
|
|
||||||
|
outstr += ' '.join(self.__dict__[field_supertypes] + basetypes)
|
||||||
|
|
||||||
if self.__dict__[field_subtypes]:
|
if self.__dict__[field_subtypes]:
|
||||||
outstr += (' ' + utils.dash_marker + ' ' +
|
outstr += (' ' + utils.dash_marker + ' ' +
|
||||||
' '.join(self.__dict__[field_subtypes]).title())
|
' '.join(self.__dict__[field_subtypes]).title())
|
||||||
|
@ -510,8 +539,8 @@ class Card:
|
||||||
mtext = transforms.text_unpass_1_choice(mtext, delimit = False)
|
mtext = transforms.text_unpass_1_choice(mtext, delimit = False)
|
||||||
mtext = transforms.text_unpass_2_counters(mtext)
|
mtext = transforms.text_unpass_2_counters(mtext)
|
||||||
mtext = transforms.text_unpass_3_unary(mtext)
|
mtext = transforms.text_unpass_3_unary(mtext)
|
||||||
mtext = transforms.text_unpass_4_cardname(mtext, cardname)
|
mtext = transforms.text_unpass_4_symbols(mtext, for_forum)
|
||||||
mtext = transforms.text_unpass_5_symbols(mtext, for_forum)
|
mtext = transforms.text_unpass_5_cardname(mtext, cardname)
|
||||||
mtext = transforms.text_unpass_6_newlines(mtext)
|
mtext = transforms.text_unpass_6_newlines(mtext)
|
||||||
newtext = Manatext('')
|
newtext = Manatext('')
|
||||||
newtext.text = mtext
|
newtext.text = mtext
|
||||||
|
@ -558,8 +587,8 @@ class Card:
|
||||||
mtext = transforms.text_unpass_1_choice(mtext, delimit = True)
|
mtext = transforms.text_unpass_1_choice(mtext, delimit = True)
|
||||||
#mtext = transforms.text_unpass_2_counters(mtext)
|
#mtext = transforms.text_unpass_2_counters(mtext)
|
||||||
mtext = transforms.text_unpass_3_unary(mtext)
|
mtext = transforms.text_unpass_3_unary(mtext)
|
||||||
#mtext = transforms.text_unpass_4_cardname(mtext, cardname)
|
mtext = transforms.text_unpass_4_symbols(mtext, for_forum)
|
||||||
mtext = transforms.text_unpass_5_symbols(mtext, for_forum)
|
#mtext = transforms.text_unpass_5_cardname(mtext, cardname)
|
||||||
mtext = transforms.text_unpass_6_newlines(mtext)
|
mtext = transforms.text_unpass_6_newlines(mtext)
|
||||||
newtext = Manatext('')
|
newtext = Manatext('')
|
||||||
newtext.text = mtext
|
newtext.text = mtext
|
||||||
|
|
|
@ -103,10 +103,15 @@ class Manacost:
|
||||||
self.colors = self.get_colors()
|
self.colors = self.get_colors()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if self.none:
|
||||||
|
return '_NOCOST_'
|
||||||
return utils.mana_untranslate(utils.mana_open_delimiter + ''.join(self.sequence)
|
return utils.mana_untranslate(utils.mana_open_delimiter + ''.join(self.sequence)
|
||||||
+ utils.mana_close_delimiter)
|
+ utils.mana_close_delimiter)
|
||||||
|
|
||||||
def format(self, for_forum = False):
|
def format(self, for_forum = False):
|
||||||
|
if self.none:
|
||||||
|
return '_NOCOST_'
|
||||||
|
else:
|
||||||
return utils.mana_untranslate(utils.mana_open_delimiter + ''.join(self.sequence)
|
return utils.mana_untranslate(utils.mana_open_delimiter + ''.join(self.sequence)
|
||||||
+ utils.mana_close_delimiter, for_forum)
|
+ utils.mana_close_delimiter, for_forum)
|
||||||
|
|
||||||
|
|
|
@ -459,13 +459,13 @@ def text_unpass_3_unary(s):
|
||||||
return utils.from_unary(s)
|
return utils.from_unary(s)
|
||||||
|
|
||||||
|
|
||||||
def text_unpass_4_cardname(s, name):
|
def text_unpass_4_symbols(s, for_forum):
|
||||||
return s.replace(this_marker, name)
|
|
||||||
|
|
||||||
|
|
||||||
def text_unpass_5_symbols(s, for_forum):
|
|
||||||
return utils.from_symbols(s, for_forum = for_forum)
|
return utils.from_symbols(s, for_forum = for_forum)
|
||||||
|
|
||||||
|
|
||||||
|
def text_unpass_5_cardname(s, name):
|
||||||
|
return s.replace(this_marker, name)
|
||||||
|
|
||||||
|
|
||||||
def text_unpass_6_newlines(s):
|
def text_unpass_6_newlines(s):
|
||||||
return s.replace(newline, '\n')
|
return s.replace(newline, '\n')
|
||||||
|
|
Loading…
Reference in a new issue