use new_unique_id() and remove old imports/calls to base36 functions
This commit is contained in:
parent
eb5a0f1344
commit
0626d8d069
|
@ -1,4 +1,4 @@
|
||||||
use crate::{from_base36, Position, ToBase36};
|
use crate::Position;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
19
src/game.rs
19
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 crate::{Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection, Tile, Variable, transform_line_endings, segments_from_string, from_base36, new_unique_id};
|
||||||
use std::error::Error;
|
|
||||||
use loe::TransformMode;
|
use loe::TransformMode;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -359,23 +358,9 @@ impl Game {
|
||||||
/// first available tile ID.
|
/// first available tile ID.
|
||||||
/// e.g. if current tile IDs are [0, 2, 3] the result will be `1`
|
/// 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`
|
/// 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]
|
#[inline]
|
||||||
pub fn new_tile_id(&self) -> String {
|
pub fn new_tile_id(&self) -> String {
|
||||||
let mut new_id = 0;
|
new_unique_id(self.tile_ids())
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// adds a tile safely and returns the new tile ID
|
/// adds a tile safely and returns the new tile ID
|
||||||
|
|
|
@ -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::game::{RoomType, RoomFormat};
|
||||||
use crate::exit::Transition;
|
use crate::exit::Transition;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -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 crate::image::animation_frames_from_string;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
use crate::image::animation_frames_from_string;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue