--!optimize 2 --!strict local Elevators = script.Parent.Parent.Parent local Main = Elevators.Parent local Storage = game:GetService("ReplicatedStorage") local Enums = require(Storage:WaitForChild("Enums")) local Map = Main:WaitForChild("Map") local PromptModule = require(Map:WaitForChild("Prompts")) local Tags = require(Map:WaitForChild("Load"):WaitForChild("Tags")) type FloorButtonActivatedCallback = (ButtonFloor: number) -> () type StopButtonActivatedCallback = (Toggled: boolean) -> () type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, --Class functions CarButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedCallback) -> (), LandingButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedCallback) -> (), SpecialButton: (self: ClassConstructor, ButtonName: Enums.SpecialButtonValues, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: StopButtonActivatedCallback) -> (), } type Constructor_Fun = (CurrentFloor: IntValue) -> ClassConstructor type Constructor_Return_Props = { CurrentFloor: IntValue } export type ButtonsConstructor = ClassConstructor local ButtonFunctions = {} :: Impl_Constructor ButtonFunctions.__index = ButtonFunctions --ButtonTags.ButtonsConstructor function ButtonFunctions.constructor(CurrentFloor) return setmetatable({CurrentFloor = CurrentFloor}, ButtonFunctions) end function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback, Fallback) local DecodedCarFloorTag = Tags.Decoders.CarTag(ButtonID) if DecodedCarFloorTag then local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance) Prompt:Triggered(function(Player: Player, _, __) if DecodedCarFloorTag == self.CurrentFloor.Value then Fallback(DecodedCarFloorTag) else Callback(DecodedCarFloorTag) end end) end end function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback, Fallback) local DecodedHallFloorTag = Tags.Decoders.HallTag(ButtonID) if DecodedHallFloorTag then local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance) Prompt:Triggered(function(Player: Player, _, __) if DecodedHallFloorTag == self.CurrentFloor.Value then Fallback(DecodedHallFloorTag) else Callback(DecodedHallFloorTag) end end) end end function ButtonFunctions:SpecialButton(ButtonID, ButtonName, ButtonTree, Callback) --precomputing speed if ButtonID == Enums.SpecialButton.Stop then local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance) local Toggled = false Prompt:Triggered(function(Player: Player, _, __) Toggled = not Toggled Callback(Toggled) end) else warn(``) end end return ButtonFunctions