use serde::{Deserialize, Serialize};
use crate::{validate_dimensions, AnimationData, Cell};
pub const SPLASH_VERSION: u8 = 1;
pub const SPLASH_MIN_SUPPORTED: u8 = 1;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SplashMeta {
pub name: String,
pub created_at: u64,
pub editor_version: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Splash {
pub version: u8,
pub meta: SplashMeta,
pub width: u32,
pub height: u32,
pub cells: Vec<Cell>,
pub animation: Option<AnimationData>,
}
impl Splash {
pub fn validate(&self) -> Result<(), String> {
let cells = validate_dimensions(self.width, self.height)?;
if self.cells.len() != cells {
return Err(format!(
"Splash cells length {} does not match {}x{}",
self.cells.len(),
self.width,
self.height
));
}
if let Some(animation) = &self.animation {
for (idx, frame) in animation.frames.iter().enumerate() {
if frame.cells.len() != cells {
return Err(format!(
"Animation frame {} has {} cells, expected {}",
idx,
frame.cells.len(),
cells
));
}
}
}
Ok(())
}
}