rocketsplash_formats/
splash.rs1use serde::{Deserialize, Serialize};
8
9use crate::{validate_dimensions, AnimationData, Cell};
10
11pub const SPLASH_VERSION: u8 = 1;
13pub const SPLASH_MIN_SUPPORTED: u8 = 1;
14
15#[derive(Clone, Debug, Serialize, Deserialize)]
16pub struct SplashMeta {
17 pub name: String,
18 pub created_at: u64,
19 pub editor_version: String,
20}
21
22#[derive(Clone, Debug, Serialize, Deserialize)]
23pub struct Splash {
24 pub version: u8,
25 pub meta: SplashMeta,
26 pub width: u32,
27 pub height: u32,
28 pub cells: Vec<Cell>,
29 pub animation: Option<AnimationData>,
30}
31
32impl Splash {
33 pub fn validate(&self) -> Result<(), String> {
34 let cells = validate_dimensions(self.width, self.height)?;
35 if self.cells.len() != cells {
36 return Err(format!(
37 "Splash cells length {} does not match {}x{}",
38 self.cells.len(),
39 self.width,
40 self.height
41 ));
42 }
43 if let Some(animation) = &self.animation {
44 for (idx, frame) in animation.frames.iter().enumerate() {
45 if frame.cells.len() != cells {
46 return Err(format!(
47 "Animation frame {} has {} cells, expected {}",
48 idx,
49 frame.cells.len(),
50 cells
51 ));
52 }
53 }
54 }
55 Ok(())
56 }
57}
58
59