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
|
|
|
|
name: Option<String>,
|
|
|
|
width: u8,
|
|
|
|
height: u8,
|
|
|
|
/// animation rate in milliseconds
|
|
|
|
tick: u64,
|
|
|
|
/// if this is not specified, the game will pick the first room it finds
|
|
|
|
starting_room: Option<String>,
|
|
|
|
/// major / minor
|
|
|
|
version: (u8, u8),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|
|
|
|
}
|