actually throw error on bad dialogue
This commit is contained in:
parent
d8183e29fc
commit
67d4e28773
|
@ -12,11 +12,19 @@ pub struct Dialogue {
|
||||||
impl Dialogue {
|
impl Dialogue {
|
||||||
pub fn from_str(str: &str) -> Result<Dialogue, crate::Error> {
|
pub fn from_str(str: &str) -> Result<Dialogue, crate::Error> {
|
||||||
let mut lines: Vec<&str> = str.lines().collect();
|
let mut lines: Vec<&str> = str.lines().collect();
|
||||||
|
|
||||||
|
if lines.is_empty() || !lines[0].starts_with("DLG ") {
|
||||||
|
return Err(crate::Error::Dialogue);
|
||||||
|
}
|
||||||
|
|
||||||
let id = lines[0].replace("DLG ", "");
|
let id = lines[0].replace("DLG ", "");
|
||||||
|
|
||||||
let name = if lines.last().unwrap().starts_with("NAME ") {
|
let last_line = lines.pop().unwrap();
|
||||||
Some(lines.pop().unwrap().replace("NAME ", ""))
|
|
||||||
|
let name = if last_line.starts_with("NAME ") {
|
||||||
|
Some(last_line.replace("NAME ", ""))
|
||||||
} else {
|
} else {
|
||||||
|
lines.push(last_line);
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue