LUADOC - Farming Simulator 19

NightIllumination

Description
Class for NightIllumination objects which are used for building windows that are illuminated at night
Functions

delete

Description
Remove Object from WeatherChangeListeners
Definition
delete()
Code
59function NightIllumination:delete()
60 if g_currentMission.environment ~= nil then
61 g_currentMission.environment:removeWeatherChangeListener(self)
62 end
63end

new

Description
Creating NightIllumination object
Definition
new(integer name)
Arguments
integernameID of the node
Return Values
tableinstanceInstance of object
Code
25function NightIllumination:new(id)
26 local self = {}
27 setmetatable(self, NightIllumination_mt)
28
29 g_currentMission.environment:addWeatherChangeListener(self)
30
31 self.id = id
32 self.windowsId = 0
33 self.lightsId = 0
34
35 if getNumOfChildren(id) > 0 then
36 self.windowsId = getChildAt(id, 0)
37 end
38 if getNumOfChildren(id) > 1 then
39 self.lightsId = getChildAt(id, 1)
40 end
41
42 self.lightIntensity = Utils.getNoNil(getUserAttribute(self.id, "lightIntensity"), 1.0)
43
44 -- set windows to dark (using dashboardLightsShader)
45 if self.windowsId ~= 0 then
46 setShaderParameter(self.windowsId, "lightControl", 0, 0, 0, 0, false)
47 end
48
49 -- make lights invisible
50 if self.lightsId ~= 0 then
51 setVisibility(self.lightsId, false)
52 end
53
54 return self
55end

onCreate

Description
Creating NightIllumination object
Definition
onCreate(integer id)
Arguments
integeridID of the node
Code
17function NightIllumination:onCreate(id)
18 g_currentMission:addNonUpdateable(NightIllumination:new(id))
19end

weatherChanged

Description
Change illumination of night objects
Definition
weatherChanged()
Code
67function NightIllumination:weatherChanged()
68 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
69 local isLightNeeded = not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining())
70
71 if self.windowsId ~= 0 then
72 if isLightNeeded then
73 setShaderParameter(self.windowsId, "lightControl", self.lightIntensity, 0, 0, 0, false)
74 else
75 setShaderParameter(self.windowsId, "lightControl", 0, 0, 0, 0, false)
76 end
77 end
78
79 if self.lightsId ~= 0 then
80 setVisibility(self.lightsId, isLightNeeded)
81 end
82 end
83end