ValidatedColor

constructor(r: Int, g: Int, b: Int, a: Int = Int.MIN_VALUE)

A validated color value

This is a ValidatedField of type ColorHolder, a basic Color data class.

Author

fzzyhmstrs

Since

0.1.2

Parameters

r

the default red component, 0 to 255

g

the default green component, 0 to 255

b

the default blue component, 0 to 255

a

the default alpha(transparency) component, 0 to 255 or Int.MIN_VALUE to set the color as opaque. Defaults to Int.MIN_VALUE

See also

Throws

if the input RGBA values aren't in bounds (not in the range 0..255)

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 
   //example validated color. defined with standard integer RGBA color components [0-225]
//this example has transparency enabled. To allow only opaque colors, use the RGB overload or input Int.MIN_VALUE
val validatedColor = ValidatedColor(255, 128, 0, 255)

//this validated color allows opaque colors only
val validatedColorOpaque = ValidatedColor(0, 128, 255)

//this validated color allows opaque colors only
val validatedColorSimple = ValidatedColor()

//Validated color built from a java Color. This color will not allow transparency
val validatedColorColor = ValidatedColor(Color(1f, 0.5f, 0f), false)

//validated color built from a hex string, with transparency enabled.
val validatedColorString = "D6FF00AA".validatedColor(true)

//fields and sections have lang keys based on their "location" in the Config class graph.
//Lange key composition is as follows
//1. the namespace of the config id: (my_mod)
//2. the path of the config id: (my_mod.my_config)
//3. any parent ConfigSection field names as declared in-code: (my_mod.my_config.subSection)
//4. the setting field name as declared in-code: (my_mod.my_config.subSection.fieldName)
val fieldLang = """
{
    "_comment1": "the lang for an example 'fieldName' setting in a config inside section 'subSection'",
    "my_mod.my_config.subSection.fieldName": "Very Important Setting",
    "my_mod.my_config.subSection.fieldName.desc": "This very important setting is used in this very important way."
}
""" 
   //sampleEnd
}

constructor(transparent: Boolean = true)

A validated color value with or without transparency enabled and with default color 0xFFFFFFFF (opaque white)

Author

fzzyhmstrs

Since

0.2.0

Parameters

transparent

Boolean, whether this color supports transparency


constructor(color: Color, transparent: Boolean = true)

A validated color value built from a jwt Color with or without transparency enabled

Author

fzzyhmstrs

Since

0.2.0

Parameters

color

Color defining the RGBA of this validated color

transparent

Boolean, whether this color supports transparency