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