diff --git a/src/exit.rs b/src/exit.rs index 5ed5b6d..4d7b2c4 100644 --- a/src/exit.rs +++ b/src/exit.rs @@ -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 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 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(), diff --git a/src/mock.rs b/src/mock.rs index cb44fa0..ef356e1 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -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![