aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/skyblock/Rarity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util/skyblock/Rarity.kt')
-rw-r--r--src/main/kotlin/util/skyblock/Rarity.kt43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/Rarity.kt b/src/main/kotlin/util/skyblock/Rarity.kt
index f244ef6..0b26bda 100644
--- a/src/main/kotlin/util/skyblock/Rarity.kt
+++ b/src/main/kotlin/util/skyblock/Rarity.kt
@@ -13,10 +13,14 @@ import net.minecraft.text.Text
import net.minecraft.util.Formatting
import moe.nea.firmament.util.StringUtil.words
import moe.nea.firmament.util.collections.lastNotNullOfOrNull
+import moe.nea.firmament.util.directLiteralStringContent
import moe.nea.firmament.util.mc.loreAccordingToNbt
import moe.nea.firmament.util.petData
+import moe.nea.firmament.util.prepend
+import moe.nea.firmament.util.prependHypixelified
import moe.nea.firmament.util.removeColorCodes
import moe.nea.firmament.util.unformattedString
+import moe.nea.firmament.util.withColor
typealias RepoRarity = io.github.moulberry.repo.data.Rarity
@@ -52,6 +56,10 @@ enum class Rarity(vararg altNames: String) {
val text: Text get() = Text.literal(name).setStyle(Style.EMPTY.withColor(colourMap[this]))
val neuRepoRarity: RepoRarity? = RepoRarity.entries.find { it.name == name }
+ fun recombobulate(): Rarity = Rarity.entries.getOrElse(ordinal + 1) { this }
+
+ fun colour() = colourMap[this] ?: Formatting.WHITE
+
companion object {
// TODO: inline those formattings as fields
val colourMap = mapOf(
@@ -94,11 +102,46 @@ enum class Rarity(vararg altNames: String) {
}
}
+ fun findLoreIndex(lore: List<Text>): Int {
+ return lore.indexOfLast {
+ it.unformattedString.words().any { fromString(it) != null }
+ }
+ }
+
fun fromLore(lore: List<Text>): Rarity? =
lore.lastNotNullOfOrNull {
it.unformattedString.words()
.firstNotNullOfOrNull(::fromString)
}
+ fun recombobulateLore(lore: List<Text>): List<Text> {
+ val before = fromLore(lore) ?: return lore
+ val rarityIndex = findLoreIndex(lore)
+ if (rarityIndex < 0) return lore
+ val after = before.recombobulate()
+ val col = after.colour()
+ val loreMut = lore.toMutableList()
+ val obfuscatedTag = Text.literal("a")
+ .withColor(col)
+ .styled { it.withObfuscated(true) }
+ val rarityLine = loreMut[rarityIndex].copy()
+ .prependHypixelified(Text.literal(" "))
+ .prepend(obfuscatedTag)
+ .append(Text.literal(" "))
+ .append(obfuscatedTag)
+ (rarityLine.siblings as MutableList<Text>)
+ .replaceAll {
+ var content = it.directLiteralStringContent
+ before.names.forEach {
+ content = content?.replace(it, after.name)
+ }
+ val editedText = (if (content != it.directLiteralStringContent)
+ Text.literal(content) else it.copy())
+ editedText.withColor(col)
+ }
+ loreMut[rarityIndex] = rarityLine
+ return loreMut
+ }
+
}
}