handle room wall array
This commit is contained in:
parent
7c566ab9d3
commit
e71c87ad4c
|
@ -55,7 +55,6 @@ some more practical uses would be things like:
|
||||||
* test for bitsy 7.0 and implement new features
|
* test for bitsy 7.0 and implement new features
|
||||||
* implement Result return types on ::from functions so we can handle errors
|
* implement Result return types on ::from functions so we can handle errors
|
||||||
* check multi-line endings/dialogues
|
* check multi-line endings/dialogues
|
||||||
* handle room wall array
|
|
||||||
* handle old out-of-bounds editor errors (extra image pixels, exits/endings with position -1,-0 etc.)
|
* handle old out-of-bounds editor errors (extra image pixels, exits/endings with position -1,-0 etc.)
|
||||||
* it's ok if the output of these does not match the input as we're fixing it
|
* it's ok if the output of these does not match the input as we're fixing it
|
||||||
|
|
||||||
|
|
|
@ -353,16 +353,11 @@ fn test_bitsy_omnibus() {
|
||||||
// fails because of sprite colours but also because a tile contains "NaN"
|
// fails because of sprite colours but also because a tile contains "NaN"
|
||||||
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
|
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
|
||||||
|
|
||||||
// fails because room wall array is not implemented
|
|
||||||
// (this game uses room_format 1 - I thought it'd be using 0...)
|
|
||||||
"src/test-resources/omnibus/76EB6E4A.bitsy.txt".to_string(),
|
|
||||||
"src/test-resources/omnibus/DC053B1A.bitsy.txt".to_string(),
|
|
||||||
"src/test-resources/omnibus/CD0609B6.bitsy.txt".to_string(),
|
|
||||||
"src/test-resources/omnibus/E45F178D.bitsy.txt".to_string(),
|
|
||||||
// not sure about this one but it uses room wall array
|
// not sure about this one but it uses room wall array
|
||||||
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
|
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
|
||||||
|
// this also has a "SET" instead of a room - what? todo investigate
|
||||||
|
// and the SET has no palette? is this allowed?
|
||||||
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
|
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
|
||||||
"src/test-resources/omnibus/AB368CEC.bitsy.txt".to_string(),
|
|
||||||
|
|
||||||
// bad game data
|
// bad game data
|
||||||
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
|
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
|
||||||
|
|
|
@ -182,6 +182,7 @@ pub fn room() -> Room {
|
||||||
endings: vec![
|
endings: vec![
|
||||||
Instance{position: Position { x: 8, y: 7 }, id: "undefined".to_string()},
|
Instance{position: Position { x: 8, y: 7 }, id: "undefined".to_string()},
|
||||||
],
|
],
|
||||||
|
walls: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,8 @@ pub fn game_default() -> Game {
|
||||||
],
|
],
|
||||||
items: vec![],
|
items: vec![],
|
||||||
exits: vec![],
|
exits: vec![],
|
||||||
endings: vec![]
|
endings: vec![],
|
||||||
|
walls: vec![]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
tiles: vec![
|
tiles: vec![
|
||||||
|
|
31
src/room.rs
31
src/room.rs
|
@ -9,12 +9,22 @@ pub struct Room {
|
||||||
pub items: Vec<Instance>,
|
pub items: Vec<Instance>,
|
||||||
pub exits: Vec<ExitInstance>,
|
pub exits: Vec<ExitInstance>,
|
||||||
pub endings: Vec<Instance>,
|
pub endings: Vec<Instance>,
|
||||||
|
pub walls: Vec<u64>, // old way of handling walls...
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
fn name_line(&self) -> String {
|
fn name_line(&self) -> String {
|
||||||
optional_data_line("NAME", self.name.as_ref())
|
optional_data_line("NAME", self.name.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(",")))
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Room {
|
impl From<String> for Room {
|
||||||
|
@ -27,11 +37,16 @@ impl From<String> for Room {
|
||||||
let mut items: Vec<Instance> = Vec::new();
|
let mut items: Vec<Instance> = Vec::new();
|
||||||
let mut exits: Vec<ExitInstance> = Vec::new();
|
let mut exits: Vec<ExitInstance> = Vec::new();
|
||||||
let mut endings: Vec<Instance> = Vec::new();
|
let mut endings: Vec<Instance> = Vec::new();
|
||||||
|
let mut walls: Vec<u64> = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let last_line = lines.pop().unwrap();
|
let last_line = lines.pop().unwrap();
|
||||||
|
|
||||||
if last_line.starts_with("NAME") {
|
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();
|
||||||
|
} else if last_line.starts_with("NAME") {
|
||||||
name = Some(last_line.replace("NAME ", "").to_string());
|
name = Some(last_line.replace("NAME ", "").to_string());
|
||||||
} else if last_line.starts_with("PAL") {
|
} else if last_line.starts_with("PAL") {
|
||||||
palette_id = from_base36(&last_line.replace("PAL ", ""));
|
palette_id = from_base36(&last_line.replace("PAL ", ""));
|
||||||
|
@ -80,7 +95,7 @@ impl From<String> for Room {
|
||||||
exits.reverse();
|
exits.reverse();
|
||||||
endings.reverse();
|
endings.reverse();
|
||||||
|
|
||||||
Room { id, palette_id, name, tiles, items, exits, endings }
|
Room { id, palette_id, name, tiles, items, exits, endings, walls }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +147,11 @@ impl ToString for Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"ROOM {}\n{}{}{}{}{}\nPAL {}",
|
"ROOM {}\n{}{}{}{}{}{}\nPAL {}",
|
||||||
self.id.to_base36(),
|
self.id.to_base36(),
|
||||||
tiles,
|
tiles,
|
||||||
self.name_line(),
|
self.name_line(),
|
||||||
|
self.wall_line(),
|
||||||
items,
|
items,
|
||||||
exits,
|
exits,
|
||||||
endings,
|
endings,
|
||||||
|
@ -148,3 +164,12 @@ impl ToString for Room {
|
||||||
fn test_room_to_string() {
|
fn test_room_to_string() {
|
||||||
assert_eq!(crate::mock::room().to_string(), include_str!("test-resources/room").to_string());
|
assert_eq!(crate::mock::room().to_string(), include_str!("test-resources/room").to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue