mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
TagService -> Tags and more refactoring, close to working again
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type Error = never
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Nuke: (self: ClassConstructor) -> (),
|
||||
Request: (self: ClassConstructor, Name: string) -> TagProduct | Error
|
||||
}
|
||||
|
||||
type Constructor_Fun = () -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
__export: ExportedTags
|
||||
}
|
||||
|
||||
export type TagProduct = Instance | {Instance}
|
||||
export type ExportedTags = {[string]: TagProduct}
|
||||
export type TagsConstructor = ClassConstructor
|
||||
|
||||
local Tags = {} :: Impl_Constructor
|
||||
Tags.__index = Tags
|
||||
|
||||
local CS: CollectionService = game:GetService("CollectionService")
|
||||
|
||||
function Tags.constructor()
|
||||
local Exports: ExportedTags = {}
|
||||
local AllTags = CS:GetAllTags()
|
||||
|
||||
for n: number = 1, #AllTags do
|
||||
local TagName = AllTags[n]
|
||||
local Tagged = CS:GetTagged(TagName)
|
||||
Exports[TagName] = #Tagged>1 and Tagged or Tagged[1]
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
__export = Exports
|
||||
}, Tags)
|
||||
end
|
||||
|
||||
function Tags:Request(Name)
|
||||
return self.__export[Name] or error(`Error requesting tag name, tag name "{Name}" does not exist.`, 2)
|
||||
end
|
||||
|
||||
function Tags:Nuke()
|
||||
local Exports = self.__export
|
||||
|
||||
for i: string, v: TagProduct in Exports do
|
||||
if type(v) == "table" then
|
||||
for n: number = 1, #v do
|
||||
CS:RemoveTag(v[n], i)
|
||||
end
|
||||
else
|
||||
CS:RemoveTag(v, i)
|
||||
end
|
||||
end
|
||||
warn("☢️ nuked all in-game tags. Left-over tags="..table.concat(CS:GetAllTags(), ", "))
|
||||
end
|
||||
|
||||
return Tags
|
||||
Reference in New Issue
Block a user