rocketsplash-formats 0.2.2

Shared data types and serialization formats for Rocketsplash TUI animations
Documentation
// <FILE>crates/rocketsplash-formats/src/splash.rs</FILE>
// <DESC>Splash screen format definitions and validation</DESC>
// <VERS>VERSION: 1.0.0</VERS>
// <WCTX>Runtime library implementation</WCTX>
// <CLOG>Define Splash format with metadata and validation</CLOG>

use serde::{Deserialize, Serialize};

use crate::{validate_dimensions, AnimationData, Cell};

/// Format version constants for compatibility checking.
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(())
    }
}

// <FILE>crates/rocketsplash-formats/src/splash.rs</FILE>
// <VERS>END OF VERSION: 1.0.0</VERS>