From 5d76798acebfbbf9e905acacf329ea25c6e7a1af Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Mon, 13 Apr 2020 19:14:57 +0100 Subject: [PATCH] dedupe optional line for room --- src/room.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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,