aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/rift
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-10 17:53:00 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-10 17:53:00 +0200
commitd5b4500d684bca13ef02b133dfd62a02b26928e3 (patch)
treeb0fa53e021fc8a629daddf430ef2249c6500e56d /src/main/java/at/hannibal2/skyhanni/features/rift
parent5684e336e2c85df68f5928a35786605c64f23383 (diff)
downloadskyhanni-d5b4500d684bca13ef02b133dfd62a02b26928e3.tar.gz
skyhanni-d5b4500d684bca13ef02b133dfd62a02b26928e3.tar.bz2
skyhanni-d5b4500d684bca13ef02b133dfd62a02b26928e3.zip
Using the with logic to make the code more readable
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/rift')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
index 9cc152e7f..53b31902b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
@@ -32,20 +32,32 @@ object DanceRoomHelper {
add("§cTry §e/shreloadlocalrepo §cor §e/shupdaterepo")
}
for ((lineIndex, line) in instructions.withIndex()) {
- if (line != null) {
- if (index < instructions.size && index == lineIndex) {
- add("${config.danceRoomFormatting.now.replace("&", "§")} ${line.format()} ${if (countdown != null) "${config.danceRoomFormatting.color.countdown.replace("&", "§")}$countdown" else ""}")
- } else if (index + 1 < instructions.size && index + 1 == lineIndex) {
- add("${config.danceRoomFormatting.next.replace("&", "§")} ${line.format()}")
- } else if (index + 2 < instructions.size && (index + 2..index + config.lineToShow).contains(lineIndex)) {
- add("${config.danceRoomFormatting.later.replace("&", "§")} ${line.format()}")
- }
- }
+ addLine(lineIndex, line)?.let { add(it) }
}
}
}
- private fun String.format() = split(" ").joinToString(" ") { it.firstLetterUppercase().addColor().replace("&", "§") }
+ private fun addLine(lineIndex: Int, line: String) = with(config.danceRoomFormatting) {
+ val size = instructions.size
+ val format = line.format()
+
+ if (index < size && index == lineIndex) {
+ val countdown = countdown?.let { "${color.countdown.formatColor()}$it" } ?: ""
+ "${now.formatColor()} $format $countdown"
+
+ } else if (index + 1 < size && index + 1 == lineIndex) {
+ "${next.formatColor()} $format"
+
+ } else if (index + 2 < size && (index + 2..index + config.lineToShow).contains(lineIndex)) {
+ "${later.formatColor()} $format"
+
+ } else null
+ }
+
+ private fun String.formatColor() = replace("&", "§")
+
+ private fun String.format() =
+ split(" ").joinToString(" ") { it.firstLetterUppercase().addColor().replace("&", "§") }
private fun String.addColor() = when (this) {
"Move" -> config.danceRoomFormatting.color.move
@@ -103,7 +115,7 @@ object DanceRoomHelper {
fun onPacket(event: PacketEvent.ReceiveEvent) {
if (!isEnabled()) return
val packet = event.packet
- if (packet !is S45PacketTitle) return
+ if (packet !is S45PacketTitle) return // TODO add a title event
if (config.hideOriginalTitle && inRoom) event.isCanceled = true
}