Palette
A Palette is an array of BlockProperties entries describing the visual properties of Shapes blocks. It can be shared by multiple shapes.
The entries of a palette can be changed at runtime with a few specific caveats:
- only colors that are unused by the shape(s) can be removed from the palette,
- changing a color from opaque to/from transparent will require a call to shape:RefreshModel() to be reflected on the existing shapes blocks (not necessary for newly added blocks),
- changing the [BlockProperties.Light] or [BlockProperties.Color]'s alpha values will only be reflected on the baked lighting after calling shape:ComputeBakedLight (as of 0.0.47, only relevant for Map)
Constructors
Creates an empty Palette.
Functions
Adds a new BlockProperties entry with the given color. Returns palette index at which it was added.
-- add red Color to the shape myShape.Palette:AddColor(Color(255, 0, 0))
Returns the palette index of the latest entry corresponding to given color, nil if not found.
-- get myShape's red Color index local idx = myShape.Palette:GetIndex(Color(255, 0, 0))
Combine the colors of the given palette into Palette. If a Shape is passed, it will use its Shape.Palette property.
The config table can contain any of the following properties,
- duplicates: keep duplicate colors when merging, false by default.
- remap: given shape will now use this palette, and shape's blocks indices are remapped to the new palette so that they keep their colors. Default is false. Only works if a Shape is passed as parameter.
- recurse: merge colors of the shape and all its children shapes, false by default. Only works if a Shape is passed as parameter.
-- merge the colors of palette2 into palette1 palette1:Merge(palette2) -- merge the colors of palette2 into palette1, keeping duplicates palette1:Merge(palette2, { duplicates=true }) -- merge into palette3 all the colors found in the shape and all its children palette3:Merge(rootShape, { recurse=true }) -- merge & assign a shared palette to given shape and all its children palette4:Merge(rootShape, { remap=true, recurse=true }) palette4[i].Color = Color.Red -- will affect all blocks using palette index 'i' in all these shapes
Removes the BlockProperties entry at given index, if it is unused. Returns true if it was removed.
-- remove red Color from the shape if not used local removed = myShape.Palette:RemoveColor(Color(255, 0, 0))
Properties
Maximum number of BlockProperties entries in a Palette. Imported shapes or shapes from previous versions may exceed this limit but no new entry can be added.