#!/usr/bin/env python3
import base64
import pathlib

here = pathlib.Path('.')

images = {
    file.name[:-4]: 'data:image/png;base64,'
                    + base64.b64encode(file.read_bytes()).decode()
    for file in (here / 'img').glob('*.png')
}
sounds = {
    file.name[:-4]: 'data:audio/mpeg;base64,'
                    + base64.b64encode(file.read_bytes()).decode()
    for file in (here / 'sound').glob('*.mp3')
}

with (here / 'assets.js').open('w') as f:
    f.write("""/**
 * @licstart  The following is the entire license notice for the JavaScript code in this page.
 *
 * Copyright 2019 HushBugger
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * @licend  The above is the entire license notice for the JavaScript code in this page.
 */

// Putting assets in here has a few advantages.
// First, they're preloaded, so there's no latency when they're first used.
// Second, it avoids extra network requests in e.g. Firefox's private browsing.
// Third, it means the whole game could easily be bundled into a single page.
// This file is generated by dev/generate_assets.py. Don't touch it manually.

var images = {
""")
    for name, content in images.items():
        f.write(f'    {name}: "{content}",\n')
    f.write("""}

var sounds = {
""")
    for name, content in sounds.items():
        f.write(f'    {name}: new Audio("{content}"),\n')
    f.write("}\n")
