diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-01 12:16:14 +0100 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-01 12:16:14 +0100 |
| commit | 3c1d534472fbd83a24799a3df7ce7c80c764597e (patch) | |
| tree | 4b762ced0489728f938f1c21a2273242ef7d37c6 /src/main/java/at/hannibal2/skyhanni/features/bingo | |
| parent | 9f2118dfc218a6b97e4d7d67e7fb9dbd7431cf54 (diff) | |
| download | skyhanni-3c1d534472fbd83a24799a3df7ce7c80c764597e.tar.gz skyhanni-3c1d534472fbd83a24799a3df7ce7c80c764597e.tar.bz2 skyhanni-3c1d534472fbd83a24799a3df7ce7c80c764597e.zip | |
Add support for hidden bingo tips.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bingo')
3 files changed, 97 insertions, 28 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 new file mode 100644 index 000000000..6941e7f57 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.features.bingo + +import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson +import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoRanksJson +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object BingoAPI { + private var ranks = mapOf<String, Int>() + var tips: Map<String, BingoJson.BingoTip> = emptyMap() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + ranks = event.getConstant<BingoRanksJson>("BingoRanks").ranks + tips = event.getConstant<BingoJson>("Bingo").bingo_tips + } + + fun getRank(text: String) = ranks.entries.find { text.contains(it.key) }?.value + + fun getIcon(searchRank: Int) = ranks.entries.find { it.value == searchRank }?.key + +} 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 8951272c1..d6d84ff82 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt @@ -2,6 +2,7 @@ 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.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -81,6 +82,8 @@ class BingoCardDisplay { } } + private fun BingoTip.getDescriptionLine() = "§7" + note.joinToString(" ") + @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!LorenzUtils.isBingoProfile) return @@ -90,9 +93,9 @@ class BingoCardDisplay { personalGoals.clear() communityGoals.clear() for (stack in event.inventoryItems.values) { - val personalGoal = stack.getLore().any { it.endsWith("Personal Goal") } - val communityGoal = stack.getLore().any { it.endsWith("Community Goal") } - if (!personalGoal && !communityGoal) continue + 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 @@ -114,15 +117,49 @@ class BingoCardDisplay { } val done = stack.getLore().any { it.contains("GOAL REACHED") } - if (personalGoal) { - personalGoals.add(PersonalGoal(name, description, done)) + if (isPersonalGoal) { + personalGoals.add(getPersonalGoal(name, description, done)) } else { - communityGoals.add(CommunityGoal(name, description, done)) + communityGoals.add(getCommunityGoal(name, description, done)) } } lastBingoCardOpenTime = SimpleTimeMark.now() update() + for (goal in personalGoals) { + println("goal.displayName: '${goal.displayName}' - ${goal.description}") + } + } + + private fun getPersonalGoal( + name: String, + description: String, + done: Boolean + ): PersonalGoal { + var personalGoal = PersonalGoal(name, description, done) + if (!done) { + personalHiddenGoalPattern.matchMatcher(description) { + BingoAPI.tips[name]?.let { + personalGoal = PersonalGoal(name, it.getDescriptionLine(), false) + } + } + } + return personalGoal + } + + private fun getCommunityGoal( + name: String, + description: String, + done: Boolean + ): CommunityGoal { + if (!done) { + if (description == "§7This goal will be revealed §7when it hits Tier IV.") { + BingoAPI.tips[name]?.let { + return CommunityGoal(name, it.getDescriptionLine(), false) + } + } + } + return CommunityGoal(name, description, done) } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardTips.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardTips.kt index 2486166a5..22925b405 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardTips.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardTips.kt @@ -1,44 +1,52 @@ package at.hannibal2.skyhanni.features.bingo import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson.BingoTip import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.getOrNull import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson -import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson.BingoTip import net.minecraft.inventory.ContainerChest import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BingoCardTips { - private var tips: Map<String, BingoTip> = emptyMap() - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - tips = event.getConstant<BingoJson>("Bingo").bingo_tips - } @SubscribeEvent fun onItemTooltipLow(event: ItemTooltipEvent) { if (!isEnabled()) return if (InventoryUtils.openInventoryName() != "Bingo Card") return - val itemName = event.itemStack?.name ?: return - tips[itemName.removeColor()]?.let { - val difficulty = Difficulty.valueOf(it.difficulty.uppercase()) - event.toolTip[0] = event.toolTip[0] + " §7(" + difficulty.displayName + "§7)" + val itemName = event.itemStack?.name?.removeColor() ?: return - var index = event.toolTip.indexOf("§5§o§7Reward") - 1 - event.toolTip.add(index++, "") - event.toolTip.add(index++, "§eGuide:") - for (line in it.note) { - event.toolTip.add(index++, line) - } + val toolTip = event.toolTip + val communityGoal = toolTip.getOrNull(1) == "§5§o§8Community Goal" + val bingoTip: BingoTip = if (communityGoal) { + BingoAPI.tips.filter { itemName.startsWith(it.key) }.values.firstOrNull() ?: return + } else { + BingoAPI.tips[itemName] ?: return + } + + if (!communityGoal) { + val difficulty = Difficulty.valueOf(bingoTip.difficulty.uppercase()) + toolTip[0] = toolTip[0] + " §7(" + difficulty.displayName + "§7)" + } + + var index = if (!communityGoal) { + toolTip.indexOf("§5§o§7Reward") + } else { + toolTip.indexOfFirst { it.startsWith("§5§o§7Contribution Rewards") } + } - 1 + + toolTip.add(index++, "") + toolTip.add(index++, "§eGuide:") + for (line in bingoTip.note) { + toolTip.add(index++, line) } } @@ -53,11 +61,13 @@ class BingoCardTips { for (slot in chest.inventorySlots) { if (slot == null) continue if (slot.slotNumber != slot.slotIndex) continue - if (slot.stack == null) continue + val stack = slot.stack ?: continue - val itemName = slot.stack.name ?: continue + val itemName = stack.name ?: continue + val communityGoal = stack.getLore().getOrNull(1) == "§8Community Goal" + if (communityGoal) continue - tips[itemName.removeColor()]?.let { + BingoAPI.tips[itemName.removeColor()]?.let { val difficulty = Difficulty.valueOf(it.difficulty.uppercase()) slot highlight difficulty.color.addOpacity(120) } |
