exit module
This commit is contained in:
parent
b887e178bb
commit
6090d36559
|
@ -0,0 +1,41 @@
|
|||
use crate::Position;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Exit {
|
||||
/// destination
|
||||
pub(crate) room: String, /// id
|
||||
pub(crate) position: Position,
|
||||
}
|
||||
|
||||
impl From<String> for Exit {
|
||||
fn from(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(room_position[1].to_string());
|
||||
|
||||
Exit { room, position }
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for Exit {
|
||||
fn to_string(&self) -> String {
|
||||
format!("{} {}", self.room, self.position.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
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 } }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exit_to_string() {
|
||||
assert_eq!(
|
||||
Exit { room: "8".to_string(), position: Position { x: 5, y: 6 } }.to_string(),
|
||||
"8 5,6".to_string()
|
||||
);
|
||||
}
|
42
src/lib.rs
42
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
pub mod avatar;
|
||||
pub mod colour;
|
||||
pub mod dialogue;
|
||||
pub mod exit;
|
||||
pub mod palette;
|
||||
pub mod image;
|
||||
pub mod item;
|
||||
|
@ -12,6 +13,7 @@ pub mod tile;
|
|||
use avatar::Avatar;
|
||||
use colour::Colour;
|
||||
use dialogue::Dialogue;
|
||||
use exit::Exit;
|
||||
use palette::Palette;
|
||||
use image::Image;
|
||||
use item::Item;
|
||||
|
@ -31,13 +33,6 @@ pub struct ExitInstance {
|
|||
exit: Exit,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Exit {
|
||||
/// destination
|
||||
room: String, /// id
|
||||
position: Position,
|
||||
}
|
||||
|
||||
// same as a dialogue basically
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Ending {
|
||||
|
@ -290,39 +285,6 @@ impl AnimationFrames for Vec<Image> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<String> for Exit {
|
||||
fn from(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(room_position[1].to_string());
|
||||
|
||||
Exit { room, position }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
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 } }
|
||||
);
|
||||
}
|
||||
|
||||
impl ToString for Exit {
|
||||
fn to_string(&self) -> String {
|
||||
format!("{} {}", self.room, self.position.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exit_to_string() {
|
||||
assert_eq!(
|
||||
Exit { room: "8".to_string(), position: Position { x: 5, y: 6 } }.to_string(),
|
||||
"8 5,6".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
impl From<String> for Ending {
|
||||
fn from(string: String) -> Ending {
|
||||
let string = string.replace("END ", "");
|
||||
|
|
Loading…
Reference in New Issue