48 lines
940 B
Lua
48 lines
940 B
Lua
-- @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
|
|
|
|
|