use serde::{Deserialize, Serialize}; use crate::level::Level; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Solution { // solution_id: String, level_id: String, // redundant? pub name: String, pub board: String, pub score: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Score { pub cycles: u32, pub tiles: u32, pub area: u32, } impl Solution { pub fn new(level: &Level, number: usize) -> Self { Self { // solution_id: format!("solution_{number}"), level_id: level.id().to_owned(), name: format!("Unnamed {number}"), board: level .init_board() .unwrap_or_else(|| " \n".repeat(20)), // todo remove when auto resizing is implemented // score: Some(Score { cycles: 5, tiles: 88, area: 987 }), score: None, } } pub fn level_id(&self) -> &str { &self.level_id } 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() } } }