feat: Add reforge recipes

This commit is contained in:
Linnea Gräf
2024-12-25 16:55:33 +01:00
parent ddebaf4790
commit c4997e2105
5 changed files with 65 additions and 21 deletions

View File

@@ -36,6 +36,10 @@ data class Reforge(
) {
val eligibleItems get() = allowOn ?: itemTypes ?: listOf()
val statUniverse: Set<String> = Rarity.entries.flatMapTo(mutableSetOf()) {
reforgeStats?.get(it)?.keys ?: emptySet()
}
@Serializable(with = ReforgeEligibilityFilter.Serializer::class)
sealed interface ReforgeEligibilityFilter {
object ItemTypesSerializer : KSerializer<List<ReforgeEligibilityFilter>> {
@@ -108,7 +112,7 @@ data class Reforge(
@Serializable(with = RarityMapped.Serializer::class)
sealed interface RarityMapped<T> {
fun get(rarity: Rarity): T?
fun get(rarity: Rarity?): T?
class Serializer<T>(
val values: KSerializer<T>
@@ -140,14 +144,14 @@ data class Reforge(
@Serializable
data class Direct<T>(val value: T) : RarityMapped<T> {
override fun get(rarity: Rarity): T {
override fun get(rarity: Rarity?): T {
return value
}
}
@Serializable
data class PerRarity<T>(val values: Map<Rarity, T>) : RarityMapped<T> {
override fun get(rarity: Rarity): T? {
override fun get(rarity: Rarity?): T? {
return values[rarity]
}
}

View File

@@ -18,7 +18,6 @@ import moe.nea.firmament.util.FirmFormatters
import moe.nea.firmament.util.LegacyFormattingCode
import moe.nea.firmament.util.ReforgeId
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.blue
import moe.nea.firmament.util.directLiteralStringContent
import moe.nea.firmament.util.extraAttributes
import moe.nea.firmament.util.getReforgeId
@@ -179,21 +178,30 @@ data class SBItemStack constructor(
}
fun formatValue() =
Text.literal(FirmFormatters.formatCommas(valueNum ?: 0.0, 1, includeSign = true) + statFormatting.postFix + " ")
Text.literal(FirmFormatters.formatCommas(valueNum ?: 0.0,
1,
includeSign = true) + statFormatting.postFix + " ")
.setStyle(Style.EMPTY.withColor(statFormatting.color))
val statFormatting = formattingOverrides[statName] ?: StatFormatting("", Formatting.GREEN)
fun reconstitute(): Text =
private fun abbreviate(abbreviateTo: Int): String {
if (abbreviateTo >= statName.length) return statName
val segments = statName.split(" ")
return segments.joinToString(" ") {
it.substring(0, maxOf(1, abbreviateTo / segments.size))
}
}
fun reconstitute(abbreviateTo: Int = Int.MAX_VALUE): Text =
Text.literal("").setStyle(Style.EMPTY.withItalic(false))
.append(Text.literal("$statName: ").grey())
.append(Text.literal("${abbreviate(abbreviateTo)}: ").grey())
.append(value ?: formatValue())
.also { rest.forEach(it::append) }
}
private fun statIdToName(statId: String): String {
return statId.split("_").joinToString(" ") {
it.replaceFirstChar { it.uppercaseChar() }
}
fun statIdToName(statId: String): String {
val segments = statId.split("_")
return segments.joinToString(" ") { it.replaceFirstChar { it.uppercaseChar() } }
}
private fun parseStatLine(line: Text): StatLine? {
@@ -271,6 +279,8 @@ data class SBItemStack constructor(
// TODO: avoid instantiating the item stack here
val itemType: ItemType? get() = ItemType.fromItemStack(asImmutableItemStack())
val rarity: Rarity? get() = Rarity.fromItem(asImmutableItemStack())
private var itemStack_: ItemStack? = null
private val itemStack: ItemStack