implement optional name for avatar
This commit is contained in:
parent
596be936d9
commit
c441fce485
|
@ -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<Image>,
|
||||
pub name: Option<String>,
|
||||
pub room_id: u64,
|
||||
pub position: Position,
|
||||
pub colour_id: Option<u64>,
|
||||
|
@ -24,6 +25,7 @@ impl From<String> for Avatar {
|
|||
let string = string.replace("SPR A\n", "");
|
||||
let mut lines: Vec<&str> = string.lines().collect();
|
||||
|
||||
let mut name: Option<String> = None;
|
||||
let mut room_id: Option<u64> = None;
|
||||
let mut position: Option<Position> = None;
|
||||
let mut colour_id: Option<u64> = None;
|
||||
|
@ -41,6 +43,8 @@ impl From<String> 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<String> 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(),
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue