//! In-process editor binary entry point.

fn main() {
    let startup = match editor::launcher::parse_startup_arguments(std::env::args().skip(1)) {
        Ok(startup) => startup,
        Err(error) => {
            eprintln!(
                "Blacksite Editor: {error}\n\n{}",
                editor::launcher::command_line_help()
            );
            std::process::exit(2);
        }
    };
    if startup.help {
        println!("{}", editor::launcher::command_line_help());
        return;
    }
    if let Some(root) = startup.project {
        if let Err(error) = editor::launcher::activate_project_root(&root) {
            eprintln!("Blacksite Editor: {error}");
            std::process::exit(2);
        }
    }

    if std::env::var_os("WGPU_VALIDATION").is_none() {
        // SAFETY: called before any threads or GPU init.
        unsafe { std::env::set_var("WGPU_VALIDATION", "0") };
    }

    let mut app = bevy::prelude::App::new();
    editor::configure_editor_app(&mut app);
    editor::register_game_editor_plugins(&mut app);
    app.run();
}
