aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/texturepack/RarityMatcher.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-07 13:26:03 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-07 13:26:03 +0100
commitbf7795df22ca7892fae1238403feebb57c005562 (patch)
tree3a49db5bade38498f976321b6e9008203f2d4d3b /src/main/kotlin/features/texturepack/RarityMatcher.kt
parentcdb5e60f52eea9030af9ca2d4a49913664023965 (diff)
downloadFirmament-bf7795df22ca7892fae1238403feebb57c005562.tar.gz
Firmament-bf7795df22ca7892fae1238403feebb57c005562.tar.bz2
Firmament-bf7795df22ca7892fae1238403feebb57c005562.zip
WIP: Port to compilation on 1.21.4
Diffstat (limited to 'src/main/kotlin/features/texturepack/RarityMatcher.kt')
-rw-r--r--src/main/kotlin/features/texturepack/RarityMatcher.kt69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/main/kotlin/features/texturepack/RarityMatcher.kt b/src/main/kotlin/features/texturepack/RarityMatcher.kt
deleted file mode 100644
index 634a171..0000000
--- a/src/main/kotlin/features/texturepack/RarityMatcher.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-
-package moe.nea.firmament.features.texturepack
-
-import com.google.gson.JsonElement
-import io.github.moulberry.repo.data.Rarity
-import moe.nea.firmament.util.useMatch
-
-abstract class RarityMatcher {
- abstract fun match(rarity: Rarity): Boolean
-
- companion object {
- fun parse(jsonElement: JsonElement): RarityMatcher {
- val string = jsonElement.asString
- val range = parseRange(string)
- if (range != null) return range
- return Exact(Rarity.valueOf(string))
- }
-
- private val allRarities = Rarity.entries.joinToString("|", "(?:", ")")
- private val intervalSpec =
- "(?<beginningOpen>[\\[\\(])(?<beginning>$allRarities)?,(?<ending>$allRarities)?(?<endingOpen>[\\]\\)])"
- .toPattern()
-
- fun parseRange(string: String): RangeMatcher? {
- intervalSpec.useMatch<Nothing>(string) {
- // Open in the set-theory sense, meaning does not include its end.
- val beginningOpen = group("beginningOpen") == "("
- val endingOpen = group("endingOpen") == ")"
- val beginning = group("beginning")?.let(Rarity::valueOf)
- val ending = group("ending")?.let(Rarity::valueOf)
- return RangeMatcher(beginning, !beginningOpen, ending, !endingOpen)
- }
- return null
- }
-
- }
-
- data class Exact(val expected: Rarity) : RarityMatcher() {
- override fun match(rarity: Rarity): Boolean {
- return rarity == expected
- }
- }
-
- data class RangeMatcher(
- val beginning: Rarity?,
- val beginningInclusive: Boolean,
- val ending: Rarity?,
- val endingInclusive: Boolean,
- ) : RarityMatcher() {
- override fun match(rarity: Rarity): Boolean {
- if (beginning != null) {
- if (beginningInclusive) {
- if (rarity < beginning) return false
- } else {
- if (rarity <= beginning) return false
- }
- }
- if (ending != null) {
- if (endingInclusive) {
- if (rarity > ending) return false
- } else {
- if (rarity >= ending) return false
- }
- }
- return true
- }
- }
-
-}