error handling for position
This commit is contained in:
49
src/room.rs
49
src/room.rs
@@ -1,6 +1,7 @@
|
||||
use crate::{from_base36, optional_data_line, Exit, ExitInstance, Instance, Position, ToBase36};
|
||||
use crate::game::{RoomType, RoomFormat};
|
||||
use crate::exit::Transition;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Room {
|
||||
@@ -70,39 +71,43 @@ impl From<String> for Room {
|
||||
let item_position: Vec<&str> = last_line.split(' ').collect();
|
||||
let item_id = item_position[0];
|
||||
let position = item_position[1];
|
||||
let position = Position::from(position.to_string()).unwrap();
|
||||
let position = Position::from_str(position);
|
||||
|
||||
items.push(Instance {
|
||||
position,
|
||||
id: item_id.to_string(),
|
||||
});
|
||||
if position.is_ok() {
|
||||
let position = position.unwrap();
|
||||
items.push(Instance { position, id: item_id.to_string() });
|
||||
}
|
||||
} else if last_line.starts_with("EXT") {
|
||||
let last_line = last_line.replace("EXT ", "");
|
||||
let parts: Vec<&str> = last_line.split(' ').collect();
|
||||
let position = Position::from(parts[0].to_string()).unwrap();
|
||||
let exit = Exit::from(format!("{} {}", parts[1], parts[2]));
|
||||
let mut transition = None;
|
||||
let mut dialogue_id = None;
|
||||
let chunks = parts[3..].chunks(2);
|
||||
for chunk in chunks {
|
||||
if chunk[0] == "FX" {
|
||||
transition = Some(Transition::from(chunk[1]));
|
||||
} else if chunk[0] == "DLG" {
|
||||
dialogue_id = Some(chunk[1].to_string());
|
||||
let position = Position::from_str(parts[0]);
|
||||
|
||||
if position.is_ok() {
|
||||
let position = position.unwrap();
|
||||
let exit = Exit::from(format!("{} {}", parts[1], parts[2]));
|
||||
let mut transition = None;
|
||||
let mut dialogue_id = None;
|
||||
let chunks = parts[3..].chunks(2);
|
||||
for chunk in chunks {
|
||||
if chunk[0] == "FX" {
|
||||
transition = Some(Transition::from(chunk[1]));
|
||||
} else if chunk[0] == "DLG" {
|
||||
dialogue_id = Some(chunk[1].to_string());
|
||||
}
|
||||
}
|
||||
exits.push(ExitInstance { position, exit, transition, dialogue_id });
|
||||
}
|
||||
exits.push(ExitInstance { position, exit, transition, dialogue_id });
|
||||
} else if last_line.starts_with("END") {
|
||||
let last_line = last_line.replace("END ", "");
|
||||
let ending_position: Vec<&str> = last_line.split(' ').collect();
|
||||
let ending = ending_position[0].to_string();
|
||||
let position = ending_position[1].to_string();
|
||||
let position = Position::from(position).unwrap();
|
||||
let position = ending_position[1];
|
||||
let position = Position::from_str(position);
|
||||
|
||||
endings.push(Instance {
|
||||
position,
|
||||
id: ending,
|
||||
});
|
||||
if position.is_ok() {
|
||||
let position = position.unwrap();
|
||||
endings.push(Instance { position, id: ending });
|
||||
}
|
||||
} else {
|
||||
lines.push(last_line);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user