added sorting

sorting by color and color coded border boxes for each card. styling for
This commit is contained in:
reimannsum 2016-06-14 13:21:19 -04:00
parent 7607a4d499
commit 68b512a7e7
1 changed files with 71 additions and 16 deletions

View File

@ -88,7 +88,18 @@ def main(fname, oname = None, verbose = True, encoding = 'std',
if for_html:
# have to preapend html info
writer.write(utils.html_prepend)
for_forum = True
# seperate the write function to allow for writing smaller chunks of cards at a time
segments = sort_cards(cards)
for i in range(len(segments)):
# this allows card boxes to be colored for each color
# for coloring of each box seperately cardlib.Card.format() must change non-minimaly
writer.write('<div id="' + utils.segment_ids[i] + '">')
writehtml(writer, segments[i])
writer.write("</div>")
# closing the html file
writer.write(utils.html_append)
return #break out of the write cards funcrion to avoid writing cards twice
for card in cards:
if for_mse:
@ -106,30 +117,19 @@ def main(fname, oname = None, verbose = True, encoding = 'std',
else:
fstring = card.format(gatherer = gatherer, for_forum = for_forum,
vdump = vdump, for_html = for_html)
if creativity and for_html:
fstring = fstring[:-6] # chop off the closing </div> to stick stuff in
writer.write((fstring + '\n').encode('utf-8'))
if creativity:
cstring = '~~ closest cards ~~\n'
if for_html:
cstring += "<br>\n"
nearest = card.nearest_cards
for dist, cardname in nearest:
cstring += hoverimg(cardname, dist, namediff)
if for_html:
cstring += "<br>\n"
cstring += '~~ closest names ~~\n'
if for_html:
cstring += "<br>\n"
nearest = card.nearest_names
for dist, cardname in nearest:
cstring += hoverimg(cardname, dist, namediff)
if for_html:
cstring = '<hr><div>' + cstring + '</div>\n</div>'
elif for_mse:
if for_mse:
cstring = ('\n\n' + cstring[:-1]).replace('\n', '\n\t\t')
writer.write(cstring.encode('utf-8'))
writer.write('\n'.encode('utf-8'))
@ -137,9 +137,64 @@ def main(fname, oname = None, verbose = True, encoding = 'std',
if for_mse:
# more formatting info
writer.write('version control:\n\ttype: none\napprentice code: ')
if for_html:
# closing the html file
writer.write(utils.html_append)
def writehtml(writer, card_set):
for card in card_set:
fstring = card.format(gatherer = gatherer, for_forum = True,
vdump = vdump, for_html = for_html)
if creativity:
fstring = fstring[:-6] # chop off the closing </div> to stick stuff in
writer.write((fstring + '\n').encode('utf-8'))
if creativity:
cstring = '~~ closest cards ~~\n<br>\n'
nearest = card.nearest_cards
for dist, cardname in nearest:
cstring += hoverimg(cardname, dist, namediff)
cstring += "<br>\n"
cstring += '~~ closest names ~~\n<br>\n'
nearest = card.nearest_names
for dist, cardname in nearest:
cstring += hoverimg(cardname, dist, namediff)
cstring = '<hr><div>' + cstring + '</div>\n</div>'
writer.write(cstring.encode('utf-8'))
writer.write('\n'.encode('utf-8'))
def sort_cards(card_set):
# Initialize sections
red_cards = []
blue_cards = []
green_cards = []
black_cards = []
white_cards = []
multi_cards = []
colorless_cards = []
for card in card_set:
if len(card.get_colors())>1:
multi_cards += [card]
continue
if 'R' in card.get_colors():
red_cards += [card]
continue
elif 'U' in card.get_colors():
blue_cards += [card]
continue
elif 'B' in card.get_colors():
black_cards += [card]
continue
elif 'G' in card.get_colors():
green_cards += [card]
continue
elif 'W' in card.get_colors():
white_cards += [card]
continue
else:
colorless_cards += [card]
return[white_cards, blue_cards, black_cards, red_cards, green_cards, multi_cards, colorless_cards]
if oname:
if for_html: