1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 16:27:18 -04:00
OpenDiablo2/Common/Palette.go
Tim Sarbin 01a48d8720
Added object support (#93)
* Fixed LevelTypes load
* Update ResourcePaths.go
* Added DCC loading support
* Added animation data. Fixed bitshift version compile issue.
* Fixed another go build error
* Initial support for object rendering
2019-11-06 18:25:19 -05:00

49 lines
1.2 KiB
Go

package Common
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/PaletteDefs"
)
// PaletteRGB represents a color in a palette
type PaletteRGB struct {
R, G, B uint8
}
// PaletteType represents a palette
type PaletteRec struct {
Name PaletteDefs.PaletteType
Colors [256]PaletteRGB
}
var Palettes map[PaletteDefs.PaletteType]PaletteRec
// CreatePalette creates a palette
func CreatePalette(name PaletteDefs.PaletteType, data []byte) PaletteRec {
result := PaletteRec{Name: name}
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
}
func LoadPalettes(mpqFiles map[string]string, fileProvider FileProvider) {
Palettes = make(map[PaletteDefs.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`
paletteName := PaletteDefs.PaletteType(pal)
palette := CreatePalette(paletteName, fileProvider.LoadFile(filePath))
Palettes[paletteName] = palette
}
log.Printf("Loaded %d palettes", len(Palettes))
}