diff --git a/src/item.rs b/src/item.rs index 641ff71..6006638 100644 --- a/src/item.rs +++ b/src/item.rs @@ -9,6 +9,7 @@ pub struct Item { pub name: Option, pub dialogue_id: Option, pub colour_id: Option, + pub blip: Option, } impl Item { @@ -24,7 +25,11 @@ impl Item { optional_data_line("COL", self.colour_id.as_ref()) } - pub fn from_str(str: &str) -> Result { + fn blip_line(&self) -> String { + optional_data_line("BLIP", self.blip.as_ref()) + } + + pub fn from_str(str: &str) -> Result<(Item, Vec), crate::Error> { let mut lines: Vec<&str> = str.lines().collect(); if lines.is_empty() || !lines[0].starts_with("ITM ") { @@ -35,11 +40,16 @@ impl Item { let mut name = None; let mut dialogue_id = None; let mut colour_id: Option = None; + let mut blip = None; + + let mut warnings = Vec::new(); loop { let last_line = lines.pop().unwrap(); - if last_line.starts_with("NAME") { + if last_line.starts_with("BLIP") { + blip = Some(last_line.replace("BLIP ", "").to_string()); + } else if last_line.starts_with("NAME") { name = Some(last_line.replace("NAME ", "").to_string()); } else if last_line.starts_with("DLG") { dialogue_id = Some(last_line.replace("DLG ", "").to_string()); @@ -51,11 +61,13 @@ impl Item { } } - let animation_frames = animation_frames_from_str( + let (animation_frames, mut animation_warnings) = animation_frames_from_str( &lines[1..].join("\n") - ); + ).unwrap(); - Ok(Item { id, name, animation_frames, dialogue_id, colour_id }) + warnings.append(&mut animation_warnings); + + Ok((Item { id, name, animation_frames, dialogue_id, colour_id, blip }, warnings)) } } @@ -63,12 +75,13 @@ impl fmt::Display for Item { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "ITM {}\n{}{}{}{}", + "ITM {}\n{}{}{}{}{}", self.id, self.animation_frames.to_string(), self.name_line(), self.dialogue_line(), self.colour_line(), + self.blip_line(), ) } } @@ -79,7 +92,7 @@ mod test { #[test] fn item_from_string() { - let output = Item::from_str(include_str!("test-resources/item")).unwrap(); + let (output, _err) = Item::from_str(include_str!("test-resources/item")).unwrap(); let expected = mock::item(); assert_eq!(output, expected); }