From beea5f8efca8cfb4b2d52b9d773c2298000c7432 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 28 Jun 2020 17:49:32 +0100 Subject: [PATCH] use existing IDs if there is no conflict --- src/game.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index ca213dd..797dd32 100644 --- a/src/game.rs +++ b/src/game.rs @@ -663,7 +663,7 @@ impl Game { /// adds a palette safely and returns the new palette ID #[inline] pub fn add_palette(&mut self, mut palette: Palette) -> String { - let new_id = self.new_palette_id(); + let new_id = try_id(self.palette_ids(), palette.id.clone()); palette.id = new_id.clone(); self.palettes.push(palette); new_id @@ -681,7 +681,7 @@ impl Game { /// adds a sprite safely and returns the new sprite ID #[inline] pub fn add_sprite(&mut self, mut sprite: Sprite) -> String { - let new_id = self.new_sprite_id(); + let new_id = try_id(self.sprite_ids(), sprite.id.clone()); sprite.id = new_id.clone(); self.sprites.push(sprite); new_id