use crate::render::grid::GridStyle;
use crate::render::palette::RgbColor;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub(crate) struct AppRuntimeConfig {
pub warmup_frames: usize,
pub skip_warmup: bool,
pub warmup_brightness_multiplier: f32,
pub auto_reset: bool,
pub auto_reset_entropy_threshold: f32,
pub auto_reset_duration_frames: usize,
pub grid: bool,
pub grid_style: GridStyle,
pub grid_size: usize,
pub grid_color: RgbColor,
pub grid_opacity: f32,
pub grid_adaptive: bool,
pub food_persist_strength: f32,
pub food_persist_radius: f32,
pub food_persist_duration: usize,
}
impl Default for AppRuntimeConfig {
fn default() -> Self {
use crate::config_defaults::{auto_reset, food_persist, grid, warmup};
Self {
warmup_frames: warmup::DEFAULT_WARMUP_FRAMES,
skip_warmup: warmup::DEFAULT_SKIP_WARMUP,
warmup_brightness_multiplier: warmup::DEFAULT_BRIGHTNESS_MULTIPLIER,
auto_reset: auto_reset::DEFAULT_AUTO_RESET,
auto_reset_entropy_threshold: auto_reset::DEFAULT_ENTROPY_THRESHOLD,
auto_reset_duration_frames: auto_reset::DEFAULT_DURATION_FRAMES,
grid: grid::DEFAULT_GRID_ENABLED,
grid_style: GridStyle::Cross,
grid_size: grid::DEFAULT_GRID_SIZE,
grid_color: RgbColor::from_hex(grid::DEFAULT_GRID_COLOR_HEX),
grid_opacity: grid::DEFAULT_GRID_OPACITY,
grid_adaptive: grid::DEFAULT_GRID_ADAPTIVE,
food_persist_strength: food_persist::DEFAULT_STRENGTH,
food_persist_radius: food_persist::DEFAULT_RADIUS,
food_persist_duration: food_persist::DEFAULT_DURATION,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_sources_from_config_defaults() {
use crate::config_defaults::{auto_reset, food_persist, grid, warmup};
let cfg = AppRuntimeConfig::default();
assert_eq!(cfg.warmup_frames, warmup::DEFAULT_WARMUP_FRAMES);
assert_eq!(cfg.skip_warmup, warmup::DEFAULT_SKIP_WARMUP);
assert_eq!(
cfg.warmup_brightness_multiplier,
warmup::DEFAULT_BRIGHTNESS_MULTIPLIER
);
assert_eq!(cfg.auto_reset, auto_reset::DEFAULT_AUTO_RESET);
assert_eq!(
cfg.auto_reset_entropy_threshold,
auto_reset::DEFAULT_ENTROPY_THRESHOLD
);
assert_eq!(
cfg.auto_reset_duration_frames,
auto_reset::DEFAULT_DURATION_FRAMES
);
assert_eq!(cfg.grid, grid::DEFAULT_GRID_ENABLED);
assert_eq!(cfg.grid_style, GridStyle::Cross);
assert_eq!(cfg.grid_size, grid::DEFAULT_GRID_SIZE);
assert_eq!(
cfg.grid_color,
RgbColor::from_hex(grid::DEFAULT_GRID_COLOR_HEX)
);
assert_eq!(cfg.grid_opacity, grid::DEFAULT_GRID_OPACITY);
assert_eq!(cfg.grid_adaptive, grid::DEFAULT_GRID_ADAPTIVE);
assert_eq!(cfg.food_persist_strength, food_persist::DEFAULT_STRENGTH);
assert_eq!(cfg.food_persist_radius, food_persist::DEFAULT_RADIUS);
assert_eq!(cfg.food_persist_duration, food_persist::DEFAULT_DURATION);
}
}