2021-05-15 15:59:51 +00:00
|
|
|
use serde_derive::{Serialize, Deserialize};
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Config {
|
|
|
|
/// used in the window title bar
|
2021-05-19 19:09:12 +00:00
|
|
|
pub name: Option<String>,
|
|
|
|
pub width: u8,
|
|
|
|
pub height: u8,
|
2021-05-15 15:59:51 +00:00
|
|
|
/// animation rate in milliseconds
|
2021-05-19 19:09:12 +00:00
|
|
|
pub tick: u64,
|
2021-05-15 15:59:51 +00:00
|
|
|
/// if this is not specified, the game will pick the first room it finds
|
2021-05-19 19:09:12 +00:00
|
|
|
pub starting_room: Option<String>,
|
2021-05-15 15:59:51 +00:00
|
|
|
/// major / minor
|
2021-05-19 19:09:12 +00:00
|
|
|
pub version: (u8, u8),
|
2021-05-15 15:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use crate::Config;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_config_from_toml() {
|
|
|
|
let output: Config = toml::from_str(include_str!("test-resources/basic/game.toml")).unwrap();
|
|
|
|
let expected = Config {
|
|
|
|
name: Some("Write your game's title here".to_string()),
|
|
|
|
width: 16,
|
|
|
|
height: 9,
|
|
|
|
tick: 400,
|
|
|
|
starting_room: Some("example room".to_string()),
|
2021-05-17 14:10:59 +00:00
|
|
|
version: (0, 1)
|
2021-05-15 15:59:51 +00:00
|
|
|
};
|
|
|
|
assert_eq!(output, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_config_to_toml() {
|
|
|
|
let output = toml::to_string(&Config {
|
|
|
|
name: Some("Write your game's title here".to_string()),
|
|
|
|
width: 16,
|
|
|
|
height: 9,
|
|
|
|
tick: 400,
|
|
|
|
starting_room: Some("example room".to_string()),
|
2021-05-17 14:10:59 +00:00
|
|
|
version: (0, 1)
|
2021-05-15 15:59:51 +00:00
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
let expected = include_str!("test-resources/basic/game.toml");
|
|
|
|
assert_eq!(&output, expected);
|
|
|
|
}
|
|
|
|
}
|