diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index d6debfa4a..b217aded1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -28,7 +28,6 @@ import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay.getCurre import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound -import java.util.function.Supplier import java.util.regex.Pattern import kotlin.time.Duration.Companion.minutes @@ -53,9 +52,31 @@ private fun getVisitingName(): String { var beenAfkFor = SimpleTimeMark.now() -enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) { +fun getPetDisplay(): String = PetAPI.currentPet?.let { + val colorCode = it.substring(1..2).first() + val petName = it.substring(2) + val petLevel = getCurrentPet()?.petLevel?.currentLevel ?: "?" - NONE(null), + "[Lvl $petLevel] ${colorCodeToRarity(colorCode)} $petName" +} ?: "No pet equipped" + +private fun getCropMilestoneDisplay(): String { + val crop = InventoryUtils.getItemInHand()?.getCropType() + val cropCounter = crop?.getCounter() + val tier = cropCounter?.let { getTierForCropCount(it, crop) } + + val progress = tier?.let { + LorenzUtils.formatPercentage(crop.progressToNextLevel()) + } ?: 100 // percentage to next milestone + + return if (tier != null) { + "${crop.cropName}: ${if (!crop.isMaxed()) "Milestone $tier ($progress)" else "MAXED (${cropCounter.addSeparators()} crops collected)"}" + } else AutoStatus.CROP_MILESTONES.placeholderText +} + +enum class DiscordStatus(private val displayMessageSupplier: (() -> String?)) { + + NONE({ null }), LOCATION({ var location = LorenzUtils.skyBlockArea?.removeColor() ?: "invalid" @@ -231,29 +252,9 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) autoReturn }), - CROP_MILESTONES({ - val crop = InventoryUtils.getItemInHand()?.getCropType() - val cropCounter = crop?.getCounter() - val tier = cropCounter?.let { getTierForCropCount(it, crop) } + CROP_MILESTONES({ getCropMilestoneDisplay() }), - val progress = tier?.let { - LorenzUtils.formatPercentage(crop.progressToNextLevel()) - } ?: 100 // percentage to next milestone - - if (tier != null) { - "${crop.cropName}: ${if (!crop.isMaxed()) "Milestone $tier ($progress)" else "MAXED (${cropCounter.addSeparators()} crops collected)"}" - } else AutoStatus.CROP_MILESTONES.placeholderText - }), - - PETS({ - PetAPI.currentPet?.let { - val colorCode = it.substring(1..2).first() - val petName = it.substring(2) - val petLevel = getCurrentPet()?.petLevel?.currentLevel ?: "?" - - "[Lvl $petLevel] ${colorCodeToRarity(colorCode)} $petName" - } ?: "No pet equipped" - }), + PETS({ getPetDisplay() }), // Dynamic-only STACKING({ @@ -333,12 +334,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) }) ; - fun getDisplayString(): String { - if (displayMessageSupplier != null) { - return displayMessageSupplier.get() - } - return "" - } + fun getDisplayString(): String = displayMessageSupplier() ?: "" } enum class AutoStatus(val placeholderText: String, val correspondingDiscordStatus: DiscordStatus) { |