implement ToString for Dialogue

This commit is contained in:
Max Bradbury 2020-04-12 10:37:41 +01:00
parent 4fd71f4a2c
commit 3d1beca268
1 changed files with 10 additions and 9 deletions

View File

@ -982,19 +982,20 @@ fn test_dialogue_from_string() {
)
}
fn dialogue_to_string(dialogue: Dialogue) -> String {
format!("DLG {}\n{}", dialogue.id, dialogue.contents)
impl ToString for Dialogue {
#[inline]
fn to_string(&self) -> String {
format!("DLG {}\n{}", self.id, self.contents)
}
}
#[test]
fn test_dialogue_to_string() {
assert_eq!(
dialogue_to_string(
Dialogue {
id: "y".to_string(),
contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string()
}
),
Dialogue {
id: "y".to_string(),
contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string()
}.to_string(),
"DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string()
);
}
@ -1286,7 +1287,7 @@ fn game_to_string(game: Game) -> String {
}
for dialogue in game.dialogues {
segments.push(dialogue_to_string(dialogue));
segments.push(dialogue.to_string());
}
for ending in game.endings {