diff --git a/src/dialogue.rs b/src/dialogue.rs index 09660f5..4cdcc82 100644 --- a/src/dialogue.rs +++ b/src/dialogue.rs @@ -12,11 +12,19 @@ pub struct Dialogue { impl Dialogue { pub fn from_str(str: &str) -> Result { 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 name = if lines.last().unwrap().starts_with("NAME ") { - Some(lines.pop().unwrap().replace("NAME ", "")) + let last_line = lines.pop().unwrap(); + + let name = if last_line.starts_with("NAME ") { + Some(last_line.replace("NAME ", "")) } else { + lines.push(last_line); None };