"add palette" functions

This commit is contained in:
Max Bradbury 2020-06-24 12:58:02 +01:00
parent 67628e4879
commit 6ee58224c1
1 changed files with 18 additions and 0 deletions

View File

@ -360,6 +360,11 @@ impl ToString for Game {
impl Game {
// todo dedupe
#[inline]
pub fn palette_ids(&self) -> Vec<String> {
self.palettes.iter().map(|palette| palette.id.clone()).collect()
}
#[inline]
pub fn tile_ids(&self) -> Vec<String> {
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 {