add images to game
This commit is contained in:
parent
036fb9e2b8
commit
f2d23a54d2
19
src/lib.rs
19
src/lib.rs
|
@ -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 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue