dedupe optional line for room

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

View File

@ -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)] #[derive(Debug, Eq, PartialEq)]
pub struct Room { pub struct Room {
@ -11,6 +11,12 @@ pub struct Room {
pub endings: Vec<Instance>, pub endings: Vec<Instance>,
} }
impl Room {
fn name_line(&self) -> String {
optional_data_line("NAME", self.name.as_ref())
}
}
impl From<String> for Room { impl From<String> for Room {
fn from(string: String) -> Room { fn from(string: String) -> Room {
// todo handle room_format? // todo handle room_format?
@ -125,7 +131,7 @@ impl ToString for Room {
"ROOM {}\n{}{}{}{}{}\nPAL {}", "ROOM {}\n{}{}{}{}{}\nPAL {}",
self.id.to_base36(), self.id.to_base36(),
tiles, tiles,
if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() }, self.name_line(),
items, items,
exits, exits,
endings, endings,