ConvertColor

ceramic.ConvertColor (Class)
Implements: ConvertField

Converter for Color fields in fragments and data serialization.

This converter handles Color values by supporting both string representations (like "#FF0000" or "red") and numeric values (0xFFRRGGBB). The conversion behavior can be controlled via the preferStringBasic property.

Instance Members

preferStringBasic: Bool

When true, colors are serialized as web strings (e.g., "#FF0000"). When false, colors are serialized as numeric values (default).


basicToField(instance: Entity, field: String, assets: Assets, basic: Any, done: Function): Void

Convert a basic value (string or number) to a Color instance.

Supports multiple input formats:

  • String: Web color strings like "#FF0000", "rgb(255,0,0)", or named colors like "red"
  • Number: Integer color values in 0xRRGGBB format
  • null: Returns Color.BLACK as default
Name Type Description
instance Entity The entity that owns this field
field String The name of the field being converted
assets Assets Assets instance for resource loading (unused for colors)
basic Any The source value to convert (string or number)
done Function Callback invoked with the converted Color instance

fieldToBasic(instance: Entity, field: String, value: Color): Any

Convert a Color instance to a basic value for serialization.

The output format depends on the preferStringBasic property:

  • If true: Returns a web color string like "#FF0000"
  • If false: Returns the numeric color value
Name Type Description
instance Entity The entity that owns this field
field String The name of the field being converted
value Color The Color instance to convert
Returns Description
Any Either a web color string or numeric value

new(): Void

Create a new color converter instance.