-- Copyright ©2022 by Todd Hundersmarck (ThundR)
-- All Rights Reserved
THNightlightFlicker = {} local THNightlightFlicker_mt = Class(THNightlightFlicker, NightlightFlicker) local function runScript() local globalEnv = g_thMain:getGlobalEnv() local NightlightFlicker = globalEnv.NightlightFlicker globalEnv.THNightlightFlicker = THNightlightFlicker g_thMain:hookFunction("NightlightFlicker", "new", THNightlightFlicker, nil, false) g_thMain:hookFunction("NightlightFlicker", "update", THNightlightFlicker) g_thMain:hookFunction("NightlightFlicker", "onWeatherChanged", THNightlightFlicker) g_thMain:hookFunction("NightlightFlicker", "delete", THNightlightFlicker) NightlightFlicker.oNWeatherChanged = NightlightFlicker.onWeatherChanged end function THNightlightFlicker:onCreate(id, ...) if entityExists(id) then return THNightlightFlicker:superClass().onCreate(self, id, ...) end end function THNightlightFlicker.hook_new(superFunc, id, ...) local newEnv, ra,rb,rc,rd,re = superFunc(id, ...) if newEnv ~= nil then local newEnvData = g_thMain:createDataTable(newEnv) newEnvData.isNightLight = Utils.getNoNil(getUserAttribute(newEnv.id, "isNightLight"), true) end return newEnv, ra,rb,rc,rd,re end function THNightlightFlicker:hook_update(superFunc, dt, ...) if entityExists(self.id) then return superFunc(self, dt, ...) end end function THNightlightFlicker:hook_onWeatherChanged(superFunc, ...) local id = self.id if entityExists(id) then local thData = g_thMain:getDataTable(self) if thData.isNightLight then self.isVisible = true else if g_currentMission ~= nil and g_currentMission.environment ~= nil then self.isVisible = not g_currentMission.environment.isSunOn end end setVisibility(id, self.isVisible) end end function THNightlightFlicker:hook_delete(superFunc, ...) g_currentMission:removeUpdateable(self) return superFunc(self, ...) end runScript()