From 6ee58224c1f6c50ab0e76f20fff81d41c680a8cf Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Wed, 24 Jun 2020 12:58:02 +0100 Subject: [PATCH] "add palette" functions --- src/game.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/game.rs b/src/game.rs index e0386de..64616c8 100644 --- a/src/game.rs +++ b/src/game.rs @@ -360,6 +360,11 @@ impl ToString for Game { impl Game { // todo dedupe + #[inline] + pub fn palette_ids(&self) -> Vec { + self.palettes.iter().map(|palette| palette.id.clone()).collect() + } + #[inline] pub fn tile_ids(&self) -> Vec { self.tiles.iter().map(|tile| tile.id.clone()).collect() @@ -382,6 +387,10 @@ impl Game { // todo dedupe? + pub fn new_palette_id(&self) -> String { + new_unique_id(self.palette_ids()) + } + /// first available tile ID. /// e.g. if current tile IDs are [0, 2, 3] the result will be `1` /// if current tile IDs are [0, 1, 2] the result will be `3` @@ -405,6 +414,15 @@ impl Game { new_unique_id(self.item_ids()) } + /// 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(); + palette.id = new_id.clone(); + self.palettes.push(palette); + new_id + } + /// adds a tile safely and returns the new tile ID #[inline] pub fn add_tile(&mut self, mut tile: Tile) -> String {