import time
import datetime
from flairnames import *

# PREPARE OUTPUT
# ------------------------------------------------------------------------------------------

output = ''
output_source = ''
load_by_id = """
    for (var key in flair.names) {
        if (flair.names.hasOwnProperty(key)) {
            var data = key.split(' ');
            var spritepos = data.shift();
            var flairClasses = ' flair-' + spritepos;
            flairClasses += ' flair-' + data[0];
            var categories = '';

            for (var i = 0; i < data.length; i++)
            {
                categories += data[i];
            }

            flair.byId[key] = {
                key: key,
                spritepos: spritepos,
                categories: categories,
                flairId: key,
                flairName: flair.names[key],
                flairClasses: flairClasses
            }
        }
    }
"""
js_output = "/* FLAIR MASTER CONFIG | auto-generated at " + \
    datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S-0' + \
        str(7 if time.localtime().tm_isdst else 8) + '00 (ISO-8601)') + " */ \n" + \
        "flair.loadById = function() {" + load_by_id + "}\nflair.byId = {}\n"

# SETTINGS
# ------------------------------------------------------------------------------------------

# The width and height of an individual sprite in pixels.
FLAIR_WIDTH   = 90
FLAIR_HEIGHT  = 30

# The number of sprites in a sprite sheet row, and the max height of a sprite sheet.
SPRITE_WIDTH  = 10
SPRITE_HEIGHT = 12

# List of sprite sheets.
SHEETS = [
    'AdeptusAstartes',
    'BloodAngels',
    'DarkAngels',
    'ImperialFists',
    'IronHands',
    'RavenGuard',
    'RenegadeChapters',
    'Salamanders',
    'SpaceWolves',
    'Ultramarines',
    'UnknownFoundings',
    'WhiteScars',
    'AdeptaSororitas',
    'AdeptusTerra',
    'CollegiaTitanica',
    'Inquisition',
    'OfficioAssassinorum',
    'AstraMilitarum',
    'TempestusScions',
    'UnknownRegiments',
    'ChaosGods',
    'ChaosLegions',
    'ChaosWarbands',
    'TraitorTitanLegions',
    'Craftworlds',
    'DarkEldar',
    'Harlequins',
    'Runes',
    'Necrons',
    'Orks',
    'Tau',
    'Tyranids',
    'NonUserFlair'
]

# Sprite sheet sources.
sheet_source  = [
    'https://a.thumbs.redditmedia.com/gbra2dsfBYhVL2xSoy0hu2Eo8OLrDgA7CR6qmKcM9Y0.png', # AdeptusAstartes
    'https://a.thumbs.redditmedia.com/w_-zSoIl7PXaMhRbRDLBUC0AAbiMT_H5TZ1CQtp7lI4.png', # BloodAngels
    'https://b.thumbs.redditmedia.com/-pWP4nywemAw-S6xMaZR2H5CslBer1SQ22SfwaaU5Cw.png', # DarkAngels
    'https://b.thumbs.redditmedia.com/YVmQ-AETXtiBPlCJXAmpZLsZwS5i35L8ivxdUM5gifg.png', # ImperialFists
    'https://b.thumbs.redditmedia.com/hEHsr5S589kUft2BXRHyZxVjwcvWPsJLMfUhQ6MuWJY.png', # IronHands
    'https://b.thumbs.redditmedia.com/wvzV0ww5fUfinAi-TY2rz04Q_Q0GnNesNhzdlY2p-AM.png', # RavenGuard
    'https://b.thumbs.redditmedia.com/z-5nqY4EcrffkVzJXUK1FB2UQngSGqGiGXvDLufy4AY.png', # RenegadeChapters
    'https://b.thumbs.redditmedia.com/p2RtUhCc0jAxEmdYCyBu-wKojCLWzlwAXdFWKS4ZTlg.png', # Salamanders
    'https://b.thumbs.redditmedia.com/AItZ2fY8R3cvJYepahZvBUUF8q8H2Lr1I_hfO68O8Jw.png', # SpaceWolves