//! Engine configuration shared by live play and recording playback.

use crate::replay::{Handling, Replay};

pub const SCORE_ATTACK_LEVEL_TOTALS: [u32; 16] = [
    0, 3, 8, 15, 24, 35, 48, 63, 80, 99, 120, 144, 170, 198, 228, 260,
];

/// Accelerating gravity thresholds and curve parameters.
#[derive(Clone, Debug)]
pub struct LeveledGravity {
    pub thresholds: Vec<u32>,
    pub base: f64,
    pub speed: f64,
}

#[derive(Clone, Debug)]
pub struct EngineConfig {
    pub handling: Handling,
    pub allow_180: bool,
    pub gravity: Option<LeveledGravity>,
    pub gravity_may20g: bool,
}

impl EngineConfig {
    pub fn from_replay(r: &Replay) -> EngineConfig {
        let gravity = if r.gamemode == "blitz" && r.levels {
            Some(LeveledGravity {
                thresholds: SCORE_ATTACK_LEVEL_TOTALS.to_vec(),
                base: r.levelgbase,
                speed: r.levelgspeed,
            })
        } else {
            None
        };
        EngineConfig {
            handling: r.handling.clone(),
            allow_180: r.allow_180,
            gravity,
            gravity_may20g: r.gravity_may20g,
        }
    }
}
