check if avatar exists
This commit is contained in:
parent
04c0ebca69
commit
4ed5e0bce8
16
src/game.rs
16
src/game.rs
|
@ -82,6 +82,7 @@ impl Version {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum NotFound {
|
||||
Avatar,
|
||||
Room,
|
||||
Sprite,
|
||||
Tile,
|
||||
|
@ -114,7 +115,7 @@ pub struct GameHasNoAvatar;
|
|||
|
||||
impl Game {
|
||||
#[inline]
|
||||
pub fn from(string: String) -> Result<Game, GameHasNoAvatar> {
|
||||
pub fn from(string: String) -> Result<Game, NotFound> {
|
||||
let line_endings_crlf = string.contains("\r\n");
|
||||
let mut string = string;
|
||||
if line_endings_crlf {
|
||||
|
@ -168,6 +169,7 @@ impl Game {
|
|||
let mut tiles: Vec<Tile> = Vec::new();
|
||||
let mut sprites: Vec<Sprite> = Vec::new();
|
||||
let mut items: Vec<Item> = Vec::new();
|
||||
let mut avatar_exists = false;
|
||||
|
||||
for segment in segments {
|
||||
if segment.starts_with("# BITSY VERSION") {
|
||||
|
@ -203,7 +205,11 @@ impl Game {
|
|||
} else if segment.starts_with("SPR ") {
|
||||
let sprite = Sprite::from(segment);
|
||||
if sprite.is_ok() {
|
||||
sprites.push(sprite.unwrap());
|
||||
let sprite = sprite.unwrap();
|
||||
if ! avatar_exists && sprite.id == "A".to_string() {
|
||||
avatar_exists = true;
|
||||
}
|
||||
sprites.push(sprite);
|
||||
}
|
||||
} else if segment.starts_with("ITM ") {
|
||||
items.push(Item::from(segment));
|
||||
|
@ -221,8 +227,10 @@ impl Game {
|
|||
}
|
||||
}
|
||||
|
||||
// todo check if SPR A (avatar) exists
|
||||
|
||||
if ! avatar_exists {
|
||||
return Err(NotFound::Avatar);
|
||||
}
|
||||
|
||||
Ok(
|
||||
Game {
|
||||
name,
|
||||
|
|
Loading…
Reference in New Issue