Sprache Deutsch Language English

Script Dokumentation LS 2015 - NightGlower (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/NightGlower.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- NightGlower class
2--
3-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
4
5NightGlower = {}
6
7local NightGlower_mt = Class(NightGlower);
8
9function NightGlower:onCreate(id)
10 g_currentMission:addUpdateable(NightGlower:new(id));
11end;
12
13function NightGlower:new(id)
14 local self = {};
15 setmetatable(self, NightGlower_mt);
16 self.id = id;
17 self.isSunOn = true;
18 self.maxGlow = {1, 6, 3};
19 self.minGlow = {1, 3, 1};
20 self.timer = 0;
21
22 setShaderParameter(self.id, "colorTint", 1, 1, 1, 1, false);
23
24 g_currentMission.environment:addWeatherChangeListener(self);
25
26 return self;
27end;
28
29function NightGlower:delete()
30 if g_currentMission.environment ~= nil then
31 g_currentMission.environment:removeWeatherChangeListener(self);
32 end;
33end;
34
35function NightGlower:update(dt)
36 if not self.isSunOn then
37 self.timer = (self.timer + dt * 0.001) % (2*math.pi);
38 local glowValue = (math.sin(self.timer) + 1) / 2; -- value from 0 to 1
39 local currentGlow = {0, 0, 0};
40 currentGlow[1] = glowValue * self.maxGlow[1] + (1 - glowValue) * self.minGlow[1];
41 currentGlow[2] = glowValue * self.maxGlow[2] + (1 - glowValue) * self.minGlow[2];
42 currentGlow[3] = glowValue * self.maxGlow[3] + (1 - glowValue) * self.minGlow[3];
43 setShaderParameter(self.id, "colorTint", currentGlow[1], currentGlow[2], currentGlow[3], 1, false);
44 end;
45end;
46
47function NightGlower:weatherChanged()
48 self.isSunOn = g_currentMission.environment.isSunOn;
49 if self.isSunOn then
50 setShaderParameter(self.id, "colorTint", 1, 1, 1, 1, false);
51 end;
52end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht