implement ToString for Position

This commit is contained in:
Max Bradbury 2020-04-12 10:20:51 +01:00
parent a58b0ae877
commit d3701348ec
1 changed files with 12 additions and 9 deletions

View File

@ -717,14 +717,17 @@ fn test_position_from_string() {
)
}
fn position_to_string(position: Position) -> String {
format!("{},{}", position.x, position.y)
impl ToString for Position {
#[inline]
fn to_string(&self) -> String {
format!("{},{}", self.x, self.y)
}
}
#[test]
fn test_position_to_string() {
assert_eq!(
position_to_string(Position { x: 4, y: 12 }),
Position { x: 4, y: 12 }.to_string(),
"4,12".to_string()
)
}
@ -759,7 +762,7 @@ fn avatar_to_string(avatar: Avatar) -> String {
"SPR A\n{}\nPOS {} {}",
animation_frames_to_string(avatar.animation_frames),
avatar.room,
position_to_string(avatar.position)
avatar.position.to_string()
)
}
@ -828,7 +831,7 @@ fn sprite_to_string(sprite: Sprite) -> String {
if sprite.name.is_some() {format!("\nNAME {}", sprite.name.unwrap())} else {"".to_string()},
if sprite.dialogue.is_some() {format!("\nDLG {}", sprite.dialogue.unwrap())} else {"".to_string()},
sprite.room,
position_to_string(sprite.position),
sprite.position.to_string(),
)
}
@ -916,7 +919,7 @@ fn test_exit_from_string() {
}
fn exit_to_string(exit: Exit) -> String {
format!("{} {}", exit.room, position_to_string(exit.position))
format!("{} {}", exit.room, exit.position.to_string())
}
#[test]
@ -1113,7 +1116,7 @@ fn room_to_string(room: Room) -> String {
for instance in room.items {
items.push_str(
&format!("\nITM {} {}", instance.id, position_to_string(instance.position))
&format!("\nITM {} {}", instance.id, instance.position.to_string())
);
}
@ -1121,7 +1124,7 @@ fn room_to_string(room: Room) -> String {
exits.push_str(
&format!(
"\nEXT {} {}",
position_to_string(instance.position),
instance.position.to_string(),
exit_to_string(instance.exit)
)
);
@ -1129,7 +1132,7 @@ fn room_to_string(room: Room) -> String {
for instance in room.endings {
endings.push_str(
&format!("\nEND {} {}", instance.id, position_to_string(instance.position))
&format!("\nEND {} {}", instance.id, instance.position.to_string())
);
}