diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 15:01:21 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 15:01:21 +0100 |
commit | 94a81e6ff52ac9c024b6058f50e5de9567f8a80b (patch) | |
tree | b575b17d93e418976eddb7cb834cf45bcc60ed3f /src | |
parent | df852759ff8a183e65b58e14aeaf99155fad563c (diff) | |
download | skyhanni-94a81e6ff52ac9c024b6058f50e5de9567f8a80b.tar.gz skyhanni-94a81e6ff52ac9c024b6058f50e5de9567f8a80b.tar.bz2 skyhanni-94a81e6ff52ac9c024b6058f50e5de9567f8a80b.zip |
Created BingoCardUpdateEvent and code cleanup
Diffstat (limited to 'src')
7 files changed, 74 insertions, 49 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoCardUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoCardUpdateEvent.kt new file mode 100644 index 000000000..f7406498b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoCardUpdateEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events.bingo + +import at.hannibal2.skyhanni.events.LorenzEvent + +class BingoCardUpdateEvent : LorenzEvent() 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 84c7c21f3..17a6fe507 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoRanksJson import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.bingo.card.BingoGoal import at.hannibal2.skyhanni.features.bingo.card.GoalType +import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object BingoAPI { @@ -14,6 +15,7 @@ object BingoAPI { val bingoGoals = mutableListOf<BingoGoal>() val personalGoals get() = bingoGoals.filter { it.type == GoalType.PERSONAL } val communityGoals get() = bingoGoals.filter { it.type == GoalType.COMMUNITY } + var lastBingoCardOpenTime = SimpleTimeMark.farPast() @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -26,11 +28,11 @@ object BingoAPI { fun getIcon(searchRank: Int) = ranks.entries.find { it.value == searchRank }?.key // We added the suffix (Community Goal) so that older skyhanni versions don't crash with the new repo data. - fun getCommunityTip(itemName: String) = + fun getTip(itemName: String) = tips.filter { itemName.startsWith(it.key.split(" (Community Goal)")[0]) }.values.firstOrNull() fun BingoGoal.getTip(): BingoJson.BingoTip? = if (type == GoalType.COMMUNITY) { - getCommunityTip(displayName) + getTip(displayName) } else { tips[displayName] } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt index 95e01c058..9a0095dd6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt @@ -2,14 +2,15 @@ package at.hannibal2.skyhanni.features.bingo import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson.BingoTip +import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.bingo.BingoGoalReachedEvent +import at.hannibal2.skyhanni.events.bingo.BingoCardUpdateEvent import at.hannibal2.skyhanni.features.bingo.card.BingoGoal import at.hannibal2.skyhanni.features.bingo.card.GoalType +import at.hannibal2.skyhanni.features.bingo.card.HiddenGoalData import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -26,13 +27,13 @@ import at.hannibal2.skyhanni.utils.TimeUtils.format import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiChat import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration import kotlin.time.Duration.Companion.days class BingoCardDisplay { private var display = emptyList<String>() - private var lastBingoCardOpenTime = SimpleTimeMark.farPast() private var hasHiddenPersonalGoals = false init { @@ -76,7 +77,7 @@ class BingoCardDisplay { } } - private fun BingoTip.getDescriptionLine() = "§7" + note.joinToString(" ") + private fun BingoJson.BingoTip.getDescriptionLine() = "§7" + note.joinToString(" ") @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { @@ -110,45 +111,47 @@ class BingoCardDisplay { } val done = stack.getLore().any { it.contains("GOAL REACHED") } - if (isPersonalGoal) { - BingoAPI.bingoGoals.add(getPersonalGoal(name, description, slot, done)) - } else { - BingoAPI.bingoGoals.add(getCommunityGoal(name, description, slot, done)) - } + + val goalType = if (isPersonalGoal) GoalType.PERSONAL else GoalType.COMMUNITY + val hiddenGoalData = getHiddenGoalData(name, description, goalType) + val visualDescription = hiddenGoalData.tipNote + + val bingoGoal = BingoGoal(name, visualDescription, goalType, slot, done, hiddenGoalData) + BingoAPI.bingoGoals.add(bingoGoal) } - lastBingoCardOpenTime = SimpleTimeMark.now() + BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now() - update() + BingoCardUpdateEvent().postAndCatch() } - private fun getPersonalGoal( + private fun getHiddenGoalData( name: String, - description: String, - slot: Int, - done: Boolean - ): BingoGoal { - if (!done) { - personalHiddenGoalPattern.matchMatcher(description) { - BingoAPI.tips[name]?.let { - return BingoGoal(name, it.getDescriptionLine(), GoalType.PERSONAL, slot, false) + originalDescription: String, + goalType: GoalType, + ): HiddenGoalData { + var unknownTip = false + val nextHintTime: Duration? = when (goalType) { + GoalType.PERSONAL -> { + personalHiddenGoalPattern.matchMatcher(originalDescription) { + unknownTip = true + TimeUtils.getDuration(group("time").removeColor()) } } - } - return BingoGoal(name, description, GoalType.PERSONAL, slot, done) - } - private fun getCommunityGoal( - name: String, - description: String, - slot: Int, - done: Boolean - ): BingoGoal { - if (description == "§7This goal will be revealed §7when it hits Tier IV.") { - BingoAPI.getCommunityTip(name)?.let { - return BingoGoal(name, it.getDescriptionLine(), GoalType.COMMUNITY, slot, done) + GoalType.COMMUNITY -> { + if (originalDescription == "§7This goal will be revealed §7when it hits Tier IV.") { + unknownTip = true + } + null } } - return BingoGoal(name, description, GoalType.COMMUNITY, slot, done) + + val description = BingoAPI.getTip(name)?.getDescriptionLine() + val tipNote = description?.let { + unknownTip = false + it + } ?: originalDescription + return HiddenGoalData(unknownTip, nextHintTime, tipNote) } @SubscribeEvent @@ -184,7 +187,7 @@ class BingoCardDisplay { val goals = BingoAPI.communityGoals.toMutableList() var hiddenGoals = 0 for (goal in goals.toList()) { - if (goal.description == "§7This goal will be revealed §7when it hits Tier IV.") { + if (goal.hiddenGoalData.unknownTip) { hiddenGoals++ goals.remove(goal) } @@ -205,12 +208,15 @@ class BingoCardDisplay { var hiddenGoals = 0 var nextTip = 7.days for (goal in todo.toList()) { - personalHiddenGoalPattern.matchMatcher(goal.description) { + val hiddenGoalData = goal.hiddenGoalData ?: continue + if (hiddenGoalData.unknownTip) { hiddenGoals++ todo.remove(goal) - val time = TimeUtils.getDuration(group("time").removeColor()) - if (time < nextTip) { - nextTip = time + } + + hiddenGoalData.nextHintTime?.let { + if (it < nextTip) { + nextTip = it } } } @@ -222,7 +228,7 @@ class BingoCardDisplay { } hasHiddenPersonalGoals = config.nextTipDuration.get() && nextTip != 7.days if (hasHiddenPersonalGoals) { - val nextTipTime = lastBingoCardOpenTime + nextTip + val nextTipTime = BingoAPI.lastBingoCardOpenTime + nextTip if (nextTipTime.isInPast()) { add("§eThe next hint got unlocked already!") add("§eOpen the bingo card to update!") @@ -262,9 +268,8 @@ class BingoCardDisplay { } @SubscribeEvent - fun onBingoGoalReached(event: BingoGoalReachedEvent) { + fun onBingoCardUpdate(event: BingoCardUpdateEvent) { if (!config.enabled) return - event.goal.done = true update() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt index 0ec586747..e2381524d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt @@ -21,7 +21,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -232,9 +231,7 @@ class BingoNextStepHelper { val description = goal.description val bingoCardStep = readDescription(description.removeColor()) if (bingoCardStep == null) { - if (!BingoCardDisplay.personalHiddenGoalPattern.matches(description)) { - println("Warning: Could not find bingo steps for $description") - } +// println("Warning: Could not find bingo steps for $description") } else { finalSteps.add(bingoCardStep) } 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 9db12c72f..c01b7e695 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,6 +2,7 @@ package at.hannibal2.skyhanni.features.bingo.card import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.bingo.BingoCardUpdateEvent import at.hannibal2.skyhanni.events.bingo.BingoGoalReachedEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI import at.hannibal2.skyhanni.utils.LorenzUtils @@ -24,7 +25,8 @@ class BingoCardReader { } ?: return val goal = BingoAPI.personalGoals.firstOrNull { it.displayName == name } ?: return - + goal.done = true BingoGoalReachedEvent(goal).postAndCatch() + BingoCardUpdateEvent().postAndCatch() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoGoal.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoGoal.kt index c999e15ae..24162fe13 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoGoal.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoGoal.kt @@ -1,3 +1,12 @@ package at.hannibal2.skyhanni.features.bingo.card -class BingoGoal(val displayName: String, val description: String, val type: GoalType, val slot: Int, var done: Boolean) +class BingoGoal( + val displayName: String, + val description: String, + val type: GoalType, + val slot: Int, + var done: Boolean, + val hiddenGoalData: HiddenGoalData, +) { + override fun toString(): String = displayName +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/HiddenGoalData.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/HiddenGoalData.kt new file mode 100644 index 000000000..8df08906c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/HiddenGoalData.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.features.bingo.card + +import kotlin.time.Duration + +class HiddenGoalData(val unknownTip: Boolean, val nextHintTime: Duration?, val tipNote: String) |