1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-07 18:57:18 -05:00
OpenDiablo2/d2data/d2datadict/palette.go

51 lines
1.3 KiB
Go
Raw Normal View History

2019-11-10 08:51:02 -05:00
package d2datadict
2019-10-24 09:31:59 -04:00
import (
"log"
2019-11-10 03:36:53 -05:00
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
)
// PaletteRGB represents a color in a palette
2019-10-24 09:31:59 -04:00
type PaletteRGB struct {
R, G, B uint8
}
// PaletteType represents a palette
type PaletteRec struct {
2019-11-10 03:36:53 -05:00
Name d2enum.PaletteType
2019-10-24 09:31:59 -04:00
Colors [256]PaletteRGB
}
2019-11-10 03:36:53 -05:00
var Palettes map[d2enum.PaletteType]PaletteRec
2019-10-24 09:31:59 -04:00
// CreatePalette creates a palette
2019-11-10 03:36:53 -05:00
func CreatePalette(name d2enum.PaletteType, data []byte) PaletteRec {
result := PaletteRec{Name: name}
2019-10-24 09:31:59 -04:00
for i := 0; i <= 255; i++ {
result.Colors[i] = PaletteRGB{
B: data[i*3],
G: data[(i*3)+1],
R: data[(i*3)+2],
}
}
return result
}
2019-11-10 03:36:53 -05:00
func LoadPalettes(mpqFiles map[string]string, fileProvider d2interface.FileProvider) {
Palettes = make(map[d2enum.PaletteType]PaletteRec)
for _, pal := range []string{
"act1", "act2", "act3", "act4", "act5", "endgame", "endgame2", "fechar", "loading",
"menu0", "menu1", "menu2", "menu3", "menu4", "sky", "static", "trademark", "units",
} {
filePath := `data\global\palette\` + pal + `\pal.dat`
2019-11-10 03:36:53 -05:00
paletteName := d2enum.PaletteType(pal)
palette := CreatePalette(paletteName, fileProvider.LoadFile(filePath))
Palettes[paletteName] = palette
}
log.Printf("Loaded %d palettes", len(Palettes))
}