diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-07-10 17:53:00 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-07-10 17:53:00 +0200 |
commit | d5b4500d684bca13ef02b133dfd62a02b26928e3 (patch) | |
tree | b0fa53e021fc8a629daddf430ef2249c6500e56d /src/main/java/at/hannibal2/skyhanni | |
parent | 5684e336e2c85df68f5928a35786605c64f23383 (diff) | |
download | skyhanni-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')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt | 34 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt | 2 |
2 files changed, 24 insertions, 12 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 } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt index 769b1a962..ba1c0d8ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt @@ -180,7 +180,7 @@ class BlazeSlayerDaggerHelper { val packet = event.packet - if (packet !is S45PacketTitle) return + if (packet !is S45PacketTitle) return // TODO add a title event val message = packet.message ?: return val formattedText = message.formattedText |