#![feature(mixed_integer_ops_unsigned_sub)]

mod assets;
mod layer;
mod oneko;

use crate::layer::Layer;
use anyhow::{Result, Context};
use tracing::{Level, info};
use tracing_subscriber::EnvFilter;

fn main() -> Result<()> {
    let env_filter = EnvFilter::builder()
        .with_default_directive((if cfg!(debug_assertions) { Level::DEBUG } else { Level::INFO }).into())
        .from_env_lossy();
    tracing_subscriber::fmt()
        .with_env_filter(env_filter)
        .init();

    info!("{} by {}, {}",
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_AUTHORS"),
        env!("CARGO_PKG_DESCRIPTION")
    );

    let (mut layer, mut event_loop) = Layer::new()
        .context("failed to create layer")?;

    info!("layer created, starting event loop");

    while !layer.asked_exit() {
        event_loop.dispatch(None, &mut layer)?;
        if let Some(err) = layer.take_error() {
            return Err(err);
        }
    }
    // event_loop.run(None, &mut layer, |_| {})?;

    Ok(())
}
