extern crate tinygfx_assets as assets;

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest_path = Path::new(&out_dir).join("assets.rs");
    let mut f = File::create(&dest_path).unwrap();

    let mut font = assets::Font::load("assets/Roboto-Regular.ttf").unwrap();

    let epd_font = font.generate("ROBOTO_100", 100, " 0123456789:", "::tinygfx");
    f.write_all(epd_font.as_bytes()).unwrap();

    let epd_font = font.generate(
        "ROBOTO_30",
        30,
        " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.,%°ß↗",
        "::tinygfx",
    );
    f.write_all(epd_font.as_bytes()).unwrap();

    let epd_font = font.generate(
        "ROBOTO_22",
        22,
        " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.,%°ß",
        "::tinygfx",
    );
    f.write_all(epd_font.as_bytes()).unwrap();

    for (filename, name) in [
        ("assets/ic_alarm_black_36dp.png", "ALARM_CLOCK_36"),
        ("assets/ic_thermometer_black_36dp.png", "THERMOMETER_36"),
        ("assets/ic_water_percent_black_36dp.png", "WATER_PERCENT_36"),
        (
            "assets/ic_wifi_strength_alert_outline_black_36dp.png",
            "WIFI_STRENGTH_ALERT_36",
        ),
    ]
    .iter()
    {
        let clock_image = assets::Image::load(filename).unwrap();
        f.write_all(clock_image.generate_bitmap(name, "::tinygfx").as_bytes())
            .unwrap();
    }
}
