convert exit room id to u64

This commit is contained in:
Max Bradbury 2020-04-13 13:51:29 +01:00
parent 53d5a28923
commit f424c49301
2 changed files with 19 additions and 14 deletions

View File

@ -1,4 +1,4 @@
use crate::Position;
use crate::{Position, from_base36, to_base36};
#[derive(Debug, Eq, PartialEq)]
pub enum Transition {
@ -48,7 +48,7 @@ impl ToString for Transition {
#[derive(Debug, Eq, PartialEq)]
pub struct Exit {
/// destination
pub room: String, /// id
pub room_id: u64, /// id
pub position: Position,
pub effect: Transition,
}
@ -57,7 +57,7 @@ impl From<String> for Exit {
fn from(string: String) -> Exit {
// e.g. "EXT 6,4 0 10,12 FX fade_w"
let room_position_effect: Vec<&str> = string.split_whitespace().collect();
let room = room_position_effect[0].to_string();
let room_id = from_base36(room_position_effect[0]);
let position = Position::from(room_position_effect[1].to_string());
let effect = if room_position_effect.len() == 4 {
@ -66,13 +66,18 @@ impl From<String> for Exit {
Transition::None
};
Exit { room, position, effect }
Exit { room_id, position, effect }
}
}
impl ToString for Exit {
fn to_string(&self) -> String {
format!("{} {}{}", self.room, self.position.to_string(), self.effect.to_string())
format!(
"{} {}{}",
to_base36(self.room_id),
self.position.to_string(),
self.effect.to_string()
)
}
}
@ -80,7 +85,7 @@ impl ToString for Exit {
fn test_exit_from_string() {
assert_eq!(
Exit::from("a 12,13".to_string()),
Exit { room: "a".to_string(), position: Position { x: 12, y: 13 }, effect: Transition::None }
Exit { room_id: 10, position: Position { x: 12, y: 13 }, effect: Transition::None }
);
}
@ -88,18 +93,14 @@ fn test_exit_from_string() {
fn test_exit_from_string_with_fx() {
assert_eq!(
Exit::from("a 12,13 FX slide_u".to_string()),
Exit { room: "a".to_string(), position: Position { x: 12, y: 13 }, effect: Transition::SlideUp }
Exit { room_id: 10, position: Position { x: 12, y: 13 }, effect: Transition::SlideUp }
);
}
#[test]
fn test_exit_to_string() {
assert_eq!(
Exit {
room: "8".to_string(),
position: Position { x: 5, y: 6 },
effect: Transition::None
}.to_string(),
Exit { room_id: 8, position: Position { x: 5, y: 6 }, effect: Transition::None}.to_string(),
"8 5,6".to_string()
);
}
@ -108,7 +109,7 @@ fn test_exit_to_string() {
fn test_exit_to_string_with_fx() {
assert_eq!(
Exit {
room: "8".to_string(),
room_id: 8,
position: Position { x: 5, y: 6 },
effect: Transition::FadeToWhite
}.to_string(),

View File

@ -149,7 +149,11 @@ pub fn room() -> Room {
exits: vec![
ExitInstance {
position: Position { x: 3, y: 3},
exit: Exit { room: "3".to_string(), position: Position { x: 10, y: 6}, effect: Transition::None}
exit: Exit {
room_id: 3,
position: Position { x: 10, y: 6},
effect: Transition::None
}
},
],
endings: vec![