Compare commits
3 Commits
b72e8f5ac8
...
c9c0942daf
Author | SHA1 | Date |
---|---|---|
Max Bradbury | c9c0942daf | |
Max Bradbury | a14cab8f41 | |
Max Bradbury | cc1015cc7a |
25
TODO.md
25
TODO.md
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
## game data structure
|
## game data structure
|
||||||
|
|
||||||
|
add "from_dir" functions for structs
|
||||||
|
make that function generic?
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
what is the distinction between animate and inanimate objects?
|
what is the distinction between animate and inanimate objects?
|
||||||
|
|
||||||
idea:
|
idea:
|
||||||
|
@ -12,21 +17,7 @@ idea:
|
||||||
* each position could have (optionally) a tile and (optionally) a thing
|
* each position could have (optionally) a tile and (optionally) a thing
|
||||||
* things have render priority
|
* things have render priority
|
||||||
|
|
||||||
### colours
|
* ideally support gif/png for images (are there other indexed colour formats?)
|
||||||
|
|
||||||
~convert colours to hex~
|
|
||||||
* ~accept abcdef, #abcdef, 0xabcdef (inc. uppercase)~
|
|
||||||
* ~export as #abcdef~
|
|
||||||
|
|
||||||
### palettes
|
|
||||||
|
|
||||||
### images
|
|
||||||
|
|
||||||
* ideally support gif/png...
|
|
||||||
|
|
||||||
### parser
|
|
||||||
|
|
||||||
* ~move tests into their respective modules where appropriate~
|
|
||||||
|
|
||||||
## players
|
## players
|
||||||
|
|
||||||
|
@ -35,10 +26,6 @@ idea:
|
||||||
* text (how?)
|
* text (how?)
|
||||||
* support older graphics adaptors
|
* support older graphics adaptors
|
||||||
|
|
||||||
### linux
|
|
||||||
|
|
||||||
* ~get working~
|
|
||||||
|
|
||||||
### windows
|
### windows
|
||||||
|
|
||||||
* ~try to compile~
|
* ~try to compile~
|
||||||
|
|
|
@ -4,9 +4,9 @@ use serde_derive::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
name: String,
|
pub name: String,
|
||||||
image: String,
|
pub image: String,
|
||||||
tags: Vec<String>,
|
pub tags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
|
|
71
src/lib.rs
71
src/lib.rs
|
@ -121,9 +121,7 @@ pub struct Game {
|
||||||
pub struct GameParseError;
|
pub struct GameParseError;
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
pub fn from(path: String) -> Result<Game, GameParseError> {
|
pub fn from(path: PathBuf) -> Result<Game, GameParseError> {
|
||||||
let path = PathBuf::from(path);
|
|
||||||
|
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
let mut tiles = Vec::new();
|
let mut tiles = Vec::new();
|
||||||
let mut entities = Vec::new();
|
let mut entities = Vec::new();
|
||||||
|
@ -200,4 +198,71 @@ impl Game {
|
||||||
|
|
||||||
Ok(Game { config, images, tiles, palettes, music, entities })
|
Ok(Game { config, images, tiles, palettes, music, entities })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo Result<&Image>?
|
||||||
|
pub fn get_image_by_name(&self, name: String) -> Option<&Image> {
|
||||||
|
for image in self.images.iter() {
|
||||||
|
if image.name == name {
|
||||||
|
return Some(&image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_entities_by_tag(&self, tag: &String) -> Vec<&Entity> {
|
||||||
|
let mut entities = Vec::new();
|
||||||
|
|
||||||
|
for entity in self.entities.iter() {
|
||||||
|
if entity.tags.contains(tag) {
|
||||||
|
entities.push(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entities
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo Result<&Entity>?
|
||||||
|
pub fn get_entity_by_name(&self, name: String) -> Option<&Entity> {
|
||||||
|
for entity in self.entities.iter() {
|
||||||
|
if entity.name == name {
|
||||||
|
return Some(&entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo Result<&Music>?
|
||||||
|
pub fn get_music_by_name(&self, name: String) -> Option<&Music> {
|
||||||
|
for music in self.music.iter() {
|
||||||
|
if music.name == name {
|
||||||
|
return Some(&music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo Result<&Palette>?
|
||||||
|
pub fn get_palette_by_name(&self, name: String) -> Option<&Palette> {
|
||||||
|
for palette in self.palettes.iter() {
|
||||||
|
if palette.name == name {
|
||||||
|
return Some(&palette);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo Result<&Tile>?
|
||||||
|
pub fn get_tile_by_name(&self, name: String) -> Option<&Tile> {
|
||||||
|
for tile in self.tiles.iter() {
|
||||||
|
if tile.name == name {
|
||||||
|
return Some(&tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
image = "avatar"
|
image = "avatar"
|
||||||
tags = []
|
tags = ["player"]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
image = "cat"
|
||||||
|
tags = []
|
|
@ -0,0 +1,2 @@
|
||||||
|
image = "tea"
|
||||||
|
tags = []
|
|
@ -0,0 +1,8 @@
|
||||||
|
00000000
|
||||||
|
00000000
|
||||||
|
00000000
|
||||||
|
00111100
|
||||||
|
01100100
|
||||||
|
00100100
|
||||||
|
00011000
|
||||||
|
00000000
|
Loading…
Reference in New Issue