diff --git a/src/room.rs b/src/room.rs index 2662cfd..94b9a8b 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,4 +1,4 @@ -use crate::{Exit, ExitInstance, Instance, mock, Position, from_base36, ToBase36}; +use crate::{Exit, ExitInstance, Instance, mock, Position, from_base36, ToBase36, optional_data_line}; #[derive(Debug, Eq, PartialEq)] pub struct Room { @@ -11,6 +11,12 @@ pub struct Room { pub endings: Vec, } +impl Room { + fn name_line(&self) -> String { + optional_data_line("NAME", self.name.as_ref()) + } +} + impl From for Room { fn from(string: String) -> Room { // todo handle room_format? @@ -125,7 +131,7 @@ impl ToString for Room { "ROOM {}\n{}{}{}{}{}\nPAL {}", self.id.to_base36(), tiles, - if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() }, + self.name_line(), items, exits, endings,