2024-10-06 12:39:36 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
2024-10-06 16:00:12 +02:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
2024-10-06 12:39:36 +02:00
|
|
|
pub struct Level {
|
|
|
|
id: String,
|
2024-10-07 12:04:55 +02:00
|
|
|
sort_order: i32,
|
2024-10-06 12:39:36 +02:00
|
|
|
name: String,
|
|
|
|
description: String,
|
2024-10-07 12:21:57 +02:00
|
|
|
#[serde(default)]
|
|
|
|
is_sandbox: bool,
|
2024-10-06 12:39:36 +02:00
|
|
|
init_board: Option<String>,
|
2024-12-05 14:23:21 +01:00
|
|
|
inputs: IOData,
|
|
|
|
outputs: IOData,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum IOData {
|
|
|
|
Bytes(Vec<u8>),
|
|
|
|
Text(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IOData {
|
|
|
|
pub fn as_bytes(&self) -> &[u8] {
|
|
|
|
match self {
|
|
|
|
IOData::Bytes(b) => b,
|
|
|
|
IOData::Text(t) => t.as_bytes(),
|
|
|
|
}
|
|
|
|
}
|
2024-10-06 12:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Level {
|
|
|
|
pub fn id(&self) -> &str {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
2024-10-07 12:04:55 +02:00
|
|
|
pub fn sort_order(&self) -> i32 {
|
|
|
|
self.sort_order
|
|
|
|
}
|
|
|
|
|
2024-10-06 12:39:36 +02:00
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> &str {
|
|
|
|
&self.description
|
|
|
|
}
|
|
|
|
|
2024-10-07 12:21:57 +02:00
|
|
|
pub fn is_sandbox(&self) -> bool {
|
|
|
|
self.is_sandbox
|
|
|
|
}
|
|
|
|
|
2024-10-06 22:24:37 +02:00
|
|
|
pub fn init_board(&self) -> Option<String> {
|
2024-10-06 16:00:12 +02:00
|
|
|
self.init_board.clone()
|
2024-10-06 12:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inputs(&self) -> &[u8] {
|
2024-12-05 14:23:21 +01:00
|
|
|
self.inputs.as_bytes()
|
2024-10-06 12:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn outputs(&self) -> &[u8] {
|
2024-12-05 14:23:21 +01:00
|
|
|
self.outputs.as_bytes()
|
2024-10-06 12:39:36 +02:00
|
|
|
}
|
2024-10-07 17:33:53 +02:00
|
|
|
|
|
|
|
pub fn input_is_text(&self) -> bool {
|
2024-12-05 14:23:21 +01:00
|
|
|
matches!(self.inputs, IOData::Text(_))
|
2024-10-07 17:33:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn output_is_text(&self) -> bool {
|
2024-12-05 14:23:21 +01:00
|
|
|
matches!(self.outputs, IOData::Text(_))
|
2024-10-07 17:33:53 +02:00
|
|
|
}
|
2024-10-06 12:39:36 +02:00
|
|
|
}
|