--!optimize 2 --!native --!strict local ElevatorDir = script.Parent local MainDir = ElevatorDir.Parent local LoadDir = MainDir:WaitForChild("Load") local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") local Tween = require(Storage:WaitForChild("Tween")) local Tags = require(LoadDir:WaitForChild("Tags")) local Enums = require(Storage:WaitForChild("Enums")) local SoundEnums = require(MainDir:WaitForChild("Enums"):WaitForChild("Sounds")) type rbxassetid = string type TagProduct = Tags.TagProduct type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, Get: (Tags: Tags.TagsConstructor, Model: Enums.ElevatorValues) -> Tags.Lanterns, --Class functions Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Tags.Lantern, Chime: boolean) -> (), DirectionUp: (self: ClassConstructor, Enabled: boolean) -> (), DirectionDown: (self: ClassConstructor, Enabled: boolean) -> (), Toggle: (self: ClassConstructor, Enabled: boolean, Floor: number) -> (), Reset: (self: ClassConstructor, ExcludeFloor: number?) -> () } & Impl_Static_Props type Impl_Static_Props = { Volume: number, LightTweenTime: number } type Constructor_Fun = (MainDisplay: UnionOperation, LanternsMap: Tags.Lanterns, ElevatorSounds: ElevatorSounds, Colors: ElevatorButtonColors) -> ClassConstructor type Constructor_Return_Props = { LanternsMap: Tags.Lanterns, AudioChimeDirection: Sound, AudioChimeLanding: Sound, Colors: ElevatorButtonColors } type ElevatorAttributes = { PassingFloor: IntValue, Moving: BoolValue, CurrentFloor: IntValue } type ElevatorEvents = { ButtonActivated: BindableEvent } type ElevatorButtonColors = { ButtonActivated: Color3, ButtonDeactivated: Color3, LanternDisplayOn: Color3, LanternDisplayOff: Color3, } type ElevatorSounds = { LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection, LanternChimeLanding: SoundEnums.Otis1960LanternChimeLanding, } export type LanternsConstructor = ClassConstructor local Lanterns = {} :: Impl_Constructor Lanterns.__index = Lanterns Lanterns.Volume = .5 Lanterns.LightTweenTime = 1 function Lanterns.constructor(MainDisplay, LanternsMap, ElevatorSounds, Colors) local AudioChimeDirection = Instance.new("Sound") :: Sound AudioChimeDirection.SoundId = ElevatorSounds.LanternChimeDirection AudioChimeDirection.Volume = Lanterns.Volume local AudioChimeLanding = Instance.new("Sound") :: Sound AudioChimeLanding.SoundId = ElevatorSounds.LanternChimeLanding AudioChimeLanding.Volume = Lanterns.Volume AudioChimeDirection.Parent = MainDisplay AudioChimeLanding.Parent = MainDisplay return setmetatable({ LanternsMap = LanternsMap, AudioChimeDirection = AudioChimeDirection, AudioChimeLanding = AudioChimeLanding, Colors = Colors }, Lanterns) end local LanternLight = Tween.constructor(TweenInfo.new(Lanterns.LightTweenTime)) function Lanterns:Activate(EnabledState, IsDirectionLantern, Lantern, Chime) local Tween = LanternLight:Start(Lantern.Light, { Color = EnabledState and self.Colors.LanternDisplayOn or self.Colors.LanternDisplayOff }) if EnabledState then if Chime then if IsDirectionLantern then self.AudioChimeDirection:Play() else Tween.Completed:Once(function() self.AudioChimeLanding:Play() end) end end if Lantern.PointLight then Lantern.PointLight.Enabled = true LanternLight:Start(Lantern.PointLight, { Color = self.Colors.LanternDisplayOn }) end else if Lantern.PointLight then local LightTween = LanternLight:Start(Lantern.PointLight, { Color = Color3.new(0,0,0) }) LightTween.Completed:Once(function() Lantern.PointLight.Enabled = false end) end end end function Lanterns:Reset(ExcludeFloor) if self.LanternsMap.Up then self.LanternsMap.Up.Played = false self:Activate(false, true, self.LanternsMap.Up, true) end if self.LanternsMap.Down then self.LanternsMap.Down.Played = false self:Activate(false, true, self.LanternsMap.Down, true) end for n: number = 1, #self.LanternsMap do local Lantern = self.LanternsMap[n] self:Activate(ExcludeFloor and n == ExcludeFloor or false, false, Lantern, false) Lantern.Played = false end end function Lanterns:DirectionUp(Enabled) if self.LanternsMap.Up and not self.LanternsMap.Up.Played then self.LanternsMap.Up.Played = true self:Activate(Enabled, true, self.LanternsMap.Up, true) end end function Lanterns:DirectionDown(Enabled) if self.LanternsMap.Down and not self.LanternsMap.Down.Played then self.LanternsMap.Down.Played = true self:Activate(Enabled, true, self.LanternsMap.Down, true) end end function Lanterns:Toggle(Enabled, Floor) local FloorLantern = self.LanternsMap[Floor] if FloorLantern then if not Enabled then FloorLantern.Played = false end if not FloorLantern.Played then FloorLantern.Played = true self:Activate(Enabled, false, FloorLantern, true) end else warn(`Floor Lantern does not exist for floor: {Floor}`, debug.traceback()) end end return Lanterns