1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-16 04:25:23 +00:00
OpenDiablo2/d2common/d2fileformats/d2dat/dat_palette.go

46 lines
910 B
Go
Raw Permalink Normal View History

2020-06-29 02:32:34 +00:00
package d2dat
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
const (
numColors = 256
)
2020-06-29 02:32:34 +00:00
// DATPalette represents a 256 color palette.
type DATPalette struct {
colors [numColors]d2interface.Color
}
2021-03-28 15:24:12 +00:00
// New creates a new dat palette
2021-03-28 15:19:08 +00:00
func New() *DATPalette {
result := &DATPalette{}
for i := range result.colors {
result.colors[i] = &DATColor{}
}
return result
}
// NumColors returns the number of colors in the palette
func (p *DATPalette) NumColors() int {
return len(p.colors)
}
// GetColors returns the slice of colors in the palette
func (p *DATPalette) GetColors() [numColors]d2interface.Color {
return p.colors
}
// GetColor returns a color by index
func (p *DATPalette) GetColor(idx int) (d2interface.Color, error) {
if color := p.colors[idx]; color != nil {
return color, nil
}
return nil, fmt.Errorf("cannot find color index '%d in palette'", idx)
2020-06-29 02:32:34 +00:00
}