use std::fs; use std::path::PathBuf; use serde_derive::{Serialize, Deserialize}; mod colour; mod config; mod image; mod mock; mod palette; mod room; pub use colour::Colour; pub use palette::Palette; use crate::config::Config; #[derive(Eq, Hash, PartialEq)] pub struct Position { x: u8, y: u8, } // #[derive(Serialize, Deserialize)] // pub struct Thing { // name: Option, // /// image name // image: String, // } // // #[derive(Serialize, Deserialize)] // pub enum DataType { // Image, // Integer, // Palette, // Room, // Script, // String, // Thing, // Variable, // } // // /// todo refactor, this is stupid // #[derive(Serialize, Deserialize)] // pub struct Value { // data_type: DataType, // image: Option, // integer: Option, // palette: Option, // room: Option, // script: Option, // string: Option, // thing: Option, // variable: Option, // } // // #[derive(Serialize, Deserialize)] // pub struct Variable { // name: String, // data_type: DataType, // default: Value, // } // // #[derive(Serialize, Deserialize)] // pub struct Parameter { // name: String, // data_type: DataType, // default: Value, // } // // #[derive(Serialize, Deserialize)] // pub struct Script { // name: Option, // params: Vec, // script: String, // } // // #[derive(Serialize, Deserialize)] // pub struct ScriptInstance { // script: String, // params: HashMap, // } // // #[derive(Serialize, Deserialize)] // pub struct ScriptCollection { // scripts: Vec, // /// as well as many named scripts, a trigger can have one anonymous script // anonymous: Option, // } // // #[derive(Serialize, Deserialize)] // pub struct Version { // major: u8, // minor: u8, // } // // impl Version { // pub fn default() -> Version { // Version { major: 0, minor: 1 } // } // } #[derive(Serialize, Deserialize)] pub struct Game { config: Config, // palettes: Vec, // variables: Vec, // triggers: HashMap, } #[derive(Debug)] pub struct GameParseError; impl Game { pub fn from(path: String) -> Result { let path = PathBuf::from(path); let mut palettes_dir = path.clone(); palettes_dir.push("palettes"); let palette_files = palettes_dir.read_dir() .expect("couldn't find any palettes"); for file in palette_files { let file = file.unwrap(); println!("palette found: {:?}", file.file_name()); } // todo load config let mut game_config = path.clone(); game_config.push("game.toml"); let config = fs::read_to_string(game_config) .expect("Couldn't load game config"); let config: Config = toml::from_str(&config) .expect("Couldn't parse game config"); Ok( Game { config, } ) } }