From 59370fab4c795a2e9715a3485c6c4203f0934dc7 Mon Sep 17 00:00:00 2001 From: Username404 Date: Fri, 18 Jun 2021 21:08:00 +0200 Subject: [PATCH] Add zeros to minutes and hours too in Clock.kt --- .../username404/snowygui/gui/feature/Clock.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Clock.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Clock.kt index f8f335f..f7729c2 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Clock.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Clock.kt @@ -3,23 +3,26 @@ package fr.username404.snowygui.gui.feature import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.Snowy.Companion.onEvent import fr.username404.snowygui.gui.FontUtil +import kotlinx.datetime.Clock as DatetimeClock import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime -import kotlinx.datetime.Clock as DatetimeClock @ButtonInfo(Category.MISC) object Clock: ButtonImpl() { private val currentTimezone = TimeZone.currentSystemDefault() + override fun toString(): String = DatetimeClock.System.now().toLocalDateTime(currentTimezone).run { + arrayOf(hour, minute, second).map { + (it.takeIf { (it >= 10) } ?: "0$it").toString() + }.reduce { previous, current -> "$previous:$current"} + } init { onEvent("HudRender") { if (toggled) { - with(DatetimeClock.System.now().toLocalDateTime(currentTimezone)) { - FontUtil.drawScaled(it.first() as PoseStack, - "$hour:$minute:${second.let { if (it >= 10) it else "0$it" }}", - 5.0, 5.0, - 0.85F, color = Colors.GOLD - ) - } + FontUtil.drawScaled(it.first() as PoseStack, + this@Clock.toString(), + 5.0, 5.0, + 0.85F, color = Colors.GOLD + ) } } }