Compare commits

..

No commits in common. "b72e8f5ac8f1078d3265fb77d32fe35083f33576" and "3f76ee4f033dc66ddbc743e2fa246fdcacda30c6" have entirely different histories.

6 changed files with 8 additions and 90 deletions

View File

@ -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);
}
}

View File

@ -3,7 +3,6 @@ use std::path::PathBuf;
mod colour;
mod config;
mod entity;
mod image;
mod mock;
mod music;
@ -13,12 +12,10 @@ mod tile;
pub use colour::Colour;
pub use config::Config;
pub use entity::Entity;
pub use crate::image::Image;
pub use music::Music;
pub use palette::Palette;
pub use scene::Scene;
pub use tile::Tile;
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Position {
@ -110,8 +107,8 @@ pub struct Game {
config: Config,
palettes: Vec<Palette>,
images: Vec<Image>,
tiles: Vec<Tile>,
entities: Vec<Entity>,
// todo tiles
// todo things
// variables: Vec<Variable>,
// triggers: HashMap<String, ScriptCollection>,
music: Vec<Music>,
@ -125,8 +122,6 @@ impl Game {
let path = PathBuf::from(path);
let mut images = Vec::new();
let mut tiles = Vec::new();
let mut entities = Vec::new();
let mut music = Vec::new();
let mut palettes = Vec::new();
@ -159,7 +154,7 @@ impl Game {
images_dir.push("palettes");
let image_files = images_dir.read_dir()
.expect("couldn't read image dir");
.expect("couldn't read images dir");
for file in image_files {
let file = file.unwrap();
@ -167,30 +162,6 @@ impl Game {
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();
game_config.push("game.toml");
let config = fs::read_to_string(game_config)
@ -198,6 +169,6 @@ impl Game {
let config: Config = toml::from_str(&config)
.expect("Couldn't parse game config");
Ok(Game { config, images, tiles, palettes, music, entities })
Ok(Game { config, images, palettes, music })
}
}

View File

@ -1,2 +0,0 @@
image = "avatar"
tags = []

View File

@ -0,0 +1 @@
images = ["avatar"]

View File

@ -1,2 +0,0 @@
images = ["block"]
wall = false

View File

@ -9,7 +9,6 @@ pub struct Tile {
/// 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?
pub images: Vec<String>,
pub wall: bool,
}
impl Tile {
@ -20,14 +19,13 @@ impl Tile {
&read_to_string(path).unwrap()
).unwrap();
Tile { name, images: intermediate.images, wall: intermediate.wall }
Tile { name, images: intermediate.images }
}
}
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
struct IntermediateTile {
images: Vec<String>,
wall: bool,
}
#[cfg(test)]
@ -37,15 +35,9 @@ mod test {
#[test]
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 expected = Tile {
name: "block".into(),
images: vec!["block".to_string()],
wall: false
};
let expected = Tile { name: "avatar".into(), images: vec!["avatar".to_string()] };
assert_eq!(output, expected);
}
}