diff --git a/src/avatar.rs b/src/avatar.rs index d7ea6c6..c5e5789 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -1,4 +1,5 @@ use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36}; +use std::error::Error; /// avatar is a "sprite" in the game data but with a specific id #[derive(Debug, Eq, PartialEq)] @@ -24,8 +25,8 @@ impl Avatar { } } -impl From for Avatar { - fn from(string: String) -> Avatar { +impl Avatar { + pub(crate) fn from(string: String) -> Result { let string = string.replace("SPR A\n", ""); let mut lines: Vec<&str> = string.lines().collect(); @@ -67,13 +68,7 @@ impl From for Avatar { .map(|&frame| Image::from(frame.to_string())) .collect(); - Avatar { - animation_frames, - name, - room_id, - position, - colour_id, - } + Ok(Avatar { animation_frames, name, room_id, position, colour_id }) } } @@ -92,7 +87,7 @@ impl ToString for Avatar { #[test] fn test_avatar_from_string() { - let output = Avatar::from(include_str!("test-resources/avatar").to_string()); + let output = Avatar::from(include_str!("test-resources/avatar").to_string()).unwrap(); assert_eq!(output, crate::mock::avatar()); } diff --git a/src/game.rs b/src/game.rs index 2857623..50ac617 100644 --- a/src/game.rs +++ b/src/game.rs @@ -131,7 +131,7 @@ impl From for Game { } else if segment.starts_with("TIL") { tiles.push(Tile::from(segment)); } else if segment.starts_with("SPR A") { - avatar = Some(Avatar::from(segment)); + avatar = Some(Avatar::from(segment).unwrap()); } else if segment.starts_with("SPR") { sprites.push(Sprite::from(segment)); } else if segment.starts_with("ITM") {