diff --git a/src/exit.rs b/src/exit.rs index c523f1a..7571989 100644 --- a/src/exit.rs +++ b/src/exit.rs @@ -1,4 +1,4 @@ -use crate::{from_base36, Position, ToBase36}; +use crate::Position; use std::str::FromStr; use std::error::Error; use std::fmt; diff --git a/src/game.rs b/src/game.rs index 8376d5c..7f714e3 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,5 +1,4 @@ -use crate::{Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection, Tile, ToBase36, Variable, transform_line_endings, segments_from_string, to_base36, from_base36}; -use std::error::Error; +use crate::{Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection, Tile, Variable, transform_line_endings, segments_from_string, from_base36, new_unique_id}; use loe::TransformMode; use std::str::FromStr; @@ -359,23 +358,9 @@ impl Game { /// 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` - /// todo this needs to be a generic function that takes a vec of string IDs and returns a new base64 string ID #[inline] pub fn new_tile_id(&self) -> String { - let mut new_id = 0; - - let mut ids = self.tile_ids(); - ids.sort(); - - for id in ids { - if new_id == from_base36(id.as_ref()) { - new_id += 1; - } else { - return to_base36(new_id); - } - } - - to_base36(new_id + 1) + new_unique_id(self.tile_ids()) } /// adds a tile safely and returns the new tile ID diff --git a/src/room.rs b/src/room.rs index 0f4733c..973bf16 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,4 +1,4 @@ -use crate::{from_base36, optional_data_line, Exit, ExitInstance, Instance, Position, ToBase36}; +use crate::{optional_data_line, Exit, ExitInstance, Instance, Position}; use crate::game::{RoomType, RoomFormat}; use crate::exit::Transition; use std::str::FromStr; diff --git a/src/sprite.rs b/src/sprite.rs index 18b3186..20a82af 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -1,4 +1,4 @@ -use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36}; +use crate::{optional_data_line, AnimationFrames, Image, Position}; use crate::image::animation_frames_from_string; use std::str::FromStr; diff --git a/src/tile.rs b/src/tile.rs index 09b747a..5a1a5aa 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,4 +1,4 @@ -use crate::{from_base36, optional_data_line, AnimationFrames, Image, ToBase36}; +use crate::{optional_data_line, AnimationFrames, Image}; use crate::image::animation_frames_from_string; #[derive(Clone, Debug, Eq, PartialEq)]