From 50e4530984a440e6fdceacb6538171df4c88ba39 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 26 Jul 2020 12:07:00 +0100 Subject: [PATCH] new game::find_tile_with_animation function --- src/game.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/game.rs b/src/game.rs index c232b41..519668b 100644 --- a/src/game.rs +++ b/src/game.rs @@ -662,6 +662,10 @@ impl Game { None } + pub fn find_tile_with_animation(&self, animation: &Vec) -> Option<&Tile> { + self.tiles.iter().find(|&tile| &tile.animation_frames == animation) + } + /// adds a palette safely and returns the ID pub fn add_palette(&mut self, mut palette: Palette) -> String { let new_id = try_id(&self.palette_ids(), &palette.id); @@ -1036,4 +1040,22 @@ mod test { assert_eq!(game.tiles, vec![crate::mock::tile_default(), tile_a, tile_b]); } + + #[test] + fn find_tile_with_animation() { + let game = crate::mock::game_default(); + let animation = vec![Image { pixels: vec![ + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 1, 0, 0, 1, + 1, 0, 0, 1, 1, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + ]}]; + let output = game.find_tile_with_animation(&animation); + let expected = Some(&game.tiles[0]); + assert_eq!(output, expected); + } }