mod camera;
mod gameplay;
mod state;
mod ui;

use bevy::prelude::*;

use camera::orbit_camera_control;
use gameplay::{
    galaxy_creation::GalaxyCreationPlugin,
    movement::MovementPlugin,
    physics::PhysicsPlugin,
    star_map::StarMapPlugin,
};
use state::AppState;
use ui::main_menu;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .insert_resource(ClearColor(Color::srgb(0.02, 0.02, 0.06)))
        .insert_resource(AmbientLight {
            color: Color::srgb(0.25, 0.3, 0.5),
            brightness: 300.0,
            ..default()
        })
        .init_state::<AppState>()
        .add_systems(Startup, camera::spawn_camera)
        // Orbit controls only in inspection-style scenes. In-game will use a
        // follow camera instead (not yet implemented).
        .add_systems(
            Update,
            orbit_camera_control.run_if(in_state(AppState::GalaxyCreation)),
        )
        .add_systems(OnEnter(AppState::MainMenu), main_menu::setup_main_menu)
        .add_systems(OnExit(AppState::MainMenu), main_menu::despawn_main_menu)
        .add_systems(Update, main_menu::main_menu_buttons)
        .add_plugins((
            MovementPlugin,
            PhysicsPlugin,
            GalaxyCreationPlugin,
            StarMapPlugin,
        ))
        .run();
}
