I have 2x structs, one for color (PixelColor) and the second for holding an array of available colors (Palette).
typedef struct{
int r;
int g;
int b;
int a;
}PixelColor;
typedef struct{
int size;
PixelColor *palette;
}Palette;
One game's global palette and one for objects that reference colors in the global palette.
PixelColor ShovelKnightColors[] = {
{0, 0, 0, 255},
{44, 44, 44, 255},
{96, 96, 96, 255},
{200, 192, 192, 255},
{0, 64, 88, 255},
...
};
Palette GamePalette = {59, ShovelKnightColors};
PixelColor CharacterColors[4];
//This doesn't work
CharacterColors[0] = GamePalette.palette[0];
CharacterColors[1] = GamePalette.palette[17];
CharacterColors[2] = GamePalette.palette[24];
CharacterColors[3] = GamePalette.palette[37];
Palette CharacterPalette = {4, CharactersColors};
I'm probably missing a fundamental thing, but I tried any idea I had. As an example:
PixelColor CharacterColors[] = {
GamePalette.palette[0],
GamePalette.palette[17],
GamePalette.palette[24],
GamePalette.palette[37]
}
All this is outside the main function, just to learn things I don't know about initiation. Please suggest a way to get closest to the initial idea of referencing the same values, because the goal is to create an ESP32 microcontroller project.
PixelColor CharacterColors[4] = {GamePalette.palette[0], GamePalette.palette[17], GamePalette.palette[24], GamePalette.palette[37]};(notice the 4 which is missing from your example)