functions for positions
This commit is contained in:
parent
ebd35b3297
commit
47a9259526
33
src/main.rs
33
src/main.rs
|
@ -31,7 +31,7 @@ struct Tile {
|
|||
animation_frames: Vec<Image>,
|
||||
}
|
||||
|
||||
#[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
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue