-- @shared -- @name Lights Controller -- @include ./entities/light.txt require("./entities/light.txt") LightsController = class("LightsController") function LightsController:initialize(config) -- self.leftTurnLights = Light:new({ Entity = config.Lights.LeftTurnLights, Colors = config.Colors.TurnLights }) -- self.rightTurnLights = Light:new({ Entity = config.Lights.RightTurnLights, Colors = config.Colors.TurnLights }) self.stopLights = {} self.reverseLights = {} self.highBeamLights = {} self.lowBeamLights = {} self.fogLights = {} if config.StopLights then for _, v in pairs(config.StopLights.Entities) do table.insert(self.stopLights, Light:new({Entity = v, Colors = config.StopLights.Colors, LerpSpeed = config.StopLights.LerpSpeed})) end end if config.ReverseLights then for _, v in pairs(config.ReverseLights.Entities) do table.insert(self.reverseLights, Light:new({Entity = v, Colors = config.ReverseLights.Colors, LerpSpeed = config.StopLights.LerpSpeed})) end end if config.LowBeamLights then for _, v in pairs(config.LowBeamLights.Entities) do table.insert(self.lowBeamLights, Light:new({Entity = v, Colors = config.LowBeamLights.Colors, LerpSpeed = config.StopLights.LerpSpeed})) end end if config.HighBeamLights then for _, v in pairs(config.HighBeamLights.Entities) do table.insert(self.highBeamLights, Light:new({Entity = v, Colors = config.HighBeamLights.Colors, LerpSpeed = config.StopLights.LerpSpeed})) end end if config.FogLights then for _, v in pairs(config.FogLights.Entities) do table.insert(self.fogLights, Light:new({Entity = v, Colors = config.FogLights.Colors, LerpSpeed = config.StopLights.LerpSpeed})) end end -- self.stopLights = Light:new({Entity = config.Lights.StopLights, Colors = config.Colors.StopLights}) -- self.reverseLights = Light:new({Entity = config.Lights.ReverseLights, Colors = config.Colors.ReverseLights}) self.active = false -- self.colors = config.Colors -- self.stopLights:setColor(self.colors.StopLight.Off) -- self.reverseLights:setColor(self.colors.ReverseLights.Off) self.allLights = {} table.add(self.allLights, self.stopLights) table.add(self.allLights, self.reverseLights) table.add(self.allLights, self.lowBeamLights) table.add(self.allLights, self.highBeamLights) table.add(self.allLights, self.fogLights) end function LightsController:useStopLights(on) for _, v in pairs(self.stopLights) do v:use(on) end end function LightsController:useReverseLights(on) for _, v in pairs(self.reverseLights) do v:use(on) end end function LightsController:useLowBeam(on) for _, v in pairs(self.lowBeamLights) do v:use(on) end end function LightsController:useHighBeam(on) for _, v in pairs(self.highBeamLights) do v:use(on) end end function LightsController:setActive(val) if self.active ~= val then local lights = {} table.add(lights, self.lowBeamLights) table.add(lights, self.stopLights) for _, v in pairs(lights) do v:setActive(val) end self.active = val end end function LightsController:update() for _, v in pairs(self.allLights) do v:update() end -- self.stopLights:update() -- self.reverseLights:update() end