Files
Roblox-Elevator-Game/src/server/main/Elevators/Lanterns.lua

156 lines
4.4 KiB
Lua

--!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"))
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, ChimeDirectionID: rbxassetid, ChimeLandingID: rbxassetid, Lanterns: Tags.Lanterns, Colors: Colors) -> ClassConstructor
type Constructor_Return_Props = {
LanternsMap: Tags.Lanterns,
AudioChimeDirection: Sound,
AudioChimeLanding: Sound,
Colors: Colors
}
export type Colors = {
Active: Color3,
Off: Color3
}
export type LanternsConstructor = ClassConstructor
local Lanterns = {} :: Impl_Constructor
Lanterns.__index = Lanterns
Lanterns.Volume = .5
Lanterns.LightTweenTime = 1
function Lanterns.constructor(MainDisplay, ChimeDirectionID, ChimeLandingID, LanternsMap, Colors)
local AudioChimeDirection = Instance.new("Sound") :: Sound
AudioChimeDirection.SoundId = ChimeDirectionID
AudioChimeDirection.Volume = Lanterns.Volume
local AudioChimeLanding = Instance.new("Sound") :: Sound
AudioChimeLanding.SoundId = ChimeLandingID
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.Active or self.Colors.Off
})
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.Active
})
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 f = self.LanternsMap[Floor]
if not Enabled then
f.Played = false
end
if not f.Played then
f.Played = true
self:Activate(Enabled, false, f, true)
end
end
return Lanterns