2020-06-28 22:32:34 -04:00
|
|
|
package d2dat
|
|
|
|
|
2020-07-05 10:01:44 -07:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-07-17 21:02:45 -07:00
|
|
|
|
2020-07-05 10:01:44 -07:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
numColors = 256
|
|
|
|
)
|
|
|
|
|
2020-06-28 22:32:34 -04:00
|
|
|
// DATPalette represents a 256 color palette.
|
|
|
|
type DATPalette struct {
|
2020-07-05 10:01:44 -07:00
|
|
|
colors [numColors]d2interface.Color
|
|
|
|
}
|
|
|
|
|
2021-03-28 17:24:12 +02:00
|
|
|
// New creates a new dat palette
|
2021-03-28 17:19:08 +02:00
|
|
|
func New() *DATPalette {
|
|
|
|
result := &DATPalette{}
|
|
|
|
for i := range result.colors {
|
|
|
|
result.colors[i] = &DATColor{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-07-05 10:01:44 -07:00
|
|
|
// 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-28 22:32:34 -04:00
|
|
|
}
|