mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-16 06:01:54 +00:00
new switch statement for Enums like Rust
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Elevators = script.Parent
|
||||
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
|
||||
type GetButtons = {
|
||||
[string]: Instance
|
||||
}
|
||||
type GetButtons = {[string]: Instance}
|
||||
type ButtonTree = {
|
||||
Inst: Instance,
|
||||
Prompt: ProximityPrompt
|
||||
@@ -35,7 +36,7 @@ type Impl_Constructor = {
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
ButtonEnum: ButtonsEnum
|
||||
ButtonEnum: any
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags, Model: string) -> ClassConstructor
|
||||
@@ -54,12 +55,7 @@ export type ButtonsEnum = {
|
||||
local ButtonsModule = {} :: Impl_Constructor
|
||||
ButtonsModule.__index = ButtonsModule
|
||||
|
||||
ButtonsModule.ButtonEnum = {
|
||||
Car = "CarButton",
|
||||
Landing = "LandingButton",
|
||||
Special = "SpecialButton",
|
||||
Unknown = "UnknownButton"
|
||||
}
|
||||
local ButtonsEnum = Enums.ButtonsEnum
|
||||
|
||||
function ButtonsModule.constructor(Tags, Model)
|
||||
return setmetatable({
|
||||
@@ -102,46 +98,52 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.MaxActivationDistance = 3
|
||||
Prompt.Parent = Attachment
|
||||
|
||||
local Split = TagName:split('_')
|
||||
--CarButton = Model_ElevatorButton_1
|
||||
--LandingButton = Model_ElevatorButton_Floor_1_Up
|
||||
--SpecialButton = Model_ElevatorButton_Open
|
||||
local ButtonType = if tonumber(Split[3]) then
|
||||
ButtonsModule.ButtonEnum.Car
|
||||
elseif Split[3] == "Floor" and Split[4]:match('%d') then
|
||||
ButtonsModule.ButtonEnum.Landing
|
||||
elseif Split[2] == "ElevatorButton" then
|
||||
ButtonsModule.ButtonEnum.Special
|
||||
else
|
||||
ButtonsModule.ButtonEnum.Unknown
|
||||
local Split = TagName:split('_')
|
||||
local ButtonType = tonumber(Split[3]) and
|
||||
ButtonsEnum.Car
|
||||
or Split[3] == "Floor" and Split[4]:match('%d') and
|
||||
ButtonsEnum.Landing
|
||||
or Split[2] == "ElevatorButton" and
|
||||
ButtonsEnum.Special
|
||||
|
||||
if ButtonType == ButtonsModule.ButtonEnum.Car then
|
||||
--ElevatorButton_1
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == ButtonsModule.ButtonEnum.Landing then
|
||||
--ElevatorButton_Floor_1_Up
|
||||
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
elseif ButtonType == ButtonsModule.ButtonEnum.Special then
|
||||
--ElevatorButton_Open
|
||||
Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == ButtonsModule.ButtonEnum.Unknown then
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
ButtonsEnum:Match(ButtonType, {
|
||||
[ButtonsEnum.Car] = function()
|
||||
--ElevatorButton_1
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
end,
|
||||
|
||||
[ButtonsEnum.Landing] = function()
|
||||
--ElevatorButton_Floor_1_Up
|
||||
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
end,
|
||||
|
||||
[ButtonsEnum.Special] = function()
|
||||
--ElevatorButton_Open
|
||||
Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
end,
|
||||
|
||||
["_"] = function()
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
})
|
||||
|
||||
print(`{self.Model}: created a ProximityPrompt @ "{Inst:GetFullName()}"`)
|
||||
end
|
||||
|
||||
12
src/server/main/Elevators/Enums.lua
Normal file
12
src/server/main/Elevators/Enums.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Enum = require(RS:WaitForChild("Enum"))
|
||||
|
||||
local Enums = {}
|
||||
|
||||
Enums.ButtonsEnum = Enum.Create("Buttons", {
|
||||
Car = "CarButton",
|
||||
Landing = "LandingButton",
|
||||
Special = "SpecialButton",
|
||||
})
|
||||
|
||||
return Enums
|
||||
Reference in New Issue
Block a user