diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 15:02:49 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 15:02:49 +0100 |
commit | fa9608670a677dcdf42f8c30c80100c440c895b9 (patch) | |
tree | 4ea6452a374f363cdce6891110777daa7d830e13 /src/main | |
parent | 94a81e6ff52ac9c024b6058f50e5de9567f8a80b (diff) | |
download | skyhanni-fa9608670a677dcdf42f8c30c80100c440c895b9.tar.gz skyhanni-fa9608670a677dcdf42f8c30c80100c440c895b9.tar.bz2 skyhanni-fa9608670a677dcdf42f8c30c80100c440c895b9.zip |
moved bingo card reading logic into its own class
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt | 91 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt | 87 |
2 files changed, 87 insertions, 91 deletions
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 9a0095dd6..e7306756e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt @@ -2,32 +2,20 @@ 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 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.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 -import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.onToggle import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils -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.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 { @@ -44,8 +32,6 @@ class BingoCardDisplay { private const val MAX_PERSONAL_GOALS = 20 private const val MAX_COMMUNITY_GOALS = 5 - val personalHiddenGoalPattern = ".*§7§eThe next hint will unlock in (?<time>.*)".toPattern() - private val config get() = SkyHanniMod.feature.event.bingo.bingoCard private var displayMode = 0 @@ -77,83 +63,6 @@ class BingoCardDisplay { } } - private fun BingoJson.BingoTip.getDescriptionLine() = "§7" + note.joinToString(" ") - - @SubscribeEvent - fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - if (!LorenzUtils.isBingoProfile) return - if (!config.enabled) return - if (event.inventoryName != "Bingo Card") return - - BingoAPI.bingoGoals.clear() - for ((slot, stack) in event.inventoryItems) { - val isPersonalGoal = stack.getLore().any { it.endsWith("Personal Goal") } - val isCommunityGoal = stack.getLore().any { it.endsWith("Community Goal") } - if (!isPersonalGoal && !isCommunityGoal) continue - val name = stack.name?.removeColor() ?: continue - val lore = stack.getLore() - var index = 0 - val builder = StringBuilder() - for (s in lore) { - if (index > 1) { - if (s == "") break - builder.append(s) - builder.append(" ") - } - index++ - } - var description = builder.toString() - if (description.endsWith(" ")) { - description = description.substring(0, description.length - 1) - } - if (description.startsWith("§7§7")) { - description = description.substring(2) - } - - val done = stack.getLore().any { it.contains("GOAL REACHED") } - - 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) - } - BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now() - - BingoCardUpdateEvent().postAndCatch() - } - - private fun getHiddenGoalData( - name: String, - 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()) - } - } - - GoalType.COMMUNITY -> { - if (originalDescription == "§7This goal will be revealed §7when it hits Tier IV.") { - unknownTip = true - } - null - } - } - - val description = BingoAPI.getTip(name)?.getDescriptionLine() - val tipNote = description?.let { - unknownTip = false - it - } ?: originalDescription - return HiddenGoalData(unknownTip, nextHintTime, tipNote) - } - @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (event.repeatSeconds(1)) { 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 c01b7e695..2c7e8cb8b 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 @@ -1,13 +1,21 @@ 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.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.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration class BingoCardReader { private val config get() = SkyHanniMod.feature.event.bingo.bingoCard @@ -15,6 +23,83 @@ class BingoCardReader { // 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) { + if (!LorenzUtils.isBingoProfile) return + if (!config.enabled) return + if (event.inventoryName != "Bingo Card") return + + BingoAPI.bingoGoals.clear() + for ((slot, stack) in event.inventoryItems) { + val isPersonalGoal = stack.getLore().any { it.endsWith("Personal Goal") } + val isCommunityGoal = stack.getLore().any { it.endsWith("Community Goal") } + if (!isPersonalGoal && !isCommunityGoal) continue + val name = stack.name?.removeColor() ?: continue + val lore = stack.getLore() + var index = 0 + val builder = StringBuilder() + for (s in lore) { + if (index > 1) { + if (s == "") break + builder.append(s) + builder.append(" ") + } + index++ + } + var description = builder.toString() + if (description.endsWith(" ")) { + description = description.substring(0, description.length - 1) + } + if (description.startsWith("§7§7")) { + description = description.substring(2) + } + + val done = stack.getLore().any { it.contains("GOAL REACHED") } + + 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) + } + BingoAPI.lastBingoCardOpenTime = SimpleTimeMark.now() + + BingoCardUpdateEvent().postAndCatch() + } + + private fun getHiddenGoalData( + name: String, + 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()) + } + } + + GoalType.COMMUNITY -> { + if (originalDescription == "§7This goal will be revealed §7when it hits Tier IV.") { + unknownTip = true + } + null + } + } + + val description = BingoAPI.getTip(name)?.getDescriptionLine() + val tipNote = description?.let { + unknownTip = false + it + } ?: originalDescription + return HiddenGoalData(unknownTip, nextHintTime, tipNote) + } + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!LorenzUtils.isBingoProfile) return @@ -29,4 +114,6 @@ class BingoCardReader { BingoGoalReachedEvent(goal).postAndCatch() BingoCardUpdateEvent().postAndCatch() } + + private fun BingoJson.BingoTip.getDescriptionLine() = "§7" + note.joinToString(" ") } |