add images to game

This commit is contained in:
Max Bradbury 2021-05-18 21:33:03 +01:00
parent 036fb9e2b8
commit f2d23a54d2
1 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,7 @@ mod scene;
pub use colour::Colour; pub use colour::Colour;
pub use config::Config; pub use config::Config;
pub use crate::image::Image;
pub use music::Music; pub use music::Music;
pub use palette::Palette; pub use palette::Palette;
pub use scene::Scene; pub use scene::Scene;
@ -104,6 +105,9 @@ pub struct Position {
pub struct Game { pub struct Game {
config: Config, config: Config,
palettes: Vec<Palette>, palettes: Vec<Palette>,
images: Vec<Image>,
// todo tiles
// todo things
// variables: Vec<Variable>, // variables: Vec<Variable>,
// triggers: HashMap<String, ScriptCollection>, // triggers: HashMap<String, ScriptCollection>,
music: Vec<Music>, music: Vec<Music>,
@ -116,6 +120,7 @@ impl Game {
pub fn from(path: String) -> Result<Game, GameParseError> { pub fn from(path: String) -> Result<Game, GameParseError> {
let path = PathBuf::from(path); let path = PathBuf::from(path);
let mut images = Vec::new();
let mut music = Vec::new(); let mut music = Vec::new();
let mut palettes = Vec::new(); let mut palettes = Vec::new();
@ -144,6 +149,18 @@ impl Game {
println!("palette found: {:?}", file.file_name()); println!("palette found: {:?}", file.file_name());
} }
let mut images_dir = path.clone();
images_dir.push("palettes");
let image_files = images_dir.read_dir()
.expect("couldn't read images dir");
for file in image_files {
let file = file.unwrap();
images.push(Image::from_file(file.path()));
println!("image found: {:?}", file.file_name());
}
let mut game_config = path.clone(); let mut game_config = path.clone();
game_config.push("game.toml"); game_config.push("game.toml");
let config = fs::read_to_string(game_config) let config = fs::read_to_string(game_config)
@ -151,6 +168,6 @@ impl Game {
let config: Config = toml::from_str(&config) let config: Config = toml::from_str(&config)
.expect("Couldn't parse game config"); .expect("Couldn't parse game config");
Ok(Game { config, palettes, music }) Ok(Game { config, images, palettes, music })
} }
} }