convert int IDs to strings
This commit is contained in:
28
src/room.rs
28
src/room.rs
@@ -5,14 +5,17 @@ use std::str::FromStr;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Room {
|
||||
pub id: u64,
|
||||
pub palette_id: Option<u64>, // optional in very early versions
|
||||
pub id: String,
|
||||
/// palette ID was optional in very early versions
|
||||
pub palette_id: Option<String>,
|
||||
pub name: Option<String>,
|
||||
pub tiles: Vec<String>, // tile ids
|
||||
/// tile IDs
|
||||
pub tiles: Vec<String>,
|
||||
pub items: Vec<Instance>,
|
||||
pub exits: Vec<ExitInstance>,
|
||||
pub endings: Vec<Instance>,
|
||||
pub walls: Vec<u64>, // old way of handling walls...
|
||||
/// old method of handling walls - a comma-separated list of tile IDs
|
||||
pub walls: Vec<String>,
|
||||
}
|
||||
|
||||
impl Room {
|
||||
@@ -24,8 +27,7 @@ impl Room {
|
||||
#[inline]
|
||||
fn wall_line(&self) -> String {
|
||||
if self.walls.len() > 0 {
|
||||
let ids: Vec<String> = self.walls.iter().map(|&id| id.to_base36()).collect();
|
||||
optional_data_line("WAL", Some(ids.join(",")))
|
||||
optional_data_line("WAL", Some(self.walls.join(",")))
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
@@ -34,7 +36,7 @@ impl Room {
|
||||
#[inline]
|
||||
fn palette_line(&self) -> String {
|
||||
if self.palette_id.is_some() {
|
||||
optional_data_line("PAL", Some(self.palette_id.unwrap().to_base36()))
|
||||
optional_data_line("PAL", Some(self.palette_id.as_ref().unwrap()))
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
@@ -47,13 +49,13 @@ impl From<String> for Room {
|
||||
let string = string.replace("ROOM ", "");
|
||||
let string = string.replace("SET ", "");
|
||||
let mut lines: Vec<&str> = string.lines().collect();
|
||||
let id = from_base36(&lines[0]);
|
||||
let id = lines[0].to_string();
|
||||
let mut name = None;
|
||||
let mut palette_id = None;
|
||||
let mut items: Vec<Instance> = Vec::new();
|
||||
let mut exits: Vec<ExitInstance> = Vec::new();
|
||||
let mut endings: Vec<Instance> = Vec::new();
|
||||
let mut walls: Vec<u64> = Vec::new();
|
||||
let mut walls: Vec<String> = Vec::new();
|
||||
|
||||
loop {
|
||||
let last_line = lines.pop().unwrap();
|
||||
@@ -61,11 +63,11 @@ impl From<String> for Room {
|
||||
if last_line.starts_with("WAL") {
|
||||
let last_line = last_line.replace("WAL ", "");
|
||||
let ids: Vec<&str> = last_line.split(",").collect();
|
||||
walls = ids.iter().map(|&id| from_base36(id)).collect();
|
||||
walls = ids.iter().map(|&id| id.to_string()).collect();
|
||||
} else if last_line.starts_with("NAME") {
|
||||
name = Some(last_line.replace("NAME ", "").to_string());
|
||||
} else if last_line.starts_with("PAL") {
|
||||
palette_id = Some(from_base36(&last_line.replace("PAL ", "")));
|
||||
palette_id = Some(last_line.replace("PAL ", ""));
|
||||
} else if last_line.starts_with("ITM") {
|
||||
let last_line = last_line.replace("ITM ", "");
|
||||
let item_position: Vec<&str> = last_line.split(' ').collect();
|
||||
@@ -211,7 +213,7 @@ impl Room {
|
||||
format!(
|
||||
"{} {}\n{}{}{}{}{}{}{}",
|
||||
room_type.to_string(),
|
||||
self.id.to_base36(),
|
||||
self.id,
|
||||
tiles,
|
||||
self.name_line(),
|
||||
self.wall_line(),
|
||||
@@ -248,6 +250,6 @@ mod test {
|
||||
fn test_room_walls_array() {
|
||||
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
|
||||
|
||||
assert_eq!(output.walls, vec![10, 15]);
|
||||
assert_eq!(output.walls, vec!["a".to_string(), "f".to_string()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user