Compare commits
No commits in common. "b72e8f5ac8f1078d3265fb77d32fe35083f33576" and "3f76ee4f033dc66ddbc743e2fa246fdcacda30c6" have entirely different histories.
b72e8f5ac8
...
3f76ee4f03
|
@ -1,42 +0,0 @@
|
||||||
use std::fs::read_to_string;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use serde_derive::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
pub struct Entity {
|
|
||||||
name: String,
|
|
||||||
image: String,
|
|
||||||
tags: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Entity {
|
|
||||||
pub fn from_file(path: PathBuf) -> Self {
|
|
||||||
let name = path.file_stem().unwrap().to_str().unwrap().into();
|
|
||||||
|
|
||||||
let intermediate: IntermediateEntity = toml::from_str(
|
|
||||||
&read_to_string(path).unwrap()
|
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
Self { name, image: intermediate.image, tags: intermediate.tags }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub(crate) struct IntermediateEntity {
|
|
||||||
image: String,
|
|
||||||
tags: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use crate::entity::Entity;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn from_file() {
|
|
||||||
let path = PathBuf::from("src/test-resources/basic/entities/avatar.toml");
|
|
||||||
let output = Entity::from_file(path);
|
|
||||||
let expected = Entity { name: "avatar".into(), image: "avatar".into(), tags: vec![] };
|
|
||||||
assert_eq!(output, expected);
|
|
||||||
}
|
|
||||||
}
|
|
37
src/lib.rs
37
src/lib.rs
|
@ -3,7 +3,6 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
mod colour;
|
mod colour;
|
||||||
mod config;
|
mod config;
|
||||||
mod entity;
|
|
||||||
mod image;
|
mod image;
|
||||||
mod mock;
|
mod mock;
|
||||||
mod music;
|
mod music;
|
||||||
|
@ -13,12 +12,10 @@ mod tile;
|
||||||
|
|
||||||
pub use colour::Colour;
|
pub use colour::Colour;
|
||||||
pub use config::Config;
|
pub use config::Config;
|
||||||
pub use entity::Entity;
|
|
||||||
pub use crate::image::Image;
|
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;
|
||||||
pub use tile::Tile;
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
|
@ -110,8 +107,8 @@ pub struct Game {
|
||||||
config: Config,
|
config: Config,
|
||||||
palettes: Vec<Palette>,
|
palettes: Vec<Palette>,
|
||||||
images: Vec<Image>,
|
images: Vec<Image>,
|
||||||
tiles: Vec<Tile>,
|
// todo tiles
|
||||||
entities: Vec<Entity>,
|
// todo things
|
||||||
// variables: Vec<Variable>,
|
// variables: Vec<Variable>,
|
||||||
// triggers: HashMap<String, ScriptCollection>,
|
// triggers: HashMap<String, ScriptCollection>,
|
||||||
music: Vec<Music>,
|
music: Vec<Music>,
|
||||||
|
@ -125,8 +122,6 @@ impl Game {
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
|
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
let mut tiles = Vec::new();
|
|
||||||
let mut entities = Vec::new();
|
|
||||||
let mut music = Vec::new();
|
let mut music = Vec::new();
|
||||||
let mut palettes = Vec::new();
|
let mut palettes = Vec::new();
|
||||||
|
|
||||||
|
@ -159,7 +154,7 @@ impl Game {
|
||||||
images_dir.push("palettes");
|
images_dir.push("palettes");
|
||||||
|
|
||||||
let image_files = images_dir.read_dir()
|
let image_files = images_dir.read_dir()
|
||||||
.expect("couldn't read image dir");
|
.expect("couldn't read images dir");
|
||||||
|
|
||||||
for file in image_files {
|
for file in image_files {
|
||||||
let file = file.unwrap();
|
let file = file.unwrap();
|
||||||
|
@ -167,30 +162,6 @@ impl Game {
|
||||||
println!("image found: {:?}", file.file_name());
|
println!("image found: {:?}", file.file_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tiles_dir = path.clone();
|
|
||||||
tiles_dir.push("palettes");
|
|
||||||
|
|
||||||
let tiles_files = tiles_dir.read_dir()
|
|
||||||
.expect("couldn't read tile dir");
|
|
||||||
|
|
||||||
for file in tiles_files {
|
|
||||||
let file = file.unwrap();
|
|
||||||
tiles.push(Tile::from_file(file.path()));
|
|
||||||
println!("tile found: {:?}", file.file_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut entities_dir = path.clone();
|
|
||||||
entities_dir.push("palettes");
|
|
||||||
|
|
||||||
let entities_files = entities_dir.read_dir()
|
|
||||||
.expect("couldn't read tile dir");
|
|
||||||
|
|
||||||
for file in entities_files {
|
|
||||||
let file = file.unwrap();
|
|
||||||
entities.push(Entity::from_file(file.path()));
|
|
||||||
println!("entity 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)
|
||||||
|
@ -198,6 +169,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, images, tiles, palettes, music, entities })
|
Ok(Game { config, images, palettes, music })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
image = "avatar"
|
|
||||||
tags = []
|
|
|
@ -0,0 +1 @@
|
||||||
|
images = ["avatar"]
|
|
@ -1,2 +0,0 @@
|
||||||
images = ["block"]
|
|
||||||
wall = false
|
|
14
src/tile.rs
14
src/tile.rs
|
@ -9,7 +9,6 @@ pub struct Tile {
|
||||||
/// todo should there be animation options? reverse, random, etc?
|
/// todo should there be animation options? reverse, random, etc?
|
||||||
/// todo do we need a "current frame" property or leave that up to the player implementation?
|
/// todo do we need a "current frame" property or leave that up to the player implementation?
|
||||||
pub images: Vec<String>,
|
pub images: Vec<String>,
|
||||||
pub wall: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tile {
|
impl Tile {
|
||||||
|
@ -20,14 +19,13 @@ impl Tile {
|
||||||
&read_to_string(path).unwrap()
|
&read_to_string(path).unwrap()
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
Tile { name, images: intermediate.images, wall: intermediate.wall }
|
Tile { name, images: intermediate.images }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
struct IntermediateTile {
|
struct IntermediateTile {
|
||||||
images: Vec<String>,
|
images: Vec<String>,
|
||||||
wall: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -37,15 +35,9 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_file() {
|
fn from_file() {
|
||||||
let path = PathBuf::from("src/test-resources/basic/tiles/block.toml");
|
let path = PathBuf::from("src/test-resources/basic/tiles/avatar.toml");
|
||||||
let output = Tile::from_file(path);
|
let output = Tile::from_file(path);
|
||||||
|
let expected = Tile { name: "avatar".into(), images: vec!["avatar".to_string()] };
|
||||||
let expected = Tile {
|
|
||||||
name: "block".into(),
|
|
||||||
images: vec!["block".to_string()],
|
|
||||||
wall: false
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue