Don't need from_str

This commit is contained in:
Thomas Forgione 2019-03-30 16:47:23 +01:00
parent a00e39e3f5
commit 322224b3b8
No known key found for this signature in database
GPG Key ID: BFD17A2D71B3B5E7
1 changed files with 0 additions and 26 deletions

View File

@ -330,32 +330,6 @@ impl Map {
Ok(deserialize_from(&mut reader).map_err(Error::Decoding)?) Ok(deserialize_from(&mut reader).map_err(Error::Decoding)?)
} }
/// Creates a map from a txt file.
pub fn from_str(text: &str) -> Result<Map> {
let split = text.split('\n').collect::<Vec<_>>();
// First two usize are the size of the map
let size = split[0]
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>();
let mut tiles = Matrix::from_size(size[0], size[1], CollisionTile::empty());
for (row, line) in split.iter().skip(1).enumerate() {
for (col, tile) in line.split_whitespace().enumerate() {
let num = tile.parse::<u8>().unwrap();
match num {
0 => (),
1 => tiles[(row, col)] = CollisionTile::full(),
_ => panic!("Expecting 0 or 1 in level files"),
}
}
}
Ok(Map::from_collision_tiles(tiles))
}
/// Creates a map from its tiles. /// Creates a map from its tiles.
pub fn from_collision_tiles(tiles: Matrix<CollisionTile>) -> Map { pub fn from_collision_tiles(tiles: Matrix<CollisionTile>) -> Map {
let rows = tiles.rows(); let rows = tiles.rows();