Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions lib/cardlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@
from titlecase import titlecase
except ImportError:
def titlecase(s):
return s.title()
s = s.title()
smallwords = [
"'S",
' A ',
' And ',
' As ',
' At ',
' For ',
' From ',
' In ',
' Of ',
' The ',
' To ',
' With ',
]
for word in smallwords:
s = s.replace(word, word.lower())
return s

try:
import textwrap
Expand Down Expand Up @@ -678,8 +695,9 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html =
outstr += ' '.join(map(str.capitalize, self.__dict__[field_supertypes]) + basetypes)

if self.__dict__[field_subtypes]:
outstr += (' ' + utils.dash_marker + ' ' +
' '.join(self.__dict__[field_subtypes]).title())
outstr += (' ' + utils.dash_marker)
for subtype in self.__dict__[field_subtypes]:
outstr += ' ' + titlecase(subtype)

if self.__dict__[field_pt]:
outstr += ' (' + utils.from_unary(self.__dict__[field_pt]) + ')'
Expand Down Expand Up @@ -737,6 +755,10 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html =
#cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name])
if vdump and not cardname:
cardname = '_NONAME_'
else:
cardname = titlecase(cardname)
if for_forum:
cardname = '[b]' + cardname + '[/b]'
outstr += cardname

coststr = self.__dict__[field_cost].format(for_forum=for_forum, for_html=for_html)
Expand All @@ -757,9 +779,17 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html =

outstr += linebreak

outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types])
if self.__dict__[field_supertypes]:
for supertype in self.__dict__[field_supertypes]:
outstr += titlecase(supertype) + ' '
for maintype in self.__dict__[field_types]:
outstr += titlecase(maintype) + ' '
if self.__dict__[field_subtypes]:
outstr += ' ' + utils.dash_marker + ' ' + ' '.join(self.__dict__[field_subtypes])
outstr += utils.dash_marker
for subtype in self.__dict__[field_subtypes]:
outstr += ' ' + titlecase(subtype)
else:
outstr = outstr.strip()

if self.__dict__[field_rarity]:
if self.__dict__[field_rarity] in utils.json_rarity_unmap:
Expand All @@ -777,6 +807,7 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html =
#mtext = transforms.text_unpass_3_uncast(mtext)
mtext = transforms.text_unpass_4_unary(mtext)
mtext = transforms.text_unpass_5_symbols(mtext, for_forum, for_html)
mtext = sentencecase(mtext)
#mtext = transforms.text_unpass_6_cardname(mtext, cardname)
mtext = transforms.text_unpass_7_newlines(mtext)
#mtext = transforms.text_unpass_8_unicode(mtext)
Expand Down Expand Up @@ -864,7 +895,10 @@ def to_mse(self, print_raw = False, vdump = False):
outstr += '\tsuper type: ' + ' '.join(self.__dict__[field_supertypes]
+ self.__dict__[field_types]).title() + '\n'
if self.__dict__[field_subtypes]:
outstr += '\tsub type: ' + ' '.join(self.__dict__[field_subtypes]).title() + '\n'
outstr += ('\tsub type:')
for subtype in self.__dict__[field_subtypes]:
outstr += ' ' + titlecase(subtype)
outstr += '\n'

if self.__dict__[field_pt]:
ptstring = utils.from_unary(self.__dict__[field_pt]).split('/')
Expand Down Expand Up @@ -1040,5 +1074,3 @@ def get_types(self):

def get_cmc(self):
return self.__dict__[field_cost].cmc