Updated counterMessageCallback

This commit is contained in:
bluefireoly
2020-10-17 13:23:55 +02:00
parent f887c73f90
commit 74bf90cad4

View File

@@ -11,40 +11,40 @@ class GamePhaseSystem(vararg gamePhases: GamePhase) {
} }
fun buildCounterMessageCallback( fun buildCounterMessageCallback(
beforeTime: String? = null, beforeTime: String? = null,
afterTime: String? = null, afterTime: String? = null,
hours: String = "h", hourPlural: String = "h",
minutes: String = "m", minutePlural: String = "m",
seconds: String = "s" secondPlural: String = "s",
hourSingular: String = hourPlural,
minuteSingular: String = minutePlural,
secondSingular: String = secondPlural
): (Long) -> String = { curSeconds -> ): (Long) -> String = { curSeconds ->
StringBuilder().apply { StringBuilder().apply {
append(beforeTime) if (beforeTime != null)
append(beforeTime)
val hourTime = (curSeconds / 3600) val hourTime = (curSeconds / 3600)
val minuteTime = ((curSeconds % 3600) / 60) val minuteTime = ((curSeconds % 3600) / 60)
val secondsTime = (curSeconds % 60) val secondsTime = (curSeconds % 60)
if (hourTime != 0L) if (hourTime != 0L) {
append("${hourTime.toString().run { if (length < 2) "0$this" else this }}:") append("$hourTime ${if (hourTime == 1L) hourSingular else hourPlural}")
if (minuteTime != 0L) append(" ")
}
if ((hourTime != 0L && secondsTime != 0L) || (minuteTime != 0L && secondsTime != 0L)) if (minuteTime != 0L) {
append("${minuteTime.toString().run { if (length < 2) "0$this" else this }}:") append("$minuteTime ${if (minuteTime == 1L) minuteSingular else minutePlural}")
else if (minuteTime != 0L) if (secondsTime != 0L) append(" ")
append(minuteTime.toString().run { if (length < 2) "0$this" else this }) }
if (secondsTime != 0L) if (secondsTime != 0L || (hourTime == 0L && minuteTime == 0L)) {
append(secondsTime.toString().run { if (length < 2) "0$this" else this }) append("$secondsTime ${if (secondsTime == 1L) secondSingular else secondPlural}")
}
append(" ").append(kotlin.run { if (afterTime != null)
return@run when { append(afterTime)
secondsTime != 0L -> seconds
minuteTime != 0L -> minutes
else -> hours
}
})
append(afterTime)
}.toString() }.toString()
} }