//! Hot-reloadable game systems for the Bevy FPS foundation.
#![allow(clippy::type_complexity)]

mod player;
mod rendering;
mod sim_systems;
mod world;

pub use player::{
    grab_cursor, spawn_player, toggle_cursor_grab, update_camera_pitch, update_eye_height,
    update_local_player_intent,
};
pub use rendering::{
    apply_camera_render_profile, apply_project_camera_fx, camera_auto_exposure_active,
    clear_viewport_camera_stack, effective_gi_path_for_camera, effective_viewport_gi_path,
    effective_viewport_render_stack, has_local_shadow_lights, hdr_enabled_profile,
    patch_camera_effects, refresh_player_camera_fx, resolve_active_camera_render_profile_system,
    resolve_viewport_camera_owner, sample_volumes_at, setup_project_camera_effects,
    snapshot_viewport_fx, strip_project_camera_fx, sync_optional_rendering_fx,
    sync_project_atmosphere, sync_viewport_camera_stack, tag_player_camera,
    world_has_local_shadow_lights, AutoExposureRenderingPlugin, FullscreenEffectsPlugin,
    ProjectAtmosphere, SolariRaytracingSceneStats, SolariRenderingPlugin, ViewportCameraOwner,
    ViewportFxSnapshot, ViewportStackApply, HDR_ENV_VAR,
};
pub use sim_systems::{apply_player_intent, move_and_slide, sync_player_physics_position};
pub use world::{
    apply_ambient_light, spawn_level, spawn_sun, sync_project_sun_from_settings,
    sync_project_sun_illuminance, sync_project_sun_visibility,
    sync_scene_directional_shadow_cascades,
};

/// Lightweight bootstrap after a hot reload (idempotent).
pub fn on_hot_reload(world: &mut World) {
    refresh_player_camera_fx(world);

    let rendering = world
        .get_resource::<settings::ProjectSettings>()
        .map(|settings| settings.rendering.clone())
        .unwrap_or_default();
    world.insert_resource(GlobalAmbientLight {
        color: Color::srgb(
            rendering.ambient_color[0],
            rendering.ambient_color[1],
            rendering.ambient_color[2],
        ),
        brightness: rendering.ambient_brightness,
        ..default()
    });

    info!("game_hot: hot reload applied");
}

use bevy::prelude::*;
