aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bingo
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-08 22:59:24 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-08 22:59:24 +0100
commitcfee6ce21b0d1a963b83517056a3edec86609174 (patch)
tree178eb432dc3ca5cc62006e114ad05e3cc8b8cc1c /src/main/java/at/hannibal2/skyhanni/features/bingo
parent37581a1ae179b97b80a85b63681011e4f61610b8 (diff)
downloadskyhanni-cfee6ce21b0d1a963b83517056a3edec86609174.tar.gz
skyhanni-cfee6ce21b0d1a963b83517056a3edec86609174.tar.bz2
skyhanni-cfee6ce21b0d1a963b83517056a3edec86609174.zip
Saving bingo goal data into the config.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bingo')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/goals/BingoGoal.kt33
5 files changed, 58 insertions, 33 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt
index cc5dec6ff..dfc910ba3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.features.bingo
+import at.hannibal2.skyhanni.config.Storage.PlayerSpecific.BingoProfile
+import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoRanksJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
@@ -7,14 +9,19 @@ import at.hannibal2.skyhanni.features.bingo.card.goals.BingoGoal
import at.hannibal2.skyhanni.features.bingo.card.goals.GoalType
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.time.LocalDate
+import java.time.LocalTime
+import java.time.OffsetDateTime
+import java.time.ZoneId
+import java.time.ZoneOffset
object BingoAPI {
private var ranks = mapOf<String, Int>()
- var tips: Map<String, BingoJson.BingoTip> = emptyMap()
- // TODO save into storage
- val bingoGoals = mutableListOf<BingoGoal>()
- val personalGoals get() = bingoGoals.filter { it.type == GoalType.PERSONAL }
- val communityGoals get() = bingoGoals.filter { it.type == GoalType.COMMUNITY }
+ private var tips: Map<String, BingoJson.BingoTip> = emptyMap()
+
+ val bingoGoals get() = bingoStorage.goals
+ val personalGoals get() = bingoGoals.values.filter { it.type == GoalType.PERSONAL }
+ val communityGoals get() = bingoGoals.values.filter { it.type == GoalType.COMMUNITY }
var lastBingoCardOpenTime = SimpleTimeMark.farPast()
@SubscribeEvent
@@ -31,10 +38,19 @@ object BingoAPI {
fun getTip(itemName: String) =
tips.filter { itemName.startsWith(it.key.split(" (Community Goal)")[0]) }.values.firstOrNull()
- fun BingoGoal.getTip(): BingoJson.BingoTip? = if (type == at.hannibal2.skyhanni.features.bingo.card.goals.GoalType.COMMUNITY) {
+ fun BingoGoal.getTip(): BingoJson.BingoTip? = if (type == GoalType.COMMUNITY) {
getTip(displayName)
} else {
tips[displayName]
}
+ private val bingoStorage: BingoProfile by lazy {
+ val playerSpecific = ProfileStorageData.playerSpecific ?: error("playerSpecific is null")
+ playerSpecific.bingoProfiles.getOrPut(getStartOfMonthInMillis()) { BingoProfile() }
+ }
+
+ private fun getStartOfMonthInMillis() = OffsetDateTime.of(
+ LocalDate.now(ZoneId.of("UTC")).plusDays(5).withDayOfMonth(1),
+ LocalTime.MIDNIGHT, ZoneOffset.UTC
+ ).toEpochSecond()
}
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 5c7f61f09..ab4c2c3df 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
@@ -33,10 +33,6 @@ class BingoCardDisplay {
private var hasHiddenPersonalGoals = false
- init {
- update()
- }
-
companion object {
private const val MAX_PERSONAL_GOALS = 20
private const val MAX_COMMUNITY_GOALS = 5
@@ -225,14 +221,6 @@ class BingoCardDisplay {
}
}
- private var highlightedMaps = mutableMapOf<String, Boolean>()
-
- var BingoGoal.highlight: Boolean
- get() = highlightedMaps[displayName] ?: false
- set(value) {
- highlightedMaps[displayName] = value
- }
-
private var lastSneak = false
private var inventoryOpen = false
@@ -281,6 +269,7 @@ class BingoCardDisplay {
fun onConfigLoad(event: ConfigLoadEvent) {
config.hideCommunityGoals.onToggle { update() }
config.nextTipDuration.onToggle { update() }
+ update()
}
@SubscribeEvent
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 c77e5705e..a0fdd2134 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
@@ -36,7 +36,6 @@ class BingoCardReader {
if (!config.enabled) return
if (event.inventoryName != "Bingo Card") return
- BingoAPI.bingoGoals.clear()
for ((slot, stack) in event.inventoryItems) {
val lore = stack.getLore()
val goalType = when {
@@ -69,9 +68,15 @@ class BingoCardReader {
val hiddenGoalData = getHiddenGoalData(name, description, goalType)
val visualDescription = hiddenGoalData.tipNote
- val bingoGoal =
- BingoGoal(name, visualDescription, goalType, slot, done, communtyGoalPercentage, hiddenGoalData)
- BingoAPI.bingoGoals.add(bingoGoal)
+ val bingoGoal = BingoAPI.bingoGoals.getOrPut(slot) { BingoGoal() }
+ with(bingoGoal) {
+ this.type = goalType
+ this.displayName = name
+ this.description = visualDescription
+ this.done = done
+ this.hiddenGoalData = hiddenGoalData
+ this.communtyGoalPercentage = communtyGoalPercentage
+ }
}
BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt
index 6ab2a9a5a..dd4639234 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt
@@ -25,7 +25,7 @@ class BingoCardTips {
val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return
val slot = gui.slotUnderMouse
- val goal = BingoAPI.bingoGoals.firstOrNull { it.slot == slot.slotNumber } ?: return
+ val goal = BingoAPI.bingoGoals[slot.slotNumber] ?: return
val toolTip = event.toolTip
val bingoTip = goal.getTip() ?: return
@@ -60,7 +60,7 @@ class BingoCardTips {
for (slot in chest.inventorySlots) {
if (slot == null) continue
- val goal = BingoAPI.bingoGoals.firstOrNull { it.slot == slot.slotNumber } ?: continue
+ val goal = BingoAPI.bingoGoals[slot.slotNumber] ?: continue
if (config.hideDoneDifficulty && goal.done) continue
val color = goal.getTip()?.let {
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 ba55b1a00..58b560905 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
@@ -1,13 +1,28 @@
package at.hannibal2.skyhanni.features.bingo.card.goals
-class BingoGoal(
- val displayName: String,
- val description: String,
- val type: GoalType,
- val slot: Int,
- var done: Boolean,
- val communtyGoalPercentage: Double?,
- val hiddenGoalData: HiddenGoalData,
-) {
+import com.google.gson.annotations.Expose
+
+class BingoGoal {
+ @Expose
+ lateinit var type: GoalType
+
+ @Expose
+ var displayName = ""
+
+ @Expose
+ var description = ""
+
+ @Expose
+ var done = false
+
+ @Expose
+ var highlight = false
+
+ @Expose
+ lateinit var hiddenGoalData: HiddenGoalData
+
+ @Expose
+ var communtyGoalPercentage: Double? = null
+
override fun toString(): String = displayName
}