From 37581a1ae179b97b80a85b63681011e4f61610b8 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 8 Dec 2023 20:33:44 +0100 Subject: Added the community goal percentage to the bingo card display. --- .../features/bingo/card/BingoCardDisplay.kt | 20 +++++++++++++++++++- .../features/bingo/card/BingoCardReader.kt | 22 ++++++++++++++++++---- .../features/bingo/card/goals/BingoGoal.kt | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt index 126212ba6..5c7f61f09 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt @@ -118,7 +118,11 @@ class BingoCardDisplay { } } - addGoals(goals) { it.description.removeColor() + if (it.done) " §aDONE" else " " } + addGoals(goals) { + val percentageFormat = percentageFormat(it) + val name = it.description.removeColor() + "$name$percentageFormat" + } if (hiddenGoals > 0) { val name = StringUtils.canBePlural(hiddenGoals, "goal", "goals") @@ -127,6 +131,20 @@ class BingoCardDisplay { add(Renderable.string(" ")) } + private fun percentageFormat(it: BingoGoal): String { + val percentage = it.communtyGoalPercentage ?: return "" + + val percentageColor = when { + percentage < 0.01 -> "§a" + percentage < 0.05 -> "§e" + percentage < 0.1 -> "§6" + percentage < 0.25 -> "§6" + + else -> "§c" + } + return " " + percentageColor + LorenzUtils.formatPercentage(percentage) + } + private fun MutableList.addPersonalGoals() { val todo = BingoAPI.personalGoals.filter { !it.done }.toMutableList() val done = MAX_PERSONAL_GOALS - todo.size diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt index f45942b49..c77e5705e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.bingo.card import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson -import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.bingo.BingoCardUpdateEvent import at.hannibal2.skyhanni.events.bingo.BingoGoalReachedEvent @@ -17,19 +17,21 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration class BingoCardReader { private val config get() = SkyHanniMod.feature.event.bingo.bingoCard + private val percentagePattern by RepoPattern.pattern("bingo.card.percentage", " {2}§8Top §.(?.*)%") + // TODO USE SH-REPO private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?.*)".toPattern() - private val personalHiddenGoalPattern = ".*§7§eThe next hint will unlock in (?