Skip to content

Commit

Permalink
Update UniqueIds syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Nov 5, 2024
1 parent 98965fa commit 3acdadb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Useful Modules/Util/UniqueIds.luau
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ function UniqueIds.new(bytes: number, b93: boolean?, idsInUse: {string}?): Uniqu

if idsInUse then
for _, id in idsInUse do
numUniqueIds = math.max(numUniqueIds, UniqueIds:GetIndexFromId(bytes, id, b93) + 1)
numUniqueIds = math.max(numUniqueIds, UniqueIds.GetIndexFromId(bytes, id, b93) + 1)
end

for index = 1, numUniqueIds do
local id = UniqueIds:GetIdFromIndex(bytes, index - 1, b93)
local id = UniqueIds.GetIdFromIndex(bytes, index - 1, b93)
if not table.find(idsInUse, id) then
table.insert(unusedIds, id)
numUnusedIds += 1
Expand All @@ -54,14 +54,14 @@ function UniqueIds.new(bytes: number, b93: boolean?, idsInUse: {string}?): Uniqu
numUnusedIds -= 1
return id
else
local id = UniqueIds:GetIdFromIndex(bytes, numUniqueIds, b93)
local id = UniqueIds.GetIdFromIndex(bytes, numUniqueIds, b93)
numUniqueIds += 1
return id
end
end;

FreeId = function(self: UniqueIds, id: string): ()
local index = UniqueIds:GetIndexFromId(bytes, id, b93)
local index = UniqueIds.GetIndexFromId(bytes, id, b93)
assert(index < numUniqueIds and not table.find(unusedIds, id), "ID not in use")
table.insert(unusedIds, id)
numUnusedIds += 1
Expand All @@ -74,7 +74,7 @@ end
--- @param id -- The unique ID string.
--- @param b93 -- Whether or not to use the Base93 format.
--- @return number -- The index of the unique ID string.
function UniqueIds:GetIndexFromId(bytes: number, id: string, b93: boolean?): number
function UniqueIds.GetIndexFromId(bytes: number, id: string, b93: boolean?): number
return if b93 then Base93.B93ToInt(id) else string.unpack("I" .. bytes, id)
end

Expand All @@ -83,7 +83,7 @@ end
--- @param index -- The index of the unique ID string.
--- @param b93 -- Whether or not to use the Base93 format.
--- @return string -- The unique ID string.
function UniqueIds:GetIdFromIndex(bytes: number, index: number, b93: boolean?): string
function UniqueIds.GetIdFromIndex(bytes: number, index: number, b93: boolean?): string
return if b93 then Base93.IntToB93(index, bytes) else string.pack("I" .. bytes, index)
end

Expand Down

0 comments on commit 3acdadb

Please sign in to comment.