use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct Solution { solution_id: String, level_id: String, // redundant? pub name: String, pub board: String, pub score: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct Score { pub cycles: u32, pub tiles: u32, pub area: u32, } impl Solution { pub fn new(level_id: String, number: usize) -> Self { Self { solution_id: format!("solution_{number}"), level_id, name: format!("Unnamed {number}"), board: " \n".repeat(20), // todo remove when auto resizing is implemented // score: Some(Score { cycles: 5, tiles: 88, area: 987 }), score: None, } } pub fn score_text(&self) -> String { if let Some(score) = &self.score { format!( "C: {} T: {} A: {}", score.cycles, score.tiles, score.area ) } else { "unsolved".into() } } }