make walls vec optional
This commit is contained in:
parent
889328f9a9
commit
fb290f07f4
|
@ -529,7 +529,7 @@ pub fn room() -> Room {
|
|||
position: Position { x: 8, y: 7 },
|
||||
id: "undefined".to_string(),
|
||||
}],
|
||||
walls: vec![],
|
||||
walls: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -828,7 +828,7 @@ pub fn game_default() -> Game {
|
|||
items: vec![],
|
||||
exits: vec![],
|
||||
endings: vec![],
|
||||
walls: vec![],
|
||||
walls: None,
|
||||
}],
|
||||
tiles: vec![self::tile_default()],
|
||||
sprites: vec![
|
||||
|
|
14
src/room.rs
14
src/room.rs
|
@ -23,7 +23,7 @@ pub struct Room {
|
|||
pub exits: Vec<ExitInstance>,
|
||||
pub endings: Vec<Instance>,
|
||||
/// old method of handling walls - a comma-separated list of tile IDs
|
||||
pub walls: Vec<String>,
|
||||
pub walls: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Room {
|
||||
|
@ -32,10 +32,10 @@ impl Room {
|
|||
}
|
||||
|
||||
fn wall_line(&self) -> String {
|
||||
if self.walls.is_empty() {
|
||||
"".to_string()
|
||||
if let Some(walls) = &self.walls {
|
||||
optional_data_line("WAL", Some(walls.join(",")))
|
||||
} else {
|
||||
optional_data_line("WAL", Some(self.walls.join(",")))
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl From<String> for Room {
|
|||
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<String> = Vec::new();
|
||||
let mut walls = None;
|
||||
|
||||
loop {
|
||||
let last_line = lines.pop().unwrap();
|
||||
|
@ -66,7 +66,7 @@ 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| id.to_string()).collect();
|
||||
walls = Some(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") {
|
||||
|
@ -258,6 +258,6 @@ mod test {
|
|||
fn room_walls_array() {
|
||||
let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
|
||||
|
||||
assert_eq!(output.walls, vec!["a".to_string(), "f".to_string()]);
|
||||
assert_eq!(output.walls, Some(vec!["a".to_string(), "f".to_string()]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue