dedupe optional line for tile

This commit is contained in:
Max Bradbury 2020-04-13 19:25:49 +01:00
parent 5d76798ace
commit df2d0105e6
1 changed files with 8 additions and 2 deletions

View File

@ -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<Image>,
}
impl Tile {
fn name_line(&self) -> String {
optional_data_line("NAME", self.name.as_ref())
}
}
impl From<String> 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 {""}
)
}