diff options
Diffstat (limited to 'src/main/java/at')
6 files changed, 75 insertions, 41 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 52f10c40e..d3796b767 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.config; import at.hannibal2.skyhanni.data.model.ComposterUpgrade; +import at.hannibal2.skyhanni.features.bingo.card.goals.BingoGoal; import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker; import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostData; import at.hannibal2.skyhanni.features.dungeon.DungeonAPI; @@ -92,6 +93,14 @@ public class Storage { public int amountGifted = 0; } + @Expose + public Map<Long, BingoProfile> bingoProfiles = new HashMap<>(); + + public static class BingoProfile { + + @Expose + public Map<Integer, BingoGoal> goals = new HashMap<>(); + } } public static class ProfileSpecific { @@ -113,9 +122,9 @@ public class Storage { @Override public String toString() { return "MinionConfig{" + - "displayName='" + displayName + '\'' + - ", lastClicked=" + lastClicked + - '}'; + "displayName='" + displayName + '\'' + + ", lastClicked=" + lastClicked + + '}'; } } @@ -367,11 +376,11 @@ public class Storage { @Override public String toString() { return "SlayerRngMeterStorage{" + - "currentMeter=" + currentMeter + - ", gainPerBoss=" + gainPerBoss + - ", goalNeeded=" + goalNeeded + - ", itemGoal='" + itemGoal + '\'' + - '}'; + "currentMeter=" + currentMeter + + ", gainPerBoss=" + gainPerBoss + + ", goalNeeded=" + goalNeeded + + ", itemGoal='" + itemGoal + '\'' + + '}'; } } 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 } |