ending functions

This commit is contained in:
Max Bradbury 2020-04-06 14:11:56 +01:00
parent e86625bbc8
commit b9fecbe8fa
2 changed files with 32 additions and 5 deletions

View File

@ -22,13 +22,13 @@ a library for parsing Bitsy game data.
* item to
* exit from
* exit to
* ending from
* ending to
## todo
### functions
* ending from
* ending to
* dialogue from
* dialogue to
* room from

View File

@ -79,7 +79,8 @@ struct Exit {
// same as a dialogue basically
#[derive(Debug, Eq, PartialEq)]
struct Ending {
contents: String,
id: String,
dialogue: String,
}
#[derive(Debug, Eq, PartialEq)]
@ -599,11 +600,37 @@ fn test_exit_to_string() {
}
fn ending_from_string(string: String) -> Ending {
Ending { contents: "".to_string() }
let string = string.replace("END ", "");
let id_dialogue: Vec<&str> = string.split('\n').collect();
let id = id_dialogue[0].to_string();
let dialogue = id_dialogue[1].to_string();
Ending { id, dialogue }
}
#[test]
fn test_ending_from_string() {
assert_eq!(
ending_from_string("END a\nThis is a long line of dialogue. Blah blah blah".to_string()),
Ending { id: "a".to_string(), dialogue: "This is a long line of dialogue. Blah blah blah".to_string() }
);
}
fn ending_to_string(ending: Ending) -> String {
"".to_string()
format!("END {}\n{}", ending.id, ending.dialogue)
}
#[test]
fn test_ending_to_string() {
assert_eq!(
ending_to_string(
Ending {
id: "7".to_string(),
dialogue: "This is another long ending. So long, farewell, etc.".to_string()
}
),
"END 7\nThis is another long ending. So long, farewell, etc.".to_string()
);
}
fn room_from_string(string: String) -> Room {