RGBColor: rename color variable to rgba

This commit is contained in:
Bixilon 2021-04-29 14:20:31 +02:00
parent 2497b9500b
commit d3378abab4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 23 additions and 13 deletions

View File

@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.text
import org.checkerframework.common.value.qual.IntRange import org.checkerframework.common.value.qual.IntRange
class RGBColor(val color: Int) : ChatCode { class RGBColor(val rgba: Int) : ChatCode {
@JvmOverloads @JvmOverloads
constructor(red: Int, green: Int, blue: Int, alpha: Int = 0xFF) : this(alpha or (blue shl 8) or (green shl 16) or (red shl 24)) constructor(red: Int, green: Int, blue: Int, alpha: Int = 0xFF) : this(alpha or (blue shl 8) or (green shl 16) or (red shl 24))
@ -24,22 +24,31 @@ class RGBColor(val color: Int) : ChatCode {
constructor(colorString: String) : this(colorString.toColorInt()) constructor(colorString: String) : this(colorString.toColorInt())
val alpha: @IntRange(from = 0.toLong(), to = 255.toLong()) Int val alpha: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
get() = color and 0xFF get() = rgba and 0xFF
val red: @IntRange(from = 0.toLong(), to = 255.toLong()) Int val red: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
get() = color ushr 24 and 0xFF get() = rgba ushr 24 and 0xFF
val floatRed: @IntRange(from = 0.toLong(), to = 1.toLong()) Float val floatRed: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
get() = red / COLOR_FLOAT_DIVIDER get() = red / COLOR_FLOAT_DIVIDER
val green: @IntRange(from = 0.toLong(), to = 255.toLong()) Int val green: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
get() = color ushr 16 and 0xFF get() = rgba ushr 16 and 0xFF
val floatGreen: @IntRange(from = 0.toLong(), to = 1.toLong()) Float val floatGreen: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
get() = green / COLOR_FLOAT_DIVIDER get() = green / COLOR_FLOAT_DIVIDER
val blue: @IntRange(from = 0.toLong(), to = 255.toLong()) Int val blue: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
get() = color ushr 8 and 0xFF get() = rgba ushr 8 and 0xFF
val floatBlue: @IntRange(from = 0.toLong(), to = 1.toLong()) Float val floatBlue: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
get() = blue / COLOR_FLOAT_DIVIDER get() = blue / COLOR_FLOAT_DIVIDER
val rgb: Int
get() = rgba ushr 8
override fun hashCode(): Int { override fun hashCode(): Int {
return color return rgba
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
@ -47,19 +56,20 @@ class RGBColor(val color: Int) : ChatCode {
return true return true
} }
val their = other as RGBColor? ?: return false val their = other as RGBColor? ?: return false
return color == their.color return rgba == their.rgba
} }
override fun toString(): String { override fun toString(): String {
return if (alpha != 255) { return if (alpha != 255) {
String.format("#%08X", color) String.format("#%08X", rgba)
} else { } else {
String.format("#%06X", 0xFFFFFF and color) String.format("#%06X", 0xFFFFFF and rgba)
} }
} }
companion object { companion object {
private const val COLOR_FLOAT_DIVIDER = 255.0f private const val COLOR_FLOAT_DIVIDER = 255.0f
fun noAlpha(color: Int): RGBColor { fun noAlpha(color: Int): RGBColor {
return RGBColor(color shl 8 or 0xFF) return RGBColor(color shl 8 or 0xFF)
} }

View File

@ -48,7 +48,7 @@ class SectionArrayMesh : Mesh(initialCacheSize = 100000) {
textureCoordinates.y * texture.uvEnd.y, textureCoordinates.y * texture.uvEnd.y,
Float.fromBits(textureLayer), Float.fromBits(textureLayer),
Float.fromBits(texture.properties.animation?.animationId ?: -1), Float.fromBits(texture.properties.animation?.animationId ?: -1),
Float.fromBits(lightColor.color ushr 8), Float.fromBits(lightColor.rgb),
)) ))
} }

View File

@ -38,7 +38,7 @@ class HUDCacheMesh(
if (tintColor == null) { if (tintColor == null) {
0.0f 0.0f
} else { } else {
Float.fromBits(tintColor.color) Float.fromBits(tintColor.rgba)
}, },
)) ))
} }

View File

@ -35,9 +35,9 @@ object RGBColorSerializer : JsonAdapter<RGBColor>() {
jsonWriter.nullValue() jsonWriter.nullValue()
return return
} }
if (color.color == 0) { if (color.rgba == 0) {
jsonWriter.nullValue() jsonWriter.nullValue()
} }
jsonWriter.value(color.color) jsonWriter.value(color.rgba)
} }
} }