turn room format and room type into enums; transform line endings

This commit is contained in:
2020-04-24 18:06:17 +01:00
parent f4b82c3a67
commit 1c6e3eb515
5 changed files with 87 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
use crate::{from_base36, optional_data_line, Exit, ExitInstance, Instance, Position, ToBase36};
use crate::game::{RoomType, RoomFormat};
#[derive(Debug, Eq, PartialEq)]
pub struct Room {
@@ -125,8 +126,8 @@ impl From<String> for Room {
}
}
impl ToString for Room {
fn to_string(&self) -> String {
impl Room {
pub fn to_string(&self, room_format: RoomFormat, room_type: RoomType) -> String {
let mut tiles = String::new();
let mut items = String::new();
let mut exits = String::new();
@@ -167,7 +168,8 @@ impl ToString for Room {
}
format!(
"ROOM {}\n{}{}{}{}{}{}{}",
"{} {}\n{}{}{}{}{}{}{}",
room_type.to_string(),
self.id.to_base36(),
tiles,
self.name_line(),
@@ -183,6 +185,7 @@ impl ToString for Room {
#[cfg(test)]
mod test {
use crate::room::Room;
use crate::game::{RoomType, RoomFormat};
#[test]
fn test_room_from_string() {
@@ -195,7 +198,7 @@ mod test {
#[test]
fn test_room_to_string() {
assert_eq!(
crate::mock::room().to_string(),
crate::mock::room().to_string(RoomFormat::CommaSeparated, RoomType::Room),
include_str!("test-resources/room").to_string()
);
}