fix SetTimeOfDaySpeed influencing "current" time

fix GetTimeOfDay not considering time speed
fix SetTimeOfDay not considering time speed
This commit is contained in:
Resaec 2026-04-29 23:28:49 +02:00
parent 0ae8ab2418
commit 7396b09998

View file

@ -573,24 +573,25 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) {
} }
def GetTimeOfDay(): Float = { def GetTimeOfDay(): Float = {
// get time since origin val now = System.currentTimeMillis()
val timeDiff = System.currentTimeMillis() - timeOfDayOrigin val timeDiff = now - timeOfDayOrigin
// get seconds - limit to 24h
val diffSeconds = (timeDiff / 1000) % 86400
diffSeconds.toFloat // get seconds
val diffSeconds = timeDiff / 1000
// apply speed factor
val elapsedTime = diffSeconds * timeOfDaySpeed
// wrap time to 24h
elapsedTime % 86400
} }
def SetTimeOfDay(requestedTime: Float) = { def SetTimeOfDay(requestedTime: Float) = {
// get current time
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
// get requested time in millis
val requestMillis = requestedTime * 1000
// substract requestedMillis from now to get new origin val requestedTimeDiff = requestedTime / timeOfDaySpeed
val newOrigin = now - requestMillis
timeOfDayOrigin = newOrigin.toLong timeOfDayOrigin = now - (requestedTimeDiff * 1000.0).toLong
} }
def GetTimeOfDaySpeed(): Float = { def GetTimeOfDaySpeed(): Float = {
@ -598,7 +599,13 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) {
} }
def SetTimeOfDaySpeed(requestedSpeed: Float) = { def SetTimeOfDaySpeed(requestedSpeed: Float) = {
// store current time
val timeOfDay = GetTimeOfDay()
timeOfDaySpeed = requestedSpeed timeOfDaySpeed = requestedSpeed
// restore old time with new speed considered
SetTimeOfDay(timeOfDay)
} }
/** /**