exit functions; ending and room stub functions
This commit is contained in:
parent
6c79de15e7
commit
e86625bbc8
|
@ -20,6 +20,8 @@ a library for parsing Bitsy game data.
|
||||||
* sprite to
|
* sprite to
|
||||||
* item from
|
* item from
|
||||||
* item to
|
* item to
|
||||||
|
* exit from
|
||||||
|
* exit to
|
||||||
|
|
||||||
## todo
|
## todo
|
||||||
|
|
||||||
|
|
84
src/main.rs
84
src/main.rs
|
@ -569,6 +569,90 @@ fn test_item_to_string() {
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exit_from_string(string: String) -> Exit {
|
||||||
|
// e.g. "4 3,3"
|
||||||
|
let room_position: Vec<&str> = string.split(' ').collect();
|
||||||
|
let room = room_position[0].to_string();
|
||||||
|
let position = position_from_string(room_position[1].to_string());
|
||||||
|
|
||||||
|
Exit { room, position }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_exit_from_string() {
|
||||||
|
assert_eq!(
|
||||||
|
exit_from_string("a 12,13".to_string()),
|
||||||
|
Exit { room: "a".to_string(), position: Position { x: 12, y: 13}}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit_to_string(exit: Exit) -> String {
|
||||||
|
format!("{} {}", exit.room, position_to_string(exit.position))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_exit_to_string() {
|
||||||
|
assert_eq!(
|
||||||
|
exit_to_string(Exit { room: "8".to_string(), position: Position { x: 5, y: 6 }}),
|
||||||
|
"8 5,6".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ending_from_string(string: String) -> Ending {
|
||||||
|
Ending { contents: "".to_string() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ending_to_string(ending: Ending) -> String {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn room_from_string(string: String) -> Room {
|
||||||
|
// todo handle room_format?
|
||||||
|
let mut lines: Vec<&str> = string.split("\n").collect();
|
||||||
|
let id = lines[0].replace("ROOM ", "");
|
||||||
|
let mut name = None;
|
||||||
|
let mut palette = "0".to_string();
|
||||||
|
let mut items: HashMap<Position, String> = HashMap::new();
|
||||||
|
let exits: HashMap<Position, Exit> = HashMap::new();
|
||||||
|
let endings: HashMap<Position, Ending> = HashMap::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let last_line = lines.pop().unwrap();
|
||||||
|
|
||||||
|
if last_line.starts_with("NAME") {
|
||||||
|
name = Some(last_line.replace("NAME ", "").to_string());
|
||||||
|
} else if last_line.starts_with("PAL") {
|
||||||
|
palette = last_line.replace("PAL ", "").to_string();
|
||||||
|
} else if last_line.starts_with("ITM") {
|
||||||
|
let last_line = last_line.replace("ITM ", "");
|
||||||
|
let item_pos: Vec<&str> = last_line.split(' ').collect();
|
||||||
|
let item_id = item_pos[0];
|
||||||
|
let pos = item_pos[1];
|
||||||
|
|
||||||
|
items.insert(
|
||||||
|
position_from_string(pos.to_string()),
|
||||||
|
item_id.to_string()
|
||||||
|
);
|
||||||
|
} else if last_line.starts_with("EXT") {
|
||||||
|
|
||||||
|
} else if last_line.starts_with("END") {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
lines.push(last_line); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Room {
|
||||||
|
id,
|
||||||
|
palette,
|
||||||
|
name,
|
||||||
|
tiles: vec![],
|
||||||
|
items: Default::default(),
|
||||||
|
exits: Default::default(),
|
||||||
|
endings: Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn game_from_string(game: String ) -> Game {
|
// fn game_from_string(game: String ) -> Game {
|
||||||
// // probably needs to split the game data into different segments starting from the end
|
// // probably needs to split the game data into different segments starting from the end
|
||||||
// // e.g. VAR... then END... then DLG...
|
// // e.g. VAR... then END... then DLG...
|
||||||
|
|
Loading…
Reference in New Issue