"get sprite" and "get avatar" functions
This commit is contained in:
parent
b468c680b3
commit
edbf9575d7
21
src/game.rs
21
src/game.rs
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue