aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-25 16:55:33 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-25 16:55:33 +0100
commitc4997e21053c8671ed4c5474fb70df6ae58dae06 (patch)
tree9b17d0fa1a46dc7571fbca8a2d09dc9aaec98dd0 /src/main/kotlin/repo
parentddebaf47900dfab41590c97c202984142ae5b9f6 (diff)
downloadFirmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.tar.gz
Firmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.tar.bz2
Firmament-c4997e21053c8671ed4c5474fb70df6ae58dae06.zip
feat: Add reforge recipes
Diffstat (limited to 'src/main/kotlin/repo')
-rw-r--r--src/main/kotlin/repo/Reforge.kt10
-rw-r--r--src/main/kotlin/repo/SBItemStack.kt26
2 files changed, 25 insertions, 11 deletions
diff --git a/src/main/kotlin/repo/Reforge.kt b/src/main/kotlin/repo/Reforge.kt
index b52adc6..dc0d93d 100644
--- a/src/main/kotlin/repo/Reforge.kt
+++ b/src/main/kotlin/repo/Reforge.kt
@@ -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]
}
}
diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt
index a5f54ae..3c59543 100644
--- a/src/main/kotlin/repo/SBItemStack.kt
+++ b/src/main/kotlin/repo/SBItemStack.kt
@@ -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