mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
Buttons algorithm work
This commit is contained in:
@@ -2,44 +2,98 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type GetButtons = {[string]: Instance}
|
||||
type ButtonTypes = {
|
||||
Landing: GetButtons,
|
||||
Car: GetButtons,
|
||||
Special: GetButtons,
|
||||
Unknown: GetButtons
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
|
||||
type GetButtons = {
|
||||
[string]: Instance
|
||||
}
|
||||
type ButtonTree = {
|
||||
Inst: Instance,
|
||||
Prompt: ProximityPrompt
|
||||
}
|
||||
type ButtonsTree = {
|
||||
Landing: ButtonTree,
|
||||
Car: ButtonTree,
|
||||
Special: ButtonTree,
|
||||
Unknown: {
|
||||
Inst: Instance,
|
||||
Prompt: ProximityPrompt?
|
||||
}
|
||||
}
|
||||
|
||||
local ButtonTags = {}
|
||||
ButtonTags.__index = ButtonTags
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Get: (self: ClassConstructor) -> GetButtons,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> ButtonsTree,
|
||||
HookPromptButtonsGroup: (self: ClassConstructor) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
function ButtonTags.constructor(Tags, Model)
|
||||
type Impl_Static_Props = {
|
||||
ButtonEnum: ButtonsEnum
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags, Model: string) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
Model: string
|
||||
}
|
||||
|
||||
export type ButtonsEnum = {
|
||||
Car: string,
|
||||
Landing: string,
|
||||
Special: string,
|
||||
Unknown: string
|
||||
}
|
||||
|
||||
local ButtonsModule = {} :: Impl_Constructor
|
||||
ButtonsModule.__index = ButtonsModule
|
||||
|
||||
ButtonsModule.ButtonEnum = {
|
||||
Car = "CarButton",
|
||||
Landing = "LandingButton",
|
||||
Special = "SpecialButton",
|
||||
Unknown = "UnknownButton"
|
||||
}
|
||||
|
||||
function ButtonsModule.constructor(Tags, Model)
|
||||
return setmetatable({
|
||||
Tags = Tags,
|
||||
Model = Model
|
||||
}, ButtonTags)
|
||||
}, ButtonsModule)
|
||||
end
|
||||
|
||||
function ButtonTags:Get()
|
||||
--Button parsing
|
||||
|
||||
function ButtonsModule:Get()
|
||||
local Buttons: GetButtons = {}
|
||||
|
||||
for TagName: string, Inst: Instance in self.Tags do
|
||||
for TagName: string, Inst: Instance | {Instance} in self.Tags do
|
||||
local Split = TagName:split('_')
|
||||
if Split[1] == self.Model and Split[2] == "ElevatorButton" then
|
||||
Buttons[TagName] = Inst
|
||||
if typeof(Inst) == "Instance" then
|
||||
Buttons[TagName] = Inst
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
return Buttons
|
||||
end
|
||||
|
||||
function ButtonTags:CreatePromptButtons()
|
||||
function ButtonsModule:CreatePromptButtons()
|
||||
local ModelButtons = self:Get()
|
||||
local Buttons: ButtonTypes = {
|
||||
local Buttons = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Unknown = {}
|
||||
}
|
||||
} :: ButtonsTree
|
||||
|
||||
for TagName: string, Inst: Instance in ModelButtons do
|
||||
local Attachment = Instance.new("Attachment") :: Attachment
|
||||
@@ -52,24 +106,40 @@ function ButtonTags:CreatePromptButtons()
|
||||
--CarButton = Model_ElevatorButton_1
|
||||
--LandingButton = Model_ElevatorButton_Floor_1_Up
|
||||
--SpecialButton = Model_ElevatorButton_Open
|
||||
local ButtonType = tonumber(Split[3]) and "CarButton" or (Split[3] == "Floor" and Split[4]:match('%d')) and "LandingButton" or Split[3] and "SpecialButton"
|
||||
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
|
||||
|
||||
if ButtonType == "CarButton" then
|
||||
if ButtonType == ButtonsModule.ButtonEnum.Car then
|
||||
--ElevatorButton_1
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = Inst
|
||||
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == "LandingButton" then
|
||||
elseif ButtonType == ButtonsModule.ButtonEnum.Landing then
|
||||
--ElevatorButton_Floor_1_Up
|
||||
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = Inst
|
||||
|
||||
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 == "SpecialButton" then
|
||||
elseif ButtonType == ButtonsModule.ButtonEnum.Special then
|
||||
--ElevatorButton_Open
|
||||
|
||||
else
|
||||
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
|
||||
|
||||
@@ -79,4 +149,8 @@ function ButtonTags:CreatePromptButtons()
|
||||
return Buttons
|
||||
end
|
||||
|
||||
return ButtonTags
|
||||
function ButtonsModule:HookPromptButtonsGroup()
|
||||
|
||||
end
|
||||
|
||||
return ButtonsModule
|
||||
Reference in New Issue
Block a user