Implementing light system

This commit is contained in:
Иван Грачёв 2021-06-06 21:55:19 +05:00
parent 9ff9b08a42
commit bacc7c617f

View File

@ -0,0 +1,42 @@
-- @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