"get sprite" and "get avatar" functions

This commit is contained in:
Max Bradbury 2020-06-18 20:32:11 +01:00
parent b468c680b3
commit edbf9575d7
3 changed files with 1599 additions and 0 deletions

View File

@ -72,6 +72,9 @@ impl Version {
}
}
#[derive(Debug)]
pub struct SpriteNotFound;
#[derive(Clone, Debug, PartialEq)]
pub struct Game {
pub name: String,
@ -217,6 +220,24 @@ impl Game {
)
}
/// todo refactor this into "get T by ID", taking a Vec<T> and an ID name?
#[inline]
pub fn get_sprite_by_id(&self, id: String) -> Result<&Sprite, SpriteNotFound> {
let index = self.sprites.iter().position(
|sprite| sprite.id == id
);
if index.is_some() {
return Ok(&self.sprites[index.unwrap()])
} else {
Err(SpriteNotFound)
}
}
pub fn get_avatar(&self) -> Result<&Sprite, SpriteNotFound> {
self.get_sprite_by_id("A".to_string())
}
pub fn merge(game: Game) {
// ignore title, version, room format, room type, font, text direction

View File

@ -20,6 +20,8 @@ pub mod text;
pub mod tile;
pub mod variable;
pub mod test_omnibus;
use colour::Colour;
use dialogue::Dialogue;
use ending::Ending;

1576
src/test_omnibus.rs Normal file

File diff suppressed because it is too large Load Diff