Skip to content

Commit

Permalink
refactor(rewrite): some time stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
IllustrisJack committed Mar 12, 2023
1 parent b2c32aa commit 19ba672
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
16 changes: 8 additions & 8 deletions ext/Client/Time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Time = class 'Time'

---@type Logger
local m_Logger = Logger("Time", false)
local m_Logger = Logger("Time", true)

---@type VisualEnvironmentHandler
local m_VisualEnvironmentHandler = require("VisualEnvironmentHandler")
Expand Down Expand Up @@ -37,7 +37,6 @@ function Time:RegisterVars()

self._CurrentPreset = 1

self._CloudSpeed = CONFIG.CLOUDS_DEFAULT_SPEED
self._Sunrise = CONFIG.DN_SUN_TIMINGS[1] / 24
self._Sunset = CONFIG.DN_SUN_TIMINGS[2] / 24
end
Expand All @@ -46,15 +45,16 @@ function Time:RegisterEvents()
NetEvents:Subscribe('VEManager:AddTimeToClient', self, self._OnAddTime)
NetEvents:Subscribe('ClientTime:Pause', self, self._OnPauseUnpause)
NetEvents:Subscribe('ClientTime:Disable', self, self._OnDisable)
Events:Subscribe('VEManager:PresetsLoaded', self, self._OnPresetsLoaded)
end

function Time:OnLevelLoaded()
self.m_ServerSyncEvent = NetEvents:Subscribe('TimeServer:Sync', self, self._OnServerSync) -- Server Sync
function Time:_OnPresetsLoaded()
self._SyncEvent = NetEvents:Subscribe('TimeServer:Sync', self, self._OnServerSync) -- Server Sync
self:_Sync()
end

function Time:OnLevelDestroy()
self.m_ServerSyncEvent = NetEvents:Unsubscribe('TimeServer:Sync') -- Server Sync
self._SyncEvent:Unsubscribe()
self:_Disable()
end

Expand Down Expand Up @@ -217,7 +217,7 @@ function Time:_OnAddTime(p_StartingTime, p_IsStatic, p_LengthOfDayInSeconds)

if l_Object.type == l_Type and s_SunRotationY ~= nil then
-- Check if night mode (moon enabled)
if s_SkyBrightness ~= nil and s_SkyBrightness <= 0.01 then
if s_SunRotationY >= 180 then
s_SunRotationY = 360 - s_SunRotationY
end
m_Logger:Write(" - " .. tostring(l_ID) .. " (Sun: " .. tostring(s_SunRotationY) .. ")")
Expand Down Expand Up @@ -411,8 +411,8 @@ function Time:_Run()
if not m_VisualEnvironmentHandler:CheckIfExists(s_ID) then return end
m_VisualEnvironmentHandler:SetVisibility(s_ID, s_Factor)

if s_Factor ~= 0 then -- TODO: Check if cloud speed works properly
m_VisualEnvironmentHandler:SetSingleValue(s_ID, 'sky', 'cloudLayer1Speed', self._CloudSpeed)
if s_Factor ~= 0 then -- hardcode for now
m_VisualEnvironmentHandler:SetSingleValue(s_ID, 'sky', 'cloudLayer1Speed', -0.0001)
end
end

Expand Down
2 changes: 2 additions & 0 deletions ext/Client/Types/VisualEnvironmentObject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function VisualEnvironmentObject:__init(p_Preset)

if not p_Preset.Priority then
p_Preset.Priority = 1
elseif p_Preset.Type == 'Dynamic' then
p_Preset.Priority = 200
else
p_Preset.Priority = tonumber(p_Preset.Priority)
end
Expand Down
4 changes: 2 additions & 2 deletions ext/Client/VisualEnvironmentHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
VisualEnvironmentHandler = class 'VisualEnvironmentHandler'

---@type Logger
local m_Logger = Logger("VisualEnvironmentHandler", true)
local m_Logger = Logger("VisualEnvironmentHandler", false)

---@type EasingTransitions
local m_Easing = require "__shared/Utils/Easing"
Expand Down Expand Up @@ -377,7 +377,7 @@ function VisualEnvironmentHandler:SetSingleValue(p_ID, p_Class, p_Property, p_Va
end
---@type VisualEnvironmentObject
local s_Object = self._VisualEnvironmentObjects[p_ID]
s_Object.entity.state[p_Class][p_Property] = p_Value
VisualEnvironmentEntity(s_Object.entity).state[p_Class][p_Property] = p_Value
VisualEnvironmentManager:SetDirty(true)
end

Expand Down
2 changes: 2 additions & 0 deletions ext/Client/__init__.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ local m_VisualEnvironmentHandler = require("VisualEnvironmentHandler")
local m_RuntimeEntityHandler = require("RuntimeEntityHandler")
---@type Patches
local m_Patches = require("Patches")
---@type Time
local m_Time = require("Time")
--#endregion

function VEManagerClient:__init()
Expand Down
6 changes: 3 additions & 3 deletions ext/Server/TimeServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TimeServer = class "TimeServer"

---@type Logger
local m_Logger = Logger("TimeServer", false)
local m_Logger = Logger("TimeServer", true)

function TimeServer:__init()
m_Logger:Write('Initializing Time-Server')
Expand Down Expand Up @@ -37,7 +37,7 @@ function TimeServer:RegisterEvents()
m_Logger:Write('Registered Events')

---@type Event
self.m_EngineUpdateEvent = Events:Subscribe('Engine:Update', self, self._OnEngineUpdate)
Events:Subscribe('Engine:Update', self, self._OnEngineUpdate)
Events:Subscribe('Level:Destroy', self, self._OnLevelDestroy)
Events:Subscribe('TimeServer:Enable', self, self._OnEnable)
Events:Subscribe('TimeServer:Pause', self, self._OnPauseUnpause)
Expand All @@ -47,7 +47,7 @@ function TimeServer:RegisterEvents()
end

function TimeServer:_OnLevelDestroy()
self.m_EngineUpdateEvent:Unsubscribe()
self:RegisterVars()
end

---@param p_StartingTime number
Expand Down

0 comments on commit 19ba672

Please sign in to comment.