music; load palettes
This commit is contained in:
parent
5bb6760568
commit
4238ea033a
36
src/lib.rs
36
src/lib.rs
|
@ -1,16 +1,17 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use serde_derive::{Serialize, Deserialize};
|
|
||||||
use crate::config::Config;
|
|
||||||
|
|
||||||
mod colour;
|
mod colour;
|
||||||
mod config;
|
mod config;
|
||||||
mod image;
|
mod image;
|
||||||
mod mock;
|
mod mock;
|
||||||
|
mod music;
|
||||||
mod palette;
|
mod palette;
|
||||||
mod scene;
|
mod scene;
|
||||||
|
|
||||||
pub use colour::Colour;
|
pub use colour::Colour;
|
||||||
|
pub use config::Config;
|
||||||
|
pub use music::Music;
|
||||||
pub use palette::Palette;
|
pub use palette::Palette;
|
||||||
pub use scene::Scene;
|
pub use scene::Scene;
|
||||||
|
|
||||||
|
@ -100,12 +101,12 @@ pub struct Position {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
config: Config,
|
config: Config,
|
||||||
// palettes: Vec<Palette>,
|
palettes: Vec<Palette>,
|
||||||
// variables: Vec<Variable>,
|
// variables: Vec<Variable>,
|
||||||
// triggers: HashMap<String, ScriptCollection>,
|
// triggers: HashMap<String, ScriptCollection>,
|
||||||
|
music: Vec<Music>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -115,17 +116,34 @@ 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 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();
|
let mut palettes_dir = path.clone();
|
||||||
palettes_dir.push("palettes");
|
palettes_dir.push("palettes");
|
||||||
|
|
||||||
let palette_files = palettes_dir.read_dir()
|
let palette_files = palettes_dir.read_dir()
|
||||||
.expect("couldn't find any palettes");
|
.expect("couldn't read palettes dir");
|
||||||
|
|
||||||
for file in palette_files {
|
for file in palette_files {
|
||||||
let file = file.unwrap();
|
let file = file.unwrap();
|
||||||
|
palettes.push(Palette::from_file(file.path()));
|
||||||
println!("palette found: {:?}", file.file_name());
|
println!("palette found: {:?}", file.file_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo load config
|
|
||||||
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)
|
||||||
|
@ -133,10 +151,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(
|
Ok(Game { config, palettes, music })
|
||||||
Game {
|
|
||||||
config,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
/// an XM music file.
|
||||||
|
/// name is derived from the file stem.
|
||||||
|
pub struct Music {
|
||||||
|
pub name: String,
|
||||||
|
pub bytes: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Music {
|
||||||
|
pub fn from_file(path: PathBuf) -> Self {
|
||||||
|
Self {
|
||||||
|
name: path.file_stem().unwrap().to_str().unwrap().into(),
|
||||||
|
bytes: fs::read(path).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue