Forgot staged files
This commit is contained in:
47
koptilnya/car_systems/entities/light.txt
Normal file
47
koptilnya/car_systems/entities/light.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
-- @shared
|
||||
-- @name Light
|
||||
-- @include ../helpers/helpers.txt
|
||||
require("../helpers/helpers.txt")
|
||||
|
||||
Light = class("Light")
|
||||
|
||||
function Light:initialize(params)
|
||||
self.target = 0
|
||||
self.entity = params.Entity
|
||||
self.colors = params.Colors
|
||||
self.lerpSpeed = params.LerpSpeed or 0.2
|
||||
self.active = false
|
||||
|
||||
self.entity:setColor(self.colors.Off)
|
||||
self.entity:suppressEngineLighting(true)
|
||||
end
|
||||
|
||||
|
||||
function Light:_process()
|
||||
local targetColor = self.colors.Off
|
||||
|
||||
if self.active == true and self.colors.Active then
|
||||
targetColor = self.target > 0 and self.colors.On or self.colors.Active
|
||||
elseif self.target > 0 then
|
||||
targetColor = self.colors.On
|
||||
end
|
||||
|
||||
self.entity:setColor(lerpColor(self.lerpSpeed, self.entity:getColor(), targetColor))
|
||||
end
|
||||
|
||||
|
||||
function Light:setActive(val)
|
||||
self.active = val
|
||||
end
|
||||
|
||||
|
||||
function Light:use(val)
|
||||
self.target = val or 0
|
||||
end
|
||||
|
||||
|
||||
function Light:update()
|
||||
self:_process()
|
||||
end
|
||||
|
||||
|
||||
11
koptilnya/car_systems/helpers/helpers.txt
Normal file
11
koptilnya/car_systems/helpers/helpers.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
function lerpColor(t, from, to)
|
||||
local clampedT = math.clamp(t, 0, 1)
|
||||
local outColor = Color(0, 0, 0, 0)
|
||||
|
||||
outColor.r = math.lerp(t, from.r, to.r)
|
||||
outColor.g = math.lerp(t, from.g, to.g)
|
||||
outColor.b = math.lerp(t, from.b, to.b)
|
||||
outColor.a = math.lerp(t, from.a, to.a)
|
||||
|
||||
return outColor
|
||||
end
|
||||
119
koptilnya/car_systems/lights_controller.txt
Normal file
119
koptilnya/car_systems/lights_controller.txt
Normal file
@@ -0,0 +1,119 @@
|
||||
-- @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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user