From bacc7c617f6dbc2e90fc0c5d1cecc58d65f96bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Sun, 6 Jun 2021 21:55:19 +0500 Subject: [PATCH] Implementing light system --- .../car_systems/entities/animated_light.txt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 koptilnya/car_systems/entities/animated_light.txt 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 + +