From 16e399b3127e8ebad6c3dac60be2e9dd8d17d4a6 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 18 Apr 2020 12:46:46 +0100 Subject: [PATCH] export font and text direction to string --- src/game.rs | 20 +++++++++++++++++++- src/text.rs | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index fe06cef..3315b7a 100644 --- a/src/game.rs +++ b/src/game.rs @@ -209,10 +209,12 @@ impl ToString for Game { } format!( - "{}\n{}\n{}\n\n{}\n\n", + "{}\n{}\n{}{}{}\n\n{}\n\n", &self.name, &self.version_line(), &self.room_format_line(), + &self.font_line(), + &self.text_direction_line(), segments.join("\n\n"), ) } @@ -257,6 +259,22 @@ impl Game { fn room_format_line(&self) -> String { optional_data_line("! ROOM_FORMAT", Some(self.room_format)) } + + fn font_line(&self) -> String { + if self.font == Font::AsciiSmall { + "".to_string() + } else { + if self.font == Font::Custom { + format!("\n\nDEFAULT FONT {}", self.custom_font.as_ref().unwrap()) + } else { + format!("\n\nDEFAULT FONT {}", self.font.to_string().unwrap()) + } + } + } + + fn text_direction_line(&self) -> &str { + if self.text_direction == TextDirection::RightToLeft {"\n\nTEXT_DIRECTION RTL"} else {""} + } } #[test] diff --git a/src/text.rs b/src/text.rs index d93c608..ce2b1f4 100644 --- a/src/text.rs +++ b/src/text.rs @@ -18,6 +18,16 @@ impl Font { _ => Font::Custom, } } + + pub(crate) fn to_string(&self) -> Result { + match &self { + Font::UnicodeEuropeanSmall => Ok("unicode_european_small".to_string()), + Font::UnicodeEuropeanLarge => Ok("unicode_european_large".to_string()), + Font::UnicodeAsian => Ok("unicode_asian".to_string()), + Font::Arabic => Ok("arabic".to_string()), + _ => Err("No string available for this Font"), + } + } } #[derive(Debug, Eq, PartialEq)]