Sprites.Media.Sprite.Palette
The sprite editor's colour palette: the Palette window, the colour picker and palette picker modals, and the slot helpers. The helpers here derive the swatch grid's rebuild keys from a slot list and locate a slot's colour within a fixed palette, so the palette follows the editor's slots and brush.
Sprites.Media.Sprite.PaletteKeys Sprites.Reactive.Value
Sprites.Media.Sprite.PaletteKeys(slots)
The swatch grid's rebuild keys: the number of colours, boxed as a one item array. Sprites.Colour.Palette reads its length once, so the grid rebuilds when the count changes and updates in place when a colour changes. A composite over Sprites.Array.Length and Sprites.Array.Fill.
| Input | Type | Description |
|---|---|---|
slots | Array or Sprites.Reactive.Value | The list of slot colours whose count drives the grid. |
Returns a read-only Sprites.Reactive.Value holding a one item array whose single element is the colour count.
const slots = Sprites.Reactive.Value([1, 2, 3, 4]);
const keys = Sprites.Media.Sprite.PaletteKeys(slots);
const count = Sprites.Array.At(keys, 0);
const size = Sprites.Array.SizeBinding(slots, 0);
Sprites.Ui.Input.Number(size);
Sprites.Ui.Dom.Text(' keys hold count = ', count);
Sprites.Media.Sprite.SlotPalettePos Sprites.Reactive.Value
Sprites.Media.Sprite.SlotPalettePos(slots, brush, palette)
The selected slot's colour position in a fixed palette. It reads the colour at the brush slot, then finds that colour's index in the palette. A composite over Sprites.Array.At and Sprites.Array.IndexOf.
| Input | Type | Description |
|---|---|---|
slots | Array or Sprites.Reactive.Value | The list of slot colours. |
brush | Number or Sprites.Reactive.Value | The selected slot index. |
palette | Array or Sprites.Reactive.Value | The fixed palette of packed colours. |
Returns a read-only Sprites.Reactive.Value holding the position of the slot's colour within the palette.
const slots = Sprites.Reactive.Value([30, 10, 20]);
const palette = Sprites.Reactive.Value([10, 20, 30, 40]);
const brush = Sprites.Reactive.Value(0);
const pos = Sprites.Media.Sprite.SlotPalettePos(slots, brush, palette);
Sprites.Ui.Input.Number(brush);
Sprites.Ui.Dom.Text(' palette position = ', pos);