Light module

This commit is contained in:
2024-04-18 15:59:55 -04:00
parent 9e94d56a9f
commit a9391feb87
3 changed files with 87 additions and 79 deletions

View File

@@ -5,7 +5,12 @@
local MapDir = script.Parent local MapDir = script.Parent
local MainDir = MapDir.Parent local MainDir = MapDir.Parent
local TagService = require(MainDir:WaitForChild("Tags")) local Storage = game:GetService("ReplicatedStorage")
local TagService = require(MainDir:WaitForChild("Tags"))
local TweenModule = require(Storage:WaitForChild("Tween"))
local PromptsConstructor = require(MapDir:WaitForChild("Prompts"))
type LightCallback = (Player: Player) -> () type LightCallback = (Player: Player) -> ()
@@ -14,9 +19,11 @@ type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
AddHook: (self: ClassConstructor, Callback: LightCallback) -> (), Create: (self: ClassConstructor) -> (),
Enable: (self: ClassConstructor) -> (), } & Impl_Static_Props
Disable: (self: ClassConstructor) -> ()
type Impl_Static_Props = {
SwitchAnimationTime: number
} }
type Constructor_Fun = (LightSwitches: TagService.LightSwitchTree) -> ClassConstructor type Constructor_Fun = (LightSwitches: TagService.LightSwitchTree) -> ClassConstructor
@@ -24,25 +31,83 @@ type Constructor_Return_Props = {
LightSwitches: TagService.LightSwitchTree LightSwitches: TagService.LightSwitchTree
} }
export type LightProperties = TagService.LightSwitchProperties
local Lights = {} :: Impl_Constructor local Lights = {} :: Impl_Constructor
Lights.__index = Lights Lights.__index = Lights
Lights.SwitchAnimationTime = .1
local LightSwitchTween = TweenModule.constructor(TweenInfo.new(Lights.SwitchAnimationTime, Enum.EasingStyle.Linear))
function Lights.constructor(LightSwitches) function Lights.constructor(LightSwitches)
return setmetatable({ return setmetatable({
LightSwitches = LightSwitches LightSwitches = LightSwitches
}, Lights) }, Lights)
end end
function Lights:AddHook(Callback) local function ToggleSwitchLight(EnabledState: boolean, LightObject: BasePart, LightProperties: LightProperties)
local Light = LightObject:FindFirstChildWhichIsA("PointLight", true) or LightObject:FindFirstChildWhichIsA("SpotLight", true)
if Light then
Light.Enabled = EnabledState
end
if EnabledState then
if LightProperties.ColorActivated then
LightObject.Color = LightProperties.ColorActivated
LightObject.Material = Enum.Material.Neon
end
else
if LightProperties.ColorDeactivated then
LightObject.Color = LightProperties.ColorDeactivated
LightObject.Material = Enum.Material.SmoothPlastic
end
end
end end
function Lights:Enable() local function SwitchAnimation(EnabledState: boolean, LightProperties: LightProperties)
local Switch = LightProperties.Switch
if Switch then
if EnabledState then
LightSwitchTween:Start(Switch, {
CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),0)+Vector3.new(0,.15,0)
})
else
LightSwitchTween:Start(Switch, {
CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),math.rad(70))-Vector3.new(0,.15,0)
})
end
end
end end
function Lights:Disable() --[[
Guide for lights with toggable switches:
TODO
]]
function Lights:Create()
for _, LightProperties in self.LightSwitches do
if LightProperties.Prompt and LightProperties.Switch then
local Prompt = PromptsConstructor.constructor(LightProperties.Prompt, LightProperties.Switch)
local EnabledState = false
if LightProperties.ColorDeactivated and LightProperties.ColorActivated and LightProperties.Prompt and LightProperties.Lights then
Prompt:AddHookTriggered(function(_Player: Player)
EnabledState = not EnabledState
SwitchAnimation(EnabledState, LightProperties)
if LightProperties.ClickSound then
LightProperties.ClickSound:Play()
end
for n: number = 1, #LightProperties.Lights do
ToggleSwitchLight(EnabledState, LightProperties.Lights[n], LightProperties)
end
end)
else
warn(`Prompt failed`)
end
end
end
end end
return Lights return Lights

View File

@@ -2,16 +2,18 @@
--!native --!native
--!strict --!strict
type PromptCallback = (Player: Player) -> () type PromptCallback = (Player: Player) -> ()
type HumanoidRootPart = BasePart type HumanoidRootPart = BasePart
type PromptSignal = RBXScriptSignal<Player>
type PromptSignalName = "Triggered" | "TriggerEnded"
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = { type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
AddHookTriggered: (self: ClassConstructor, Callback: PromptCallback) -> (), AddHookTriggered: (self: ClassConstructor, Callback: PromptCallback) -> PromptSignal?,
AddHookTriggerEnded: (self: ClassConstructor, Callback: PromptCallback) -> (), AddHookTriggerEnded: (self: ClassConstructor, Callback: PromptCallback) -> PromptSignal?,
Enable: (self: ClassConstructor) -> (), Enable: (self: ClassConstructor) -> (),
Disable: (self: ClassConstructor) -> () Disable: (self: ClassConstructor) -> ()
} }
@@ -29,9 +31,6 @@ type Constructor_Return_Props = {
}, },
} }
type PromptSignal = RBXScriptSignal<Player>
type PromptSignalName = "Triggered" | "TriggerEnded"
local Prompts = {} :: Impl_Constructor local Prompts = {} :: Impl_Constructor
Prompts.__index = Prompts Prompts.__index = Prompts
@@ -67,6 +66,8 @@ local EnumPromptSignals = {
--This is overly automated lol --This is overly automated lol
local function NewPromptConnection(self: ClassConstructor, PromptSignal: PromptSignal, PromptSignalName: PromptSignalName) local function NewPromptConnection(self: ClassConstructor, PromptSignal: PromptSignal, PromptSignalName: PromptSignalName)
local Signal: PromptSignal?
if self.Prompt then if self.Prompt then
if self.Instance then if self.Instance then
if self.__PromptConnections[PromptSignalName] and self.__PromptConnections[PromptSignalName].Connected then if self.__PromptConnections[PromptSignalName] and self.__PromptConnections[PromptSignalName].Connected then
@@ -76,25 +77,28 @@ local function NewPromptConnection(self: ClassConstructor, PromptSignal: PromptS
self.__PromptConnections[PromptSignalName] = PromptSignal:Connect(function(Player: Player) self.__PromptConnections[PromptSignalName] = PromptSignal:Connect(function(Player: Player)
EnumPromptSignals[PromptSignalName](self, Player) EnumPromptSignals[PromptSignalName](self, Player)
end) end)
Signal = self.__PromptConnections[PromptSignalName]
else else
warn("Button Hook Error! Inst is missing", debug.traceback()) warn("Button Hook Error! Inst is missing", debug.traceback())
end end
else else
warn("Button Hook Error! Prompt is missing", debug.traceback()) warn("Button Hook Error! Prompt is missing", debug.traceback())
end end
return Signal
end end
function Prompts:AddHookTriggered(Callback) function Prompts:AddHookTriggered(Callback)
self.__TriggeredCallback = Callback self.__TriggeredCallback = Callback
--These dont make sense... --These dont make sense...
NewPromptConnection(self, self.Prompt.Triggered, "Triggered") return NewPromptConnection(self, self.Prompt.Triggered, "Triggered")
end end
function Prompts:AddHookTriggerEnded(Callback) function Prompts:AddHookTriggerEnded(Callback)
self.__TriggerEndedCallback = Callback self.__TriggerEndedCallback = Callback
NewPromptConnection(self, self.Prompt.TriggerEnded, "TriggerEnded") return NewPromptConnection(self, self.Prompt.TriggerEnded, "TriggerEnded")
end end
function Prompts:Disable() function Prompts:Disable()
@@ -111,10 +115,10 @@ end
function Prompts:Enable() function Prompts:Enable()
self.Prompt.Enabled = true self.Prompt.Enabled = true
if self.__TriggeredCallback then if self.__TriggeredCallback and not (self.__PromptConnections.Triggered and self.__PromptConnections.Triggered.Connected) then
self:AddHookTriggered(self.__TriggeredCallback) self:AddHookTriggered(self.__TriggeredCallback)
end end
if self.__TriggerEndedCallback then if self.__TriggerEndedCallback and not (self.__PromptConnections.TriggerEnded and self.__PromptConnections.TriggerEnded.Connected) then
self:AddHookTriggerEnded(self.__TriggerEndedCallback) self:AddHookTriggerEnded(self.__TriggerEndedCallback)
end end
end end

View File

@@ -10,10 +10,6 @@ local Enums = require(Storage:WaitForChild("Enums"))
local Elevators = script:WaitForChild("Elevators") local Elevators = script:WaitForChild("Elevators")
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960")) local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
local Map = script:WaitForChild("Map")
local LightSwitchesConstructor = require(Map:WaitForChild("LightSwitches"))
local PromptsConstructor = require(Map:WaitForChild("Prompts"))
local TagsModule = require(script:WaitForChild("Tags")) local TagsModule = require(script:WaitForChild("Tags"))
local HideEditorEntities = require(script:WaitForChild("EditorEntities")) local HideEditorEntities = require(script:WaitForChild("EditorEntities"))
local Lighting_Stuff = require(script:WaitForChild("Lighting")) local Lighting_Stuff = require(script:WaitForChild("Lighting"))
@@ -30,67 +26,10 @@ StarterPlayer_Stuff()
Lighting_Stuff() Lighting_Stuff()
Workspace_Stuff() Workspace_Stuff()
--Map --Map
local Interactables = TagsConstructor:__Interactables() local Interactables = TagsConstructor:__Interactables()
print("[DEBUG] Interactables=", Interactables) print("[DEBUG] Interactables=", Interactables)
--Temporary
--[[
Guide for lights with toggable switches:
TODO
]]
local TweenModule = require(Storage:WaitForChild("Tween"))
local LightSwitchTween = TweenModule.constructor(TweenInfo.new(.1, Enum.EasingStyle.Linear))
for _, LightProperties in Interactables.LightSwitches do
if LightProperties.Prompt and LightProperties.Switch then
local Prompt = PromptsConstructor.constructor(LightProperties.Prompt, LightProperties.Switch)
local LightEnabled = false
if LightProperties.ColorDeactivated and LightProperties.ColorActivated and LightProperties.Prompt and LightProperties.Lights then
Prompt:AddHookTriggered(function(_Player: Player)
LightEnabled = not LightEnabled
local Switch = LightProperties.Switch
if LightEnabled then
LightSwitchTween:Start(Switch, {
CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),0)+Vector3.new(0,.15,0)
})
else
LightSwitchTween:Start(Switch, {
CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),math.rad(70))-Vector3.new(0,.15,0)
})
end
if LightProperties.ClickSound then
LightProperties.ClickSound:Play()
end
for n: number = 1, #LightProperties.Lights do
local LightObj = LightProperties.Lights[n]
local Light = LightObj:FindFirstChildWhichIsA("PointLight", true) or LightObj:FindFirstChildWhichIsA("SpotLight", true)
if Light then
Light.Enabled = LightEnabled
end
if LightEnabled then
LightObj.Color = LightProperties.ColorActivated
LightObj.Material = Enum.Material.Neon
else
LightObj.Color = LightProperties.ColorDeactivated
LightObj.Material = Enum.Material.SmoothPlastic
end
end
end)
else
warn("failed")
end
end
end
--
--local LightSwitches = LightSwitchesConstructor.constructor(Interactables.LightSwitches)
--Start the elevators --Start the elevators
local Buttons = TagsConstructor:__ElevatorButtons() local Buttons = TagsConstructor:__ElevatorButtons()
print("[DEBUG] Buttons=", Buttons) print("[DEBUG] Buttons=", Buttons)