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); + } }