Skip to content

Commit

Permalink
Fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Jan 10, 2025
1 parent dc5c029 commit 6f6c993
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}")
}
}
}
}

tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ object PolyTimeClient {
fun initialize() {
PolyTimeConfig.preload()
CommandManager.registerCommand(PolyTimeCommand())

RealTimeHandler.initialize()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import org.polyfrost.oneconfig.api.config.v1.annotations.Keybind
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager.registerKeybind
import org.polyfrost.polytime.PolyTimeConstants
import org.polyfrost.polyui.input.KeybindHelper
import org.polyfrost.universal.UKeyboard

object PolyTimeConfig : Config("${PolyTime.MODID}.json", PolyTime.NAME, Category.QOL) { // TODO: Fix mod
object PolyTimeConfig : Config("${PolyTimeConstants.ID}.json", PolyTimeConstants.NAME, Category.QOL) { // TODO: Fix mod

// TODO
// @Info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,27 @@ data class RealTimeData(
val nadir: Float
) {

private companion object {
companion object {

private val logger = LogManager.getLogger(RealTimeData::class.java)

@JvmStatic
fun from(times: SunTimes): RealTimeData? {
val sunrise = times.rise ?: return null.also { logger.error("Sunrise time is null") }
val sunset = times.set ?: return null.also { logger.error("Sunset time is null") }
val noon = times.noon ?: return null.also { logger.error("Noon time is null") }
val nadir = times.nadir ?: return null.also { logger.error("Nadir time is null") }

return RealTimeData(
times.isAlwaysUp,
times.isAlwaysDown,
sunrise,
sunset,
noon,
nadir
)
}

private fun ZonedDateTime.parse(): Float {
return hour + minute / 60f + second / 3600f
}
Expand All @@ -39,17 +56,4 @@ data class RealTimeData(
nadir.parse()
)

constructor(
isAlwaysUp: Boolean,
isAlwaysDown: Boolean,
times: SunTimes
) : this(
isAlwaysUp,
isAlwaysDown,
times.rise ?: return logger.error("Sunrise time is null"),
times.set ?: return logger.error("Sunset time is null"),
times.noon ?: return logger.error("Noon time is null"),
times.nadir ?: return logger.error("Nadir time is null")
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ object RealTimeHandler {

val irlTime = irlTime // Caches the value
return when {
irlTime.isWithinPeriod(data.sunrise, data.noon) -> currentTime.calculateMappedTime(data.sunrise, data.noon, 5f, 12f)
irlTime.isWithinPeriod(data.noon, data.sunset) -> currentTime.calculateMappedTime(data.noon, data.sunset, 12f, 19f)
irlTime.isWithinPeriod(data.sunset, data.nadir) -> currentTime.calculateMappedTime(data.sunset, data.nadir, 19f, 0f)
else -> currentTime.calculateMappedTime(data.nadir, data.sunrise, 0f, 5f)
irlTime.isWithinPeriod(data.sunrise, data.noon) -> irlTime.calculateMappedTime(data.sunrise, data.noon, 5f, 12f)
irlTime.isWithinPeriod(data.noon, data.sunset) -> irlTime.calculateMappedTime(data.noon, data.sunset, 12f, 19f)
irlTime.isWithinPeriod(data.sunset, data.nadir) -> irlTime.calculateMappedTime(data.sunset, data.nadir, 19f, 0f)
else -> irlTime.calculateMappedTime(data.nadir, data.sunrise, 0f, 5f)
}
}
}
Expand All @@ -72,7 +72,8 @@ object RealTimeHandler {
.oneDay()
.timezone(Calendar.getInstance().timeZone)
.execute()
data = RealTimeData(times.isAlwaysUp, times.isAlwaysDown, times)
data = RealTimeData.from(times) ?: return logger.error("Failed to obtain real-time data")
logger.info("Obtained real-time data: $data")

val illumination = MoonIllumination.compute()
.at(latitude, longitude)
Expand All @@ -90,6 +91,8 @@ object RealTimeHandler {
MoonPhase.Phase.WAXING_GIBBOUS -> 7
else -> 0
}

logger.info("Obtained lunar phase: $currentLunarPhase")
}

private fun obtainLongitudeLatitude(): Pair<Double, Double>? {
Expand Down

0 comments on commit 6f6c993

Please sign in to comment.