diff --git a/src/game.rs b/src/game.rs index c52e1fa..e0386de 100644 --- a/src/game.rs +++ b/src/game.rs @@ -393,6 +393,18 @@ impl Game { new_unique_id(ids) } + pub fn new_sprite_id(&self) -> String { + new_unique_id(self.sprite_ids()) + } + + pub fn new_room_id(&self) -> String { + new_unique_id(self.room_ids()) + } + + pub fn new_item_id(&self) -> String { + new_unique_id(self.item_ids()) + } + /// adds a tile safely and returns the new tile ID #[inline] pub fn add_tile(&mut self, mut tile: Tile) -> String { @@ -402,6 +414,24 @@ impl Game { new_id } + /// 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(); + sprite.id = new_id.clone(); + self.sprites.push(sprite); + new_id + } + + /// adds a sprite safely and returns the new sprite ID + #[inline] + pub fn add_item(&mut self, mut item: Item) -> String { + let new_id = self.new_item_id(); + item.id = new_id.clone(); + self.items.push(item); + new_id + } + #[inline] fn version_line(&self) -> String { if self.version.is_some() {