use bevy::prelude::*;
use bevy_asset_loader::loading_state::{
    config::ConfigureLoadingState, LoadingState, LoadingStateAppExt,
};
use tracing_subscriber::EnvFilter;

mod logo;
mod menu;
mod networking;
mod rooms;

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
pub enum AppState {
    #[default]
    LoadingLogo,
    Logo,
    LoadingMenu,
    Menu,
    Rooms,
    InGame,
}

fn main() {
    let _ = tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .try_init();

    App::new()
        .init_state::<AppState>()
        .add_loading_state(
            LoadingState::new(AppState::LoadingLogo)
                .continue_to_state(AppState::Logo)
                .load_collection::<logo::LogoAssets>(),
        )
        .add_loading_state(
            LoadingState::new(AppState::LoadingMenu)
                .continue_to_state(AppState::Menu)
                .load_collection::<menu::MenuAssets>(),
        )
        .add_plugins((
            DefaultPlugins,
            logo::LogoPlugin,
            menu::MenuPlugin,
            rooms::RoomsPlugin,
        ))
        .add_plugins(bevy_egui::EguiPlugin)
        // .add_plugins(EditorPlugin::default())
        .run();
}
