mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 22:21:55 +00:00
move lanterns directory into system
This commit is contained in:
63
src/server/main/Elevators/System/Lanterns/Arrows.luau
Normal file
63
src/server/main/Elevators/System/Lanterns/Arrows.luau
Normal file
@@ -0,0 +1,63 @@
|
||||
--!optimize 2
|
||||
--!strict
|
||||
|
||||
local MainDir = script.Parent.Parent.Parent
|
||||
local TagsModule = require(MainDir:WaitForChild("Map"):WaitForChild("Load"):WaitForChild("Tags"))
|
||||
local ElevatorTypes = require(MainDir:WaitForChild("Types"):WaitForChild("Elevator"))
|
||||
|
||||
local TS = game:GetService("TweenService")
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Toggle: (self: ClassConstructor, OnState: boolean, UpDirection: boolean) -> Tween?,
|
||||
Off: (self: ClassConstructor) -> (Tween?, Tween?),
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Lanterns: TagsModule.Lanterns, ElevatorConfig: ElevatorTypes.ElevatorConfigurationTable) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Lanterns: TagsModule.Lanterns,
|
||||
ElevatorConfig: ElevatorTypes.ElevatorConfigurationTable
|
||||
}
|
||||
|
||||
local ArrowLanterns = {} :: Impl_Constructor
|
||||
ArrowLanterns.__index = ArrowLanterns
|
||||
|
||||
function ArrowLanterns.constructor(Lanterns, ElevatorConfig)
|
||||
return setmetatable({
|
||||
Lanterns = Lanterns,
|
||||
ElevatorConfig = ElevatorConfig
|
||||
}, ArrowLanterns)
|
||||
end
|
||||
|
||||
function ArrowLanterns:Toggle(OnState, UpDirection)
|
||||
local LanternType = UpDirection and self.Lanterns.Up or self.Lanterns.Down
|
||||
if LanternType then
|
||||
--mega boolean short circuit
|
||||
local ConfigState = OnState and (UpDirection and self.ElevatorConfig.Lanterns.On.Up or self.ElevatorConfig.Lanterns.On.Down) or (UpDirection and self.ElevatorConfig.Lanterns.Off.Up or self.ElevatorConfig.Lanterns.Off.Down)
|
||||
|
||||
LanternType.Inst.Material = ConfigState.Material
|
||||
|
||||
local TweenTime = TweenInfo.new(ConfigState.Time)
|
||||
local UpArrowTween = TS:Create(LanternType.Inst, TweenTime, {
|
||||
Color = ConfigState.Color
|
||||
})
|
||||
UpArrowTween:Play()
|
||||
TS:Create(LanternType.PointLight, TweenTime, {
|
||||
Brightness = OnState and 1 or 0
|
||||
}):Play()
|
||||
|
||||
return UpArrowTween
|
||||
else
|
||||
warn(`[{self.ElevatorConfig.Name}]: Could not toggle a direction lantern. UpDirection={UpDirection} OnState={OnState}, LaternType={LanternType}`)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function ArrowLanterns:Off()
|
||||
return self:Toggle(false, true), self:Toggle(false, false)
|
||||
end
|
||||
|
||||
return ArrowLanterns
|
||||
178
src/server/main/Elevators/System/Lanterns/Display.luau
Normal file
178
src/server/main/Elevators/System/Lanterns/Display.luau
Normal file
@@ -0,0 +1,178 @@
|
||||
--!optimize 2
|
||||
--!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
|
||||
Reference in New Issue
Block a user