actually throw error on bad dialogue
This commit is contained in:
parent
d8183e29fc
commit
67d4e28773
|
@ -12,11 +12,19 @@ pub struct Dialogue {
|
|||
impl Dialogue {
|
||||
pub fn from_str(str: &str) -> Result<Dialogue, crate::Error> {
|
||||
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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue