From 366914e4bba0fcb0fdc859e2dc6a5b214cff3e04 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 19 Jul 2020 12:11:09 +0100 Subject: [PATCH] don't add duplicate tiles --- src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fdd39d5..c3165d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,20 +57,23 @@ pub fn add_tiles(game_data: String, image: String, prefix: String) -> String { } } - game.add_tile(Tile { + let tile = Tile { /// "0" will get overwritten to a new, safe tile ID id: "0".to_string(), name: tile_name(&prefix, &tile_index), wall: None, animation_frames: vec![Image { pixels }], colour_id: None - }); + }; - tile_index += 1; + if !game.tiles.contains(&tile) { + game.add_tile(tile); + + tile_index += 1; + } } } - game.dedupe_tiles(); game.to_string() }