mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
remove string constructor in RGBColor, use extension functions
This commit is contained in:
parent
f58d9b6f8b
commit
82483282fe
@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.entities.block
|
|||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
import de.bixilon.minosoft.data.text.ChatColors
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||||
|
|
||||||
class BedBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
|
class BedBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
|
||||||
@ -27,7 +28,7 @@ class BedBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
|
|||||||
color = nbt["color"]?.let {
|
color = nbt["color"]?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is String -> {
|
is String -> {
|
||||||
RGBColor(it)
|
it.asColor()
|
||||||
}
|
}
|
||||||
is Number -> {
|
is Number -> {
|
||||||
when (it.toInt()) {
|
when (it.toInt()) {
|
||||||
|
@ -18,6 +18,8 @@ import de.bixilon.minosoft.data.mappings.registry.RegistryItem
|
|||||||
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
|
import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
|
||||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
import de.bixilon.minosoft.gui.rendering.TintColorCalculator
|
import de.bixilon.minosoft.gui.rendering.TintColorCalculator
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
@ -55,6 +57,7 @@ data class Biome(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object : ResourceLocationDeserializer<Biome> {
|
companion object : ResourceLocationDeserializer<Biome> {
|
||||||
|
private val TODO_SWAMP_COLOR = "#6A7039".asColor()
|
||||||
override fun deserialize(mappings: VersionMapping?, resourceLocation: ResourceLocation, data: JsonObject): Biome {
|
override fun deserialize(mappings: VersionMapping?, resourceLocation: ResourceLocation, data: JsonObject): Biome {
|
||||||
check(mappings != null) { "VersionMapping is null!" }
|
check(mappings != null) { "VersionMapping is null!" }
|
||||||
return Biome(
|
return Biome(
|
||||||
@ -67,7 +70,7 @@ data class Biome(
|
|||||||
waterFogColor = TintColorCalculator.getJsonColor(data["water_fog_color"]?.asInt ?: 0),
|
waterFogColor = TintColorCalculator.getJsonColor(data["water_fog_color"]?.asInt ?: 0),
|
||||||
category = mappings.biomeCategoryRegistry.get(data["category"]?.asInt ?: -1) ?: DEFAULT_CATEGORY,
|
category = mappings.biomeCategoryRegistry.get(data["category"]?.asInt ?: -1) ?: DEFAULT_CATEGORY,
|
||||||
precipitation = mappings.biomePrecipitationRegistry.get(data["precipitation"]?.asInt ?: -1) ?: DEFAULT_PRECIPITATION,
|
precipitation = mappings.biomePrecipitationRegistry.get(data["precipitation"]?.asInt ?: -1) ?: DEFAULT_PRECIPITATION,
|
||||||
skyColor = data["sky_color"]?.asInt?.let { RGBColor.noAlpha(it) } ?: RenderConstants.GRASS_FAILOVER_COLOR,
|
skyColor = data["sky_color"]?.asInt?.let { it.asRGBColor() } ?: RenderConstants.GRASS_FAILOVER_COLOR,
|
||||||
foliageColorOverride = TintColorCalculator.getJsonColor(data["foliage_color_override"]?.asInt ?: 0),
|
foliageColorOverride = TintColorCalculator.getJsonColor(data["foliage_color_override"]?.asInt ?: 0),
|
||||||
grassColorOverride = TintColorCalculator.getJsonColor(data["grass_color_override"]?.asInt ?: 0),
|
grassColorOverride = TintColorCalculator.getJsonColor(data["grass_color_override"]?.asInt ?: 0),
|
||||||
descriptionId = data["water_fog_color"]?.asString,
|
descriptionId = data["water_fog_color"]?.asString,
|
||||||
@ -89,7 +92,7 @@ data class Biome(
|
|||||||
DARK_FOREST({ color: RGBColor -> color }), // ToDo: This rgb 2634762 should be added to this?
|
DARK_FOREST({ color: RGBColor -> color }), // ToDo: This rgb 2634762 should be added to this?
|
||||||
SWAMP({
|
SWAMP({
|
||||||
// ToDo: Minecraft uses PerlinSimplexNoise here
|
// ToDo: Minecraft uses PerlinSimplexNoise here
|
||||||
RGBColor("#6A7039")
|
TODO_SWAMP_COLOR
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import de.bixilon.minosoft.data.mappings.registry.ResourceLocationDeserializer
|
|||||||
import de.bixilon.minosoft.data.mappings.registry.Translatable
|
import de.bixilon.minosoft.data.mappings.registry.Translatable
|
||||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
|
||||||
import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix
|
import de.bixilon.minosoft.datafixer.EntityAttributeFixer.fix
|
||||||
|
|
||||||
data class StatusEffect(
|
data class StatusEffect(
|
||||||
@ -47,7 +48,7 @@ data class StatusEffect(
|
|||||||
resourceLocation = resourceLocation,
|
resourceLocation = resourceLocation,
|
||||||
category = StatusEffectCategories.NAME_MAP[data["category"].asString]!!,
|
category = StatusEffectCategories.NAME_MAP[data["category"].asString]!!,
|
||||||
translationKey = data["translation_key"]?.asString,
|
translationKey = data["translation_key"]?.asString,
|
||||||
color = RGBColor.noAlpha(data["color"].asInt),
|
color = data["color"].asInt.asRGBColor(),
|
||||||
attributes.toMap(),
|
attributes.toMap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.text
|
|||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
import de.bixilon.minosoft.gui.rendering.font.text.TextGetProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
import de.bixilon.minosoft.gui.rendering.font.text.TextSetProperties
|
||||||
@ -94,7 +95,7 @@ class BaseComponent : ChatComponent {
|
|||||||
|
|
||||||
val color = json["color"]?.asString?.let { colorName ->
|
val color = json["color"]?.asString?.let { colorName ->
|
||||||
if (colorName.startsWith("#")) {
|
if (colorName.startsWith("#")) {
|
||||||
RGBColor(colorName)
|
colorName.asColor()
|
||||||
} else {
|
} else {
|
||||||
ChatColors.getColorByName(colorName)
|
ChatColors.getColorByName(colorName)
|
||||||
}
|
}
|
||||||
|
@ -21,27 +21,25 @@ class RGBColor(val rgba: Int) : ChatCode {
|
|||||||
|
|
||||||
constructor(red: Byte, green: Byte, blue: Byte, alpha: Byte = 0xFF.toByte()) : this(red.toInt() and 0xFF, green.toInt() and 0xFF, blue.toInt() and 0xFF, alpha.toInt() and 0xFF)
|
constructor(red: Byte, green: Byte, blue: Byte, alpha: Byte = 0xFF.toByte()) : this(red.toInt() and 0xFF, green.toInt() and 0xFF, blue.toInt() and 0xFF, alpha.toInt() and 0xFF)
|
||||||
|
|
||||||
constructor(colorString: String) : this(colorString.toColorInt())
|
val alpha: @IntRange(from = 0L, to = 255L) Int
|
||||||
|
|
||||||
val alpha: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
|
|
||||||
get() = rgba and 0xFF
|
get() = rgba and 0xFF
|
||||||
|
|
||||||
val red: @IntRange(from = 0.toLong(), to = 255.toLong()) Int
|
val red: @IntRange(from = 0L, to = 255L) Int
|
||||||
get() = rgba ushr 24 and 0xFF
|
get() = rgba ushr 24 and 0xFF
|
||||||
|
|
||||||
val floatRed: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
|
val floatRed: @IntRange(from = 0L, to = 1L) 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 = 0L, to = 255L) Int
|
||||||
get() = rgba ushr 16 and 0xFF
|
get() = rgba ushr 16 and 0xFF
|
||||||
|
|
||||||
val floatGreen: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
|
val floatGreen: @IntRange(from = 0L, to = 1L) 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 = 0L, to = 255L) Int
|
||||||
get() = rgba ushr 8 and 0xFF
|
get() = rgba ushr 8 and 0xFF
|
||||||
|
|
||||||
val floatBlue: @IntRange(from = 0.toLong(), to = 1.toLong()) Float
|
val floatBlue: @IntRange(from = 0L, to = 1L) Float
|
||||||
get() = blue / COLOR_FLOAT_DIVIDER
|
get() = blue / COLOR_FLOAT_DIVIDER
|
||||||
|
|
||||||
val rgb: Int
|
val rgb: Int
|
||||||
@ -63,33 +61,35 @@ class RGBColor(val rgba: Int) : ChatCode {
|
|||||||
return if (alpha != 255) {
|
return if (alpha != 255) {
|
||||||
String.format("#%08X", rgba)
|
String.format("#%08X", rgba)
|
||||||
} else {
|
} else {
|
||||||
String.format("#%06X", 0xFFFFFF and rgba)
|
String.format("#%06X", rgb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 String.asColor(): RGBColor {
|
||||||
return RGBColor(color shl 8 or 0xFF)
|
return RGBColor(let {
|
||||||
|
var colorString = this
|
||||||
|
if (colorString.startsWith("#")) {
|
||||||
|
colorString = colorString.substring(1)
|
||||||
|
}
|
||||||
|
return@let if (colorString.length == 6) {
|
||||||
|
Integer.parseUnsignedInt(colorString + "ff", 16)
|
||||||
|
} else {
|
||||||
|
Integer.parseUnsignedInt(colorString, 16)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toColor(): RGBColor {
|
fun Int.asRGBColor(): RGBColor {
|
||||||
|
return RGBColor(this shl 8 or 0xFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Int.asRGBAColor(): RGBColor {
|
||||||
return RGBColor(this)
|
return RGBColor(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toColorInt(): Int {
|
|
||||||
var colorString = this
|
|
||||||
if (colorString.startsWith("#")) {
|
|
||||||
colorString = colorString.substring(1)
|
|
||||||
}
|
|
||||||
return if (colorString.length == 6) {
|
|
||||||
Integer.parseUnsignedInt(colorString + "ff", 16)
|
|
||||||
} else {
|
|
||||||
Integer.parseUnsignedInt(colorString, 16)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mix(vararg colors: RGBColor): RGBColor {
|
fun mix(vararg colors: RGBColor): RGBColor {
|
||||||
var red = 0
|
var red = 0
|
||||||
var green = 0
|
var green = 0
|
||||||
|
@ -15,25 +15,27 @@ package de.bixilon.minosoft.gui.rendering
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
|
|
||||||
object RenderConstants {
|
object RenderConstants {
|
||||||
const val DISABLE_RENDERING = false
|
const val DISABLE_RENDERING = false
|
||||||
|
|
||||||
val DEFAULT_SKY_COLOR = RGBColor("#ecff89")
|
val DEFAULT_SKY_COLOR = "#ecff89".asColor()
|
||||||
val WHITE_COLOR = RGBColor("#ffffff")
|
val WHITE_COLOR = "#ffffff".asColor()
|
||||||
val BLACK_COLOR = RGBColor("#000000")
|
val BLACK_COLOR = "#000000".asColor()
|
||||||
|
|
||||||
val GRASS_FAILOVER_COLOR = RGBColor("#48B518")
|
val GRASS_FAILOVER_COLOR = "#48B518".asColor()
|
||||||
|
|
||||||
val GRASS_OUT_OF_BOUNDS_COLOR = RGBColor(-65281)
|
val GRASS_OUT_OF_BOUNDS_COLOR = (-65281).asRGBColor()
|
||||||
|
|
||||||
val LILY_PAD_INVENTORY_COLOR = RGBColor("#71C35C")
|
val LILY_PAD_INVENTORY_COLOR = "#71C35C".asColor()
|
||||||
val LILY_PAD_BLOCK_COLOR = RGBColor("#208030")
|
val LILY_PAD_BLOCK_COLOR = "#208030".asColor()
|
||||||
|
|
||||||
|
|
||||||
val EXPERIENCE_BAR_LEVEL_COLOR = RGBColor("#80ff20")
|
val EXPERIENCE_BAR_LEVEL_COLOR = "#80ff20".asColor()
|
||||||
val HP_TEXT_COLOR = RGBColor("#ff1313")
|
val HP_TEXT_COLOR = "#ff1313".asColor()
|
||||||
|
|
||||||
const val COLORMAP_SIZE = 255
|
const val COLORMAP_SIZE = 255
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.config.StaticConfiguration
|
|||||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||||
import de.bixilon.minosoft.gui.input.camera.FrustumChangeCallback
|
import de.bixilon.minosoft.gui.input.camera.FrustumChangeCallback
|
||||||
import de.bixilon.minosoft.gui.input.key.RenderWindowInputHandler
|
import de.bixilon.minosoft.gui.input.key.RenderWindowInputHandler
|
||||||
import de.bixilon.minosoft.gui.modding.events.RenderingStateChangeEvent
|
import de.bixilon.minosoft.gui.modding.events.RenderingStateChangeEvent
|
||||||
@ -177,7 +178,7 @@ class RenderWindow(
|
|||||||
// Make the window visible
|
// Make the window visible
|
||||||
GL.createCapabilities()
|
GL.createCapabilities()
|
||||||
|
|
||||||
setSkyColor(RGBColor("#fffe7a"))
|
setSkyColor("#fffe7a".asColor())
|
||||||
|
|
||||||
Log.log(LogMessageType.RENDERING_LOADING) { "Enabling all open gl features (${stopwatch.labTime()})..." }
|
Log.log(LogMessageType.RENDERING_LOADING) { "Enabling all open gl features (${stopwatch.labTime()})..." }
|
||||||
glEnable(GL_DEPTH_TEST)
|
glEnable(GL_DEPTH_TEST)
|
||||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.mappings.ResourceLocation
|
|||||||
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
|
||||||
import de.bixilon.minosoft.data.world.World
|
import de.bixilon.minosoft.data.world.World
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
import glm_.vec3.Vec3i
|
import glm_.vec3.Vec3i
|
||||||
@ -136,7 +137,7 @@ class TintColorCalculator(val world: World) {
|
|||||||
if (color == 0) {
|
if (color == 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return RGBColor.noAlpha(color)
|
return color.asRGBColor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.util.json
|
|||||||
|
|
||||||
import com.squareup.moshi.*
|
import com.squareup.moshi.*
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor.Companion.asRGBColor
|
||||||
|
|
||||||
object RGBColorSerializer : JsonAdapter<RGBColor>() {
|
object RGBColorSerializer : JsonAdapter<RGBColor>() {
|
||||||
@FromJson
|
@FromJson
|
||||||
@ -26,7 +27,7 @@ object RGBColorSerializer : JsonAdapter<RGBColor>() {
|
|||||||
if (rgb == 0) {
|
if (rgb == 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return RGBColor.noAlpha(rgb)
|
return rgb.asRGBColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ToJson
|
@ToJson
|
||||||
@ -35,9 +36,9 @@ object RGBColorSerializer : JsonAdapter<RGBColor>() {
|
|||||||
jsonWriter.nullValue()
|
jsonWriter.nullValue()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (color.rgba == 0) {
|
if (color.rgb == 0) {
|
||||||
jsonWriter.nullValue()
|
jsonWriter.nullValue()
|
||||||
}
|
}
|
||||||
jsonWriter.value(color.rgba)
|
jsonWriter.value(color.rgb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user