From a2d17be9e0fa7155aab1990cb5969ced6305ba1b Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Thu, 13 Jun 2024 22:52:49 +0200 Subject: Fix: Elapsed Time in Dungeons DiscordRPC (#2089) Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../skyhanni/features/dungeon/DungeonAPI.kt | 34 +++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt index e79abbe7c..b6d1ba219 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt @@ -22,6 +22,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary +import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -55,26 +56,33 @@ object DungeonAPI { var isUniqueClass = false val bossStorage: MutableMap? get() = ProfileStorageData.profileSpecific?.dungeons?.bosses - private val timePattern = - "Time Elapsed:( )?(?:(?\\d+)m)? (?\\d+)s".toPattern() // Examples: Time Elapsed: 10m 10s, Time Elapsed: 2s private val patternGroup = RepoPattern.group("dungeon") + /** + * REGEX-TEST: Time Elapsed: §a01m 17s + * REGEX-TEST: Time Elapsed: §a14s + */ + private val timePattern by patternGroup.pattern( + "time", + "Time Elapsed: §.(?:(?\\d+)m )?(?\\d+)s", + ) + private val dungeonComplete by patternGroup.pattern( "complete", - "§.\\s+§.§.(?:The|Master Mode) Catacombs §.§.- §.§.(?:Floor )?(?M?[IV]{1,3}|Entrance)" + "§.\\s+§.§.(?:The|Master Mode) Catacombs §.§.- §.§.(?:Floor )?(?M?[IV]{1,3}|Entrance)", ) private val dungeonRoomPattern by patternGroup.pattern( "room", - "§7\\d+\\/\\d+\\/\\d+ §\\w+ (?[\\w,-]+)" + "§7\\d+\\/\\d+\\/\\d+ §\\w+ (?[\\w,-]+)", ) private val blessingPattern by patternGroup.pattern( "blessings", - "§r§r§fBlessing of (?\\w+) (?\\w+)§r" + "§r§r§fBlessing of (?\\w+) (?\\w+)§r", ) private val noBlessingPattern by patternGroup.pattern( "noblessings", - "§r§r§7No Buffs active. Find them by exploring the Dungeon!§r" + "§r§r§7No Buffs active. Find them by exploring the Dungeon!§r", ) enum class DungeonBlessings(var power: Int) { @@ -124,12 +132,10 @@ object DungeonAPI { return bossName.endsWith(correctBoss) } - fun getTime(): String { + fun getTime(): String = ScoreboardData.sidebarLinesFormatted.matchFirst(timePattern) { - return "${group("minutes") ?: "00"}:${group("seconds")}" // 03:14 - } - return "" - } + "${groupOrNull("minutes") ?: "00"}:${group("seconds")}" + } ?: "" fun getCurrentBoss(): DungeonFloor? { val floor = dungeonFloor ?: return null @@ -320,8 +326,8 @@ object DungeonAPI { add("playerClassLevel: $playerClassLevel") add("") add("Blessings: ") - for (blessing in DungeonBlessings.entries) { - add(" ${blessing.displayName} ${blessing.power}") + DungeonBlessings.entries.forEach { + add(" ${it.displayName} ${it.power}") } } } @@ -331,7 +337,7 @@ object DungeonAPI { BERSERK("Berserk"), HEALER("Healer"), MAGE("Mage"), - TANK("Tank") + TANK("Tank"), } enum class DungeonChest(val inventory: String) { -- cgit