diff --git a/src/main.rs b/src/main.rs index ae4b9aa..c1f0ab9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ struct Tile { animation_frames: Vec, } -#[derive(Eq, PartialEq, Hash)] +#[derive(Debug, Eq, PartialEq, Hash)] struct Position { room: String, // id. is room id int or base36 string? x: u8, @@ -407,6 +407,37 @@ fn test_palette_from_string_no_name() { assert_eq!(output, expected); } +fn position_from_string(string: String) -> Position { + // e.g. "0 2,5" + let room_xy: Vec<&str> = string.split(' ').collect(); + let xy: Vec<&str> = room_xy[1].split(',').collect(); + let room = room_xy[0].to_string(); + let x = xy[0].parse().unwrap(); + let y = xy[1].parse().unwrap(); + + Position {room, x, y} +} + +#[test] +fn test_position_from_string() { + assert_eq!( + position_from_string("5 4,12".to_string()), + Position { room: "5".to_string(), x: 4, y: 12 } + ) +} + +fn position_to_string(position: Position) -> String { + format!("{} {},{}", position.room, position.x, position.y) +} + +#[test] +fn test_position_to_string() { + assert_eq!( + position_to_string(Position { room: "5".to_string(), x: 4, y: 12 }), + "5 4,12".to_string() + ) +} + // fn get_avatar(game: Game) -> Sprite { // // get the sprite with an id of A // }