mod effects;
mod slide;
mod slide_show_config;
mod slides;
mod text_drawer;
mod utils;

use crate::slide_show_config::{Context, SlideShowTheme};
use crate::slides::Slideshow;
use crate::slides::demo::Demo;
use crate::slides::projects::Projects;
use crate::slides::standard_slide::StandardSlide;
use crate::slides::title::Title;
use crate::text_drawer::{Justified, TextConfigBuilder};
use macroquad::prelude::*;
use std::path::PathBuf;

fn window_conf() -> Conf {
    Conf {
        window_title: "On Deck".to_owned(),
        fullscreen: true,
        platform: miniquad::conf::Platform {
            ..Default::default()
        },
        ..Default::default()
    }
}

#[macroquad::main(window_conf)]
async fn main() {
    let heading = load_ttf_font("fonts/BoldPixels.ttf").await.unwrap();
    let body = load_ttf_font("fonts/ByteBounce.ttf").await.unwrap();

    let slide_show_theme = SlideShowTheme {
        title_config: TextConfigBuilder::default()
            .justification(Justified::Center)
            .font_size(250)
            .font(&heading)
            .color(WHITE)
            .build(),
        heading_config: TextConfigBuilder::default()
            .justification(Justified::CenterHorizontal)
            .font(&heading)
            .color(WHITE)
            .font_size(150)
            .build(),
        body_config: TextConfigBuilder::default()
            .justification(Justified::Left)
            .font(&body)
            .font_size(100)
            .color(WHITE)
            .build(),
    };

    let mut slideshow = Slideshow::new(Context::new(slide_show_theme));

    slideshow.add_slide(Title::new("Software As a Bit".to_string()));
    slideshow.add_slide(Demo::new());
    slideshow.add_slide(StandardSlide::new(&PathBuf::from("cfg/01_author_intro.toml")).await);
    slideshow
        .add_slide(StandardSlide::new(&PathBuf::from("cfg/02_things_i_have_worked_on.toml")).await);
    slideshow.add_slide(StandardSlide::new(&PathBuf::from("cfg/03_me_outside_work.toml")).await);
    slideshow.add_slide(StandardSlide::new(&PathBuf::from("cfg/04_wait_what.toml")).await);
    slideshow.add_slide(Projects::new());

    loop {
        if slideshow.handle_slide_show() {
            return;
        }

        next_frame().await;
    }
}
