diff --git a/koptilnya/car_systems/entities/animated_light.txt b/koptilnya/car_systems/entities/animated_light.txt new file mode 100644 index 0000000..0d7e7b5 --- /dev/null +++ b/koptilnya/car_systems/entities/animated_light.txt @@ -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 + +