diff --git a/src/tile.rs b/src/tile.rs index 60942fe..a34aed3 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,4 +1,4 @@ -use crate::{AnimationFrames, from_base36, ToBase36}; +use crate::{AnimationFrames, from_base36, ToBase36, optional_data_line}; use crate::image::Image; use crate::mock; @@ -10,6 +10,12 @@ pub struct Tile { pub animation_frames: Vec, } +impl Tile { + fn name_line(&self) -> String { + optional_data_line("NAME", self.name.as_ref()) + } +} + impl From for Tile { #[inline] fn from(string: String) -> Tile { @@ -52,7 +58,7 @@ impl ToString for Tile { "TIL {}\n{}{}{}", self.id.to_base36(), self.animation_frames.to_string(), - if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap())} else {"".to_string() }, + self.name_line(), if self.wall {"\nWAL true"} else {""} ) }