mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2026-02-03 19:46:49 +00:00
relay work and source map
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type EnumValue = any
|
||||
type EnumName = string
|
||||
type MatchResult = any?
|
||||
|
||||
type MatchList_f = {[string]: (...any?) -> MatchResult}
|
||||
type Enums = {[EnumName]: EnumValue}
|
||||
|
||||
type EnumsMetadata = {
|
||||
__index: (self: EnumsMetadata, i: EnumName) -> EnumValue?,
|
||||
__newindex: (self: EnumsMetadata, i: EnumName, v: EnumValue) -> ()
|
||||
}
|
||||
|
||||
export type CustomEnums = {
|
||||
Enums: typeof(setmetatable({} :: Enums, {} :: EnumsMetadata))
|
||||
} & CustonEnumsFunctions
|
||||
|
||||
type CustonEnumsFunctions = {
|
||||
Create: <T>(Name: EnumName, EnumValue: T) -> T,
|
||||
Remove: (Name: EnumName) -> ()
|
||||
}
|
||||
|
||||
local CustomEnum = {} :: CustomEnums
|
||||
local EnumMeta = {} :: EnumsMetadata
|
||||
|
||||
function EnumMeta.__index(self, i)
|
||||
local get = rawget(self, i)
|
||||
if type(i) == "string" then
|
||||
return get
|
||||
end
|
||||
warn(`Enum: attempt to retrieve an unknown Enum "{i}".`, debug.traceback())
|
||||
return nil
|
||||
end
|
||||
|
||||
function EnumMeta.__newindex(self, i, v)
|
||||
local PossibleEnum = rawget(self, i)
|
||||
if not PossibleEnum then
|
||||
if type(i) == "string" then
|
||||
rawset(self, i, v)
|
||||
else
|
||||
error(`Enum: attempt to set an Enum but the requested name was not a string "{i}", type="{type(i)}".`, 2)
|
||||
end
|
||||
else
|
||||
error(`Enum: attempt to set an Enum but the name "{i}" is already registered.`, 2)
|
||||
end
|
||||
end
|
||||
|
||||
CustomEnum.Enums = setmetatable({}, EnumMeta)
|
||||
|
||||
local function EnumMethods(Enum)
|
||||
--Branch these out later
|
||||
function Enum:Match(Result: string, MatchList: MatchList_f): MatchResult
|
||||
local LastIndexName, LastIndexValue = next(MatchList)
|
||||
|
||||
for MatchEnumName: string, EnumFunc in MatchList do
|
||||
if MatchEnumName == Result then
|
||||
return type(EnumFunc) == "function" and EnumFunc() or EnumFunc
|
||||
elseif MatchEnumName == LastIndexName and LastIndexValue ~= nil and MatchList['_'] then
|
||||
return type(MatchList['_']) == "function" and MatchList['_']() or MatchList['_']
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function Enum:MatchOnThread(Result: string, MatchList: MatchList_f): (boolean, MatchResult)
|
||||
return coroutine.resume(coroutine.create(function()
|
||||
return self:Match(Result, MatchList)
|
||||
end))
|
||||
end
|
||||
end
|
||||
|
||||
function CustomEnum.Create(Name, EnumValue)
|
||||
CustomEnum.Enums[Name] = EnumValue
|
||||
|
||||
local Enum = CustomEnum.Enums[Name]
|
||||
EnumMethods(Enum)
|
||||
|
||||
return Enum
|
||||
end
|
||||
|
||||
function CustomEnum.Remove(Name)
|
||||
if CustomEnum.Enums[Name] then
|
||||
CustomEnum.Enums[Name] = nil
|
||||
else
|
||||
warn(`Enum: attempt to remove an Enum that does not exist "{Name}".`, debug.traceback())
|
||||
end
|
||||
end
|
||||
|
||||
return CustomEnum
|
||||
Reference in New Issue
Block a user