implement ToString for Position
This commit is contained in:
parent
a58b0ae877
commit
d3701348ec
21
src/main.rs
21
src/main.rs
|
@ -717,14 +717,17 @@ fn test_position_from_string() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn position_to_string(position: Position) -> String {
|
impl ToString for Position {
|
||||||
format!("{},{}", position.x, position.y)
|
#[inline]
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
format!("{},{}", self.x, self.y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_position_to_string() {
|
fn test_position_to_string() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
position_to_string(Position { x: 4, y: 12 }),
|
Position { x: 4, y: 12 }.to_string(),
|
||||||
"4,12".to_string()
|
"4,12".to_string()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -759,7 +762,7 @@ fn avatar_to_string(avatar: Avatar) -> String {
|
||||||
"SPR A\n{}\nPOS {} {}",
|
"SPR A\n{}\nPOS {} {}",
|
||||||
animation_frames_to_string(avatar.animation_frames),
|
animation_frames_to_string(avatar.animation_frames),
|
||||||
avatar.room,
|
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.name.is_some() {format!("\nNAME {}", sprite.name.unwrap())} else {"".to_string()},
|
||||||
if sprite.dialogue.is_some() {format!("\nDLG {}", sprite.dialogue.unwrap())} else {"".to_string()},
|
if sprite.dialogue.is_some() {format!("\nDLG {}", sprite.dialogue.unwrap())} else {"".to_string()},
|
||||||
sprite.room,
|
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 {
|
fn exit_to_string(exit: Exit) -> String {
|
||||||
format!("{} {}", exit.room, position_to_string(exit.position))
|
format!("{} {}", exit.room, exit.position.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1113,7 +1116,7 @@ fn room_to_string(room: Room) -> String {
|
||||||
|
|
||||||
for instance in room.items {
|
for instance in room.items {
|
||||||
items.push_str(
|
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(
|
exits.push_str(
|
||||||
&format!(
|
&format!(
|
||||||
"\nEXT {} {}",
|
"\nEXT {} {}",
|
||||||
position_to_string(instance.position),
|
instance.position.to_string(),
|
||||||
exit_to_string(instance.exit)
|
exit_to_string(instance.exit)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1129,7 +1132,7 @@ fn room_to_string(room: Room) -> String {
|
||||||
|
|
||||||
for instance in room.endings {
|
for instance in room.endings {
|
||||||
endings.push_str(
|
endings.push_str(
|
||||||
&format!("\nEND {} {}", instance.id, position_to_string(instance.position))
|
&format!("\nEND {} {}", instance.id, instance.position.to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue