diff --git a/src/item.rs b/src/item.rs index 8d0589c..940eaf5 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,4 +1,4 @@ -use crate::{AnimationFrames, Image, mock, from_base36, ToBase36}; +use crate::{AnimationFrames, Image, mock, from_base36, ToBase36, optional_data_line}; #[derive(Debug, Eq, PartialEq)] pub struct Item { @@ -8,6 +8,15 @@ pub struct Item { pub dialogue_id: Option, } +impl Item { + fn name_line(&self) -> String { + optional_data_line("NAME", self.name.as_ref()) + } + fn dialogue_line(&self) -> String { + optional_data_line("DLG", self.dialogue_id.as_ref()) + } +} + impl From for Item { fn from(string: String) -> Item { let mut lines: Vec<&str> = string.lines().collect(); @@ -47,8 +56,8 @@ impl ToString for Item { "ITM {}\n{}{}{}", self.id.to_base36(), self.animation_frames.to_string(), - if self.name.is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() }, - if self.dialogue_id.is_some() { format!("\nDLG {}", self.dialogue_id.as_ref().unwrap()) } else { "".to_string() }, + self.name_line(), + self.dialogue_line(), ) } }