marble-machinations/src/level.rs

51 lines
801 B
Rust
Raw Normal View History

2024-10-06 12:39:36 +02:00
use serde::Deserialize;
use crate::marble_engine::board::Board;
#[derive(Debug, Deserialize)]
pub struct Level {
id: String,
name: String,
description: String,
init_board: Option<String>,
inputs: Vec<u8>,
outputs: Vec<u8>,
}
impl Level {
pub fn new_sandbox() -> Self {
Self {
id: "sandbox".into(),
name: "Sandbox".into(),
description: String::new(),
init_board: None,
inputs: Vec::new(),
outputs: Vec::new(),
}
}
pub fn id(&self) -> &str {
&self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn description(&self) -> &str {
&self.description
}
pub fn init_board(&self) -> Option<Board> {
self.init_board.as_deref().map(Board::parse)
}
pub fn inputs(&self) -> &[u8] {
&self.inputs
}
pub fn outputs(&self) -> &[u8] {
&self.outputs
}
}