Remove recursive search for light source, add LightSources

This commit is contained in:
2024-04-19 01:23:27 -04:00
parent e76e38bf0f
commit dbda8f9ca6
3 changed files with 38 additions and 15 deletions

View File

@@ -19,7 +19,7 @@ type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Init: (self: ClassConstructor) -> (),
Init: (self: ClassConstructor) -> ()
} & Impl_Static_Props
type Impl_Static_Props = {
@@ -63,6 +63,10 @@ local function ToggleSwitchLight(EnabledState: boolean, LightObject: BasePart, L
end
end
local function SwitchState()
end
local LightSwitchTween = TweenModule.constructor(TweenInfo.new(Lights.SwitchAnimationTime, Enum.EasingStyle.Linear))
local function SwitchAnimation(EnabledState: boolean, LightProperties: LightProperties)
@@ -92,6 +96,14 @@ function Lights:Init()
local EnabledState = false
if LightProperties.ColorDeactivated and LightProperties.ColorActivated and LightProperties.Prompt and LightProperties.Lights then
if LightProperties.Enabled then
LightProperties.Prompt.ActionText = "Toggle Off"
else
LightProperties.Prompt.ActionText = "Toggle On"
end
Prompt:AddHookTriggered(function(_Player: Player)
EnabledState = not EnabledState

View File

@@ -63,10 +63,12 @@ export type LanternsTree = {
export type LightSwitchProperties = {
Switch: BasePart?,
Lights: {BasePart}?,
LightSources: {PointLight | SpotLight}?,
Prompt: ProximityPrompt?,
ClickSound: Sound?,
ColorActivated: Color3?,
ColorDeactivated: Color3?
ColorDeactivated: Color3?,
Enabled: boolean?
}
export type LightSwitchTree = {
@@ -233,8 +235,9 @@ function Tags:__Interactables()
Interactables.LightSwitches[InteractObjectLocation] = {}
end
if InteractType == Enums.Interactables.LightSwitch then
local ptr = Interactables.LightSwitches[InteractObjectLocation]
local ptr = Interactables.LightSwitches[InteractObjectLocation]
if InteractType == Enums.InteractType.LightSwitch then
local itype = type(Inst) == "table"
local Switch = (itype and (Inst :: {Instance})[1] or Inst :: Instance) :: BasePart
if itype then
@@ -244,6 +247,7 @@ function Tags:__Interactables()
local Attachment = Instance.new("Attachment") :: Attachment
Attachment.Parent = Switch
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
Prompt.ObjectText = "Light"
Prompt.MaxActivationDistance = Tags.MaxLightSwitchActivationDistance
Prompt.HoldDuration = Tags.MaxLightSwitchHoldDuration
Prompt.Parent = Attachment
@@ -252,11 +256,12 @@ function Tags:__Interactables()
ClickSound.SoundId = Tags.LightSwitchActivateSoundId
ClickSound.Parent = Switch
local ActivatedColor: Color3 = Switch:GetAttribute("Activated")
local DeactivatedColor: Color3 = Switch:GetAttribute("Deactivated")
local ActivatedColor: Color3 = Switch:GetAttribute("Activated")
local DeactivatedColor: Color3 = Switch:GetAttribute("Deactivated")
local Enabled: boolean = Switch:GetAttribute("Enabled")
if ActivatedColor then
ptr.ColorActivated = ActivatedColor
Switch:SetAttribute("Activated", nil)
print(`LightSwitch: [{Switch}] "Activated" -> "{Switch:GetAttribute("Activated")}"`)
else
@@ -264,7 +269,6 @@ function Tags:__Interactables()
end
if DeactivatedColor then
ptr.ColorDeactivated = DeactivatedColor
Switch:SetAttribute("Deactivated", nil)
print(`LightSwitch: [{Switch}] "Deactivated" -> "{Switch:GetAttribute("Deactivated")}"`)
else
@@ -274,15 +278,20 @@ function Tags:__Interactables()
ptr.Switch = Switch
ptr.Prompt = Prompt
ptr.ClickSound = ClickSound
elseif InteractType == Enums.Interactables.Light then
local ptr = Interactables.LightSwitches[InteractObjectLocation]
ptr.Enabled = Enabled
Switch:SetAttribute("Activated", nil)
Switch:SetAttribute("Deactivated", nil)
Switch:SetAttribute("Enabled", nil)
elseif InteractType == Enums.InteractType.Light then
if type(Inst) == "table" then
ptr.Lights = Inst
else
ptr.Lights = {}
table.insert(ptr.Lights :: {BasePart}, Inst :: BasePart)
end
elseif InteractType == Enums.InteractType.LightSource then
ptr.LightSources = {}
end
end
end

View File

@@ -8,7 +8,7 @@ export type EnumValue = EnumButton | EnumButtonTree | EnumElevator | EnumInterac
export type EnumButton = typeof(Enums.Button)
export type EnumButtonTree = typeof(Enums.ButtonTree)
export type EnumElevator = typeof(Enums.Elevator)
export type EnumInteractables = typeof(Enums.Interactables)
export type EnumInteractables = typeof(Enums.InteractType)
export type ButtonValues = typeof(Enums.Button.Car) |
typeof(Enums.Button.Landing) |
@@ -21,8 +21,9 @@ export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) |
typeof(Enums.ButtonTree.Relays) |
typeof(Enums.ButtonTree.Unknown)
export type InteractablesValues = typeof(Enums.Interactables.LightSwitch) |
typeof(Enums.Interactables.Light)
export type InteractablesValues = typeof(Enums.InteractType.LightSwitch) |
typeof(Enums.InteractType.Light) |
typeof(Enums.InteractType.LightSource)
export type ElevatorValues = typeof(Enums.Elevator.Otis1960)
@@ -45,9 +46,10 @@ Enums.Elevator = {
Otis1960 = "Otis1960" :: "Otis1960"
}
Enums.Interactables = {
Enums.InteractType = {
LightSwitch = "LightSwitch" :: "LightSwitch",
Light = "Light" :: "Light"
Light = "Light" :: "Light",
LightSource = "LightSource" :: "LightSource"
}
return Enums