implement From for Tile

This commit is contained in:
Max Bradbury 2020-04-12 11:29:13 +01:00
parent 163fddda5a
commit 7b941b5d99
1 changed files with 29 additions and 29 deletions

View File

@ -507,7 +507,8 @@ impl AnimationFrames for Vec<Image> {
}
}
fn tile_from_string(string: String) -> Tile {
impl From<String> for Tile {
fn from(string: String) -> Tile {
let mut lines: Vec<&str> = string.lines().collect();
let id = lines[0].replace("TIL ", "");
@ -538,12 +539,11 @@ fn tile_from_string(string: String) -> Tile {
Tile { id, name, wall, animation_frames }
}
}
#[test]
fn test_tile_from_string() {
let output = tile_from_string(
include_str!("../test/resources/tile").to_string()
);
let output = Tile::from(include_str!("../test/resources/tile").to_string());
let expected = Tile {
id: "z".to_string(),
@ -1237,7 +1237,7 @@ fn game_from_string(string: String ) -> Game {
} else if segment.starts_with("ROOM") {
rooms.push(room_from_string(segment));
} else if segment.starts_with("TIL") {
tiles.push(tile_from_string(segment));
tiles.push(Tile::from(segment));
} else if segment.starts_with("SPR A") {
avatar = Some(avatar_from_string(segment));
} else if segment.starts_with("SPR") {