aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-08 20:33:44 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-08 20:33:44 +0100
commit37581a1ae179b97b80a85b63681011e4f61610b8 (patch)
treeb3d5db4befdd49bdd8a467eb0828e2c2b3976029 /src/main/java/at/hannibal2/skyhanni/features
parent33a3bb5eb33cb620d2a778949980a768253cd567 (diff)
downloadskyhanni-37581a1ae179b97b80a85b63681011e4f61610b8.tar.gz
skyhanni-37581a1ae179b97b80a85b63681011e4f61610b8.tar.bz2
skyhanni-37581a1ae179b97b80a85b63681011e4f61610b8.zip
Added the community goal percentage to the bingo card display.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt1
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