From 68b512a7e7faf378cd80fb8632d95a20d1c502ea Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:21:19 -0400 Subject: [PATCH] added sorting sorting by color and color coded border boxes for each card. styling for --- decode.py | 87 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/decode.py b/decode.py index 9f3a79d..aa8e541 100755 --- a/decode.py +++ b/decode.py @@ -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('
') + writehtml(writer, segments[i]) + writer.write("
") + # 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 to stick stuff in writer.write((fstring + '\n').encode('utf-8')) if creativity: cstring = '~~ closest cards ~~\n' - if for_html: - cstring += "
\n" nearest = card.nearest_cards for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) - if for_html: - cstring += "
\n" cstring += '~~ closest names ~~\n' - if for_html: - cstring += "
\n" nearest = card.nearest_names for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) - if for_html: - cstring = '
' + cstring + '
\n' - 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 to stick stuff in + writer.write((fstring + '\n').encode('utf-8')) + + if creativity: + cstring = '~~ closest cards ~~\n
\n' + nearest = card.nearest_cards + for dist, cardname in nearest: + cstring += hoverimg(cardname, dist, namediff) + cstring += "
\n" + cstring += '~~ closest names ~~\n
\n' + nearest = card.nearest_names + for dist, cardname in nearest: + cstring += hoverimg(cardname, dist, namediff) + cstring = '
' + cstring + '
\n' + 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: