From 76eca726996fdcd1e270903349db7fa7013d6921 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Tue, 28 Apr 2020 19:30:18 +0100 Subject: [PATCH] allow non-16x16 rooms --- src/lib.rs | 22 ++++++++++++++++++++++ src/room.rs | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 72e16a5..de71adc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -152,6 +152,28 @@ fn is_string_numeric(str: String) -> bool { return true; } +pub trait Quote { + fn quote(&self) -> String; +} + +impl Quote for String { + #[inline] + fn quote(&self) -> String { + format!("\"\"\"\n{}\n\"\"\"", self).to_string() + } +} + +pub trait Unquote { + fn unquote(&self) -> String; +} + +impl Unquote for String { + #[inline] + fn unquote(&self) -> String { + self.trim_matches('\"').trim_matches('\n').to_string() + } +} + #[cfg(test)] mod test { use crate::{from_base36, ToBase36, optional_data_line, mock, segments_from_string}; diff --git a/src/room.rs b/src/room.rs index cd4ee0e..74aa3b5 100644 --- a/src/room.rs +++ b/src/room.rs @@ -110,7 +110,7 @@ impl From for Room { } let lines = &lines[1..]; - + let dimension = lines.len(); // x or y, e.g. `16` for 16x16 let mut tiles: Vec = Vec::new(); for line in lines.into_iter() { @@ -120,7 +120,7 @@ impl From for Room { .collect(); if ! comma_separated { line = line[1..].to_owned(); } - let line = line[..16].to_owned(); + let line = line[..dimension].to_owned(); for tile_id in line { tiles.push(tile_id.to_string());