From bf7795df22ca7892fae1238403feebb57c005562 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 7 Dec 2024 13:26:03 +0100 Subject: WIP: Port to compilation on 1.21.4 --- .../kotlin/features/texturepack/TintOverrides.kt | 75 ---------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/main/kotlin/features/texturepack/TintOverrides.kt (limited to 'src/main/kotlin/features/texturepack/TintOverrides.kt') diff --git a/src/main/kotlin/features/texturepack/TintOverrides.kt b/src/main/kotlin/features/texturepack/TintOverrides.kt deleted file mode 100644 index 85fcae4..0000000 --- a/src/main/kotlin/features/texturepack/TintOverrides.kt +++ /dev/null @@ -1,75 +0,0 @@ -package moe.nea.firmament.features.texturepack - -import com.google.gson.JsonObject -import com.google.gson.JsonPrimitive -import moe.nea.firmament.util.ErrorUtil - -data class TintOverrides( - val layerMap: Map = mapOf() -) { - val hasOverrides by lazy { layerMap.values.any { it !is Reset } } - - companion object { - val EMPTY = TintOverrides() - private val threadLocal = object : ThreadLocal() {} - fun enter(overrides: TintOverrides?) { - ErrorUtil.softCheck("Double entered tintOverrides", - threadLocal.get() == null) - threadLocal.set(overrides ?: EMPTY) - } - - fun exit(overrides: TintOverrides?) { - ErrorUtil.softCheck("Exited with non matching enter tintOverrides", - threadLocal.get() == (overrides ?: EMPTY)) - threadLocal.remove() - } - - fun getCurrentOverrides(): TintOverrides { - return ErrorUtil.notNullOr(threadLocal.get(), "Got current tintOverrides without entering") { - EMPTY - } - } - - fun parse(jsonObject: JsonObject): TintOverrides { - val map = mutableMapOf() - for ((key, value) in jsonObject.entrySet()) { - val layerIndex = - ErrorUtil.notNullOr(key.toIntOrNull(), - "Unknown layer index $value. Should be integer") { continue } - if (value.isJsonNull) { - map[layerIndex] = Reset - continue - } - val override = (value as? JsonPrimitive) - ?.takeIf(JsonPrimitive::isNumber) - ?.asInt - ?.let(::Fixed) - if (override == null) { - ErrorUtil.softError("Invalid tint override for a layer: $value") - continue - } - map[layerIndex] = override - } - return TintOverrides(map) - } - } - - fun mergeWithParent(parent: TintOverrides): TintOverrides { - val mergedMap = parent.layerMap.toMutableMap() - mergedMap.putAll(this.layerMap) - return TintOverrides(mergedMap) - } - - fun hasOverrides(): Boolean = hasOverrides - fun getOverride(tintIndex: Int): Int? { - return when (val tint = layerMap[tintIndex]) { - is Reset -> null - is Fixed -> tint.color - null -> null - } - } - - sealed interface TintOverride - data object Reset : TintOverride - data class Fixed(val color: Int) : TintOverride -} -- cgit