43 lines
835 B
Plaintext
43 lines
835 B
Plaintext
-- @shared
|
|
-- @name Animated light
|
|
-- @include ../../helpers/helpers.txt
|
|
require("../helpers/helpers.txt")
|
|
|
|
-- this entity implements composite pattern
|
|
AnimatedLight = class("AnimatedLight")
|
|
|
|
function AnimatedLight:new(cfg)
|
|
self.keyframes = cfg.keyframes
|
|
|
|
end
|
|
|
|
|
|
function AnimatedLight:_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 AnimatedLight:setActive(val)
|
|
self.active = val
|
|
end
|
|
|
|
|
|
function AnimatedLight:use(val)
|
|
self.target = val or 0
|
|
end
|
|
|
|
|
|
function AnimatedLight:update()
|
|
self:_process()
|
|
end
|
|
|
|
|