This commit is contained in:
2024-03-11 02:17:24 -04:00
parent df86e6efb6
commit fc1f2bd9ee
2 changed files with 89 additions and 17 deletions

View File

@@ -0,0 +1,82 @@
--!optimize 2
--!native
--!strict
type GetButtons = {[string]: Instance}
type ButtonTypes = {
Landing: GetButtons,
Car: GetButtons,
Special: GetButtons,
Unknown: GetButtons
}
local ButtonTags = {}
ButtonTags.__index = ButtonTags
function ButtonTags.constructor(Tags, Model)
return setmetatable({
Tags = Tags,
Model = Model
}, ButtonTags)
end
function ButtonTags:Get()
local Buttons: GetButtons = {}
for TagName: string, Inst: Instance in self.Tags do
local Split = TagName:split('_')
if Split[1] == self.Model and Split[2] == "ElevatorButton" then
Buttons[TagName] = Inst
end
end
return Buttons
end
function ButtonTags:CreatePromptButtons()
local ModelButtons = self:Get()
local Buttons: ButtonTypes = {
Landing = {},
Car = {},
Special = {},
Unknown = {}
}
for TagName: string, Inst: Instance in ModelButtons do
local Attachment = Instance.new("Attachment") :: Attachment
Attachment.Parent = Inst
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
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 = tonumber(Split[3]) and "CarButton" or (Split[3] == "Floor" and Split[4]:match('%d')) and "LandingButton" or Split[3] and "SpecialButton"
if ButtonType == "CarButton" then
--ElevatorButton_1
Buttons.Car[`{Split[2]}_{Split[3]}`] = Inst
Prompt.ActionText = tostring(Split[3])
Prompt.ObjectText = "Floor"
elseif ButtonType == "LandingButton" then
--ElevatorButton_Floor_1_Up
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = Inst
Prompt.ActionText = tostring(Split[5])
Prompt.ObjectText = `Floor {tostring(Split[4])}`
elseif ButtonType == "SpecialButton" then
--ElevatorButton_Open
else
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
return Buttons
end
return ButtonTags

View File

@@ -9,7 +9,9 @@ local TagsModule = require(RS:WaitForChild("Tags"))
local Leveling = require(script:WaitForChild("Leveling"))
local Doors = require(script:WaitForChild("Doors"))
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
local ButtonTags = require(Elevators:WaitForChild("Buttons"))
type Tags = TagsModule.ExportedTags
@@ -39,20 +41,6 @@ type Constructor_Return_Props = {
local Otis1960 = {} :: Impl_Constructor
Otis1960.__index = Otis1960
local function PromptButtons(self: Constructor_Return_Props)
for i: number = 1, #self.ProximityButtons do
local Button = self.ProximityButtons[i]
local Attachment = Instance.new("Attachment") :: Attachment
Attachment.Parent = Button
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
Prompt.MaxActivationDistance = 3
Prompt.Parent = Attachment
print(`Created a ProximityPrompt @ "{Button:GetFullName()}"`)
end
end
function Otis1960.constructor(Tags)
local self = {} :: Constructor_Return_Props
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: BasePart
@@ -65,15 +53,17 @@ function Otis1960.constructor(Tags)
self.BoxAttachment, self.BoxAlignPosition, self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position)
self.ElevatorDoors = Doors.constructor(self.ElevatorBox, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
PromptButtons(self)
print("Otis1960 initialized and ready")
--Buttons
local Buttons = ButtonTags.constructor(Tags, "Otis1960")
local Otis1960_Buttons = Buttons:CreatePromptButtons()
print("[DEBUG] Otis1960 Buttons=", Otis1960_Buttons)
print("🔝 Otis1960 initialized and ready")
return setmetatable(self, Otis1960)
end
function Otis1960:MoveFloors(Level)
local ElevatorBoxCurrentPos = self.ElevatorBox.Position
--Its gonna use raycasting inside of the shaft to detect when its near and when to stop
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, Level, ElevatorBoxCurrentPos.Z)
end