diff --git a/src/avatar.rs b/src/avatar.rs index 9061d95..a2510a6 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -4,6 +4,7 @@ use crate::{AnimationFrames, Image, Position, optional_data_line, ToBase36, from #[derive(Debug, Eq, PartialEq)] pub struct Avatar { pub animation_frames: Vec, + pub name: Option, pub room_id: u64, pub position: Position, pub colour_id: Option, @@ -24,6 +25,7 @@ impl From for Avatar { let string = string.replace("SPR A\n", ""); let mut lines: Vec<&str> = string.lines().collect(); + let mut name: Option = None; let mut room_id: Option = None; let mut position: Option = None; let mut colour_id: Option = None; @@ -41,6 +43,8 @@ impl From for Avatar { } position = Some(Position::from(room_pos[1].to_string())); + } else if last_line.starts_with("NAME") { + name = Some(last_line.replace("NAME ", "")); } else if last_line.starts_with("COL") { colour_id = Some(last_line.replace("COL ", "").parse().unwrap()); } else { @@ -58,7 +62,7 @@ impl From for Avatar { Image::from(frame.to_string()) }).collect(); - Avatar { animation_frames, room_id, position , colour_id } + Avatar { animation_frames, name, room_id, position , colour_id } } } @@ -66,8 +70,9 @@ impl ToString for Avatar { #[inline] fn to_string(&self) -> String { format!( - "SPR A\n{}{}{}", + "SPR A\n{}{}{}{}", self.animation_frames.to_string(), + optional_data_line("NAME", self.name.as_ref()), self.room_position_line(), self.colour_line(), ) diff --git a/src/mock.rs b/src/mock.rs index ed1f17f..33b5842 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -62,6 +62,7 @@ pub fn avatar() -> Avatar { ] }, ], + name: None, room_id: 0, position: Position { x: 2, y: 5 }, colour_id: None, @@ -252,6 +253,7 @@ pub fn game_default() -> Game { ] } ], + name: None, room_id: 0, position: Position { x: 4, y: 4 }, colour_id: None,