use std::fs; use std::path::PathBuf; mod colour; mod config; mod image; mod mock; mod music; mod palette; mod scene; pub use colour::Colour; pub use config::Config; pub use music::Music; pub use palette::Palette; pub use scene::Scene; #[derive(Debug, 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 } // } // } pub struct Game { config: Config, palettes: Vec, // variables: Vec, // triggers: HashMap, music: Vec, } #[derive(Debug)] pub struct GameParseError; impl Game { pub fn from(path: String) -> Result { let path = PathBuf::from(path); let mut music = Vec::new(); let mut palettes = Vec::new(); let mut music_dir = path.clone(); music_dir.push("music"); let music_files = music_dir.read_dir(); if music_files.is_ok() { for file in music_files.unwrap() { let file = file.unwrap(); music.push(Music::from_file(file.path())); println!("music found: {:?}", file.file_name()); } } let mut palettes_dir = path.clone(); palettes_dir.push("palettes"); let palette_files = palettes_dir.read_dir() .expect("couldn't read palettes dir"); for file in palette_files { let file = file.unwrap(); palettes.push(Palette::from_file(file.path())); println!("palette found: {:?}", file.file_name()); } 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, palettes, music }) } }