ColorHolder

data class ColorHolder(val r: Int, val g: Int, val b: Int, val a: Int, alphaMode: Boolean) : EntryHandler<ValidatedColor.ColorHolder>

An immutable holder of an ARGB color value. The return type of ValidatedColor, which can be used directly in code or shortcutted with helper functions in ValdiatedColor to get Int or Hex String values instead.

Author

fzzyhmstrs

Since

0.2.0

Parameters

r

int value of r component (0..255)

g

int value of g component (0..255)

b

int value of b component (0..255)

a

int value of a component (0..255)

alphaMode

whether this color holder supports transparency

Samples

import me.fzzyhmstrs.fzzy_config.util.AllowableIdentifiers
import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.util.FcText.lit
import me.fzzyhmstrs.fzzy_config.util.ValidationResult
import me.fzzyhmstrs.fzzy_config.validation.collection.ValidatedList
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedRegistryType
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedTagKey
import me.fzzyhmstrs.fzzy_config.validation.misc.*
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedColor.Companion.validatedColor
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedInt
import net.minecraft.item.Items
import net.minecraft.item.SwordItem
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
import java.awt.Color
import java.util.function.Function

fun main() { 
   //sampleStart 
   //generate a color holder from a ValidatedColor wrapper
val validatedColor: ValidatedColor = ValidatedColor(255, 128, 0, 255)

// the wrapped ColorHolder
val holder: ValidatedColor.ColorHolder = validatedColor.get()

//we can get color values from it
val r: Int = holder.r //255
val g: Int = holder.g //128
val argb: Int = holder.argb()

//color holders are immutable, we can mutate them via a MutableColor though
val mutable: ValidatedColor.MutableColor = holder.mutable()

//update the RGB to something new
mutable.updateRGB(128, 0, 128)

//the colors HSL is automatically updated too
val h = mutable.h
val l = mutable.l

// once we are done, we can update our ValidatedColor
validatedColor.validateAndSet(mutable.createHolder()) 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(r: Int, g: Int, b: Int, a: Int, alphaMode: Boolean)

Properties

Link copied to clipboard
val a: Int
Link copied to clipboard
val b: Int
Link copied to clipboard
val g: Int
Link copied to clipboard
val r: Int

Functions

Link copied to clipboard
fun argb(): Int

returns ARGB color int representing this color

Link copied to clipboard

Copies the provided input as deeply as possible.

Link copied to clipboard
open fun deserializedChanged(old: Any?, new: Any?): Boolean

Specialized equals method for determining if a newly deserialized value is effectively equal to its old counterpart.

Link copied to clipboard

converts this color holder into a new one representing the color integer passed. AlphaMode is maintained

Link copied to clipboard

Creates a deep copy of this color holder and wraps it

Link copied to clipboard
fun mutable(hex: ValidatedString = validatedString(toHexString(), opaque())): ValidatedColor.MutableColor

Generates a MutableColor from this color holder

Link copied to clipboard

If this color holder does NOT support transparency

Link copied to clipboard

converts this color holder to a hex string (without prefix)

Link copied to clipboard
fun toInt(): Int

returns ARGB color int representing this color

Link copied to clipboard

If this color holder supports transparency