turn room format and room type into enums; transform line endings
This commit is contained in:
11
src/room.rs
11
src/room.rs
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user