diff options
Diffstat (limited to 'src')
3 files changed, 38 insertions, 5 deletions
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<Renderable>.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 §.(?<percentage>.*)%") + // TODO USE SH-REPO private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?<name>.*)".toPattern() - private val personalHiddenGoalPattern = ".*§7§eThe next hint will unlock in (?<time>.*)".toPattern() @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + fun onInventoryOpen(event: InventoryUpdatedEvent) { if (!LorenzUtils.isBingoProfile) return if (!config.enabled) return if (event.inventoryName != "Bingo Card") return @@ -62,11 +64,13 @@ class BingoCardReader { } val done = lore.any { it.contains("GOAL REACHED") } + val communtyGoalPercentage = readCommuntyGoalPercentage(lore) val hiddenGoalData = getHiddenGoalData(name, description, goalType) val visualDescription = hiddenGoalData.tipNote - val bingoGoal = BingoGoal(name, visualDescription, goalType, slot, done, hiddenGoalData) + val bingoGoal = + BingoGoal(name, visualDescription, goalType, slot, done, communtyGoalPercentage, hiddenGoalData) BingoAPI.bingoGoals.add(bingoGoal) } BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now() @@ -74,6 +78,16 @@ class BingoCardReader { BingoCardUpdateEvent().postAndCatch() } + private fun readCommuntyGoalPercentage(lore: List<String>): Double? { + for (line in lore) { + percentagePattern.matchMatcher(line) { + return group("percentage").toDouble() / 100 + } + } + + return null + } + private fun getHiddenGoalData( name: String, originalDescription: String, diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt index 31f01b335..ba55b1a00 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt @@ -6,6 +6,7 @@ class BingoGoal( val type: GoalType, val slot: Int, var done: Boolean, + val communtyGoalPercentage: Double?, val hiddenGoalData: HiddenGoalData, ) { override fun toString(): String = displayName |