aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-09-10 23:23:42 +0200
committerGitHub <noreply@github.com>2024-09-10 23:23:42 +0200
commitd6c9b63136cae3a8abf7d4ce91424dfc648dc59c (patch)
treec8e0df4cfeabe04c711b00e32df7ef1c8eab6549 /src/main/java/at/hannibal2/skyhanni/utils
parent9acb6e88fb868ce9d591fb98cfa80730681653f6 (diff)
downloadskyhanni-d6c9b63136cae3a8abf7d4ce91424dfc648dc59c.tar.gz
skyhanni-d6c9b63136cae3a8abf7d4ce91424dfc648dc59c.tar.bz2
skyhanni-d6c9b63136cae3a8abf7d4ce91424dfc648dc59c.zip
Feature: Golden Fish Timer (#1941)
Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt7
2 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
index c8492086a..fd240b145 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
@@ -54,7 +54,10 @@ object InventoryUtils {
fun getItemsInHotbar() =
getItemsInOwnInventoryWithNull()?.sliceArray(0..8)?.filterNotNull() ?: emptyList()
- fun countItemsInLowerInventory(predicate: (ItemStack) -> Boolean) =
+ fun containsInLowerInventory(predicate: (ItemStack) -> Boolean): Boolean =
+ countItemsInLowerInventory(predicate) > 0
+
+ fun countItemsInLowerInventory(predicate: (ItemStack) -> Boolean): Int =
getItemsInOwnInventory().filter { predicate(it) }.sumOf { it.stackSize }
fun inStorage() = openInventoryName().let {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index b31bb828b..5cf3ec2e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -19,6 +19,7 @@ object TimeUtils {
showMilliSeconds: Boolean = this in -1.seconds..1.seconds,
longName: Boolean = false,
maxUnits: Int = -1,
+ showSmallerUnits: Boolean = false,
): String {
var millis = inWholeMilliseconds
val parts = mutableMapOf<TimeUnit, Int>()
@@ -31,10 +32,14 @@ object TimeUtils {
}
}
+ val largestNonZeroUnit = parts.firstNotNullOfOrNull { if (it.value != 0) it.key else null } ?: TimeUnit.SECOND
+
var currentUnits = 0
val result = buildString {
for ((unit, value) in parts) {
- if (value != 0 || (unit == TimeUnit.SECOND && showMilliSeconds)) {
+ val showUnit = value != 0 || (showSmallerUnits && unit.factor <= largestNonZeroUnit.factor)
+
+ if (showUnit) {
val formatted = value.addSeparators()
val text = if (unit == TimeUnit.SECOND && showMilliSeconds) {
val formattedMillis = (millis / 100).toInt()