mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-14 15:28:11 -04:00
019bb920c9
* adding pl2 as a fiel format and an asset manager for pl2 files * adding pl2 as a file format and an asset manager for pl2 files * pl2 asset manager and file format * added call in main.go to load palette transforms * removed incorrect PaletteTransformType declarations from main.go * removingn bad resource path for palette transform * PL2 file format added, added to asset management PL2 files are beside palette files in the mpq These files define palette transforms of their respective base palette. I've bound a command to d2term (in d2asset.go) load_pl2 <path> * Clean up PL2 asset stuff removed pl2 stuff from d2datadict, didn't belong in there removed d2term debug binding * minor cleanup for d2pl2
38 lines
770 B
Go
38 lines
770 B
Go
package d2asset
|
|
|
|
import (
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2"
|
|
)
|
|
|
|
type paletteTransformManager struct {
|
|
cache *d2common.Cache
|
|
}
|
|
|
|
const (
|
|
paletteTransformBudget = 64
|
|
)
|
|
|
|
func createPaletteTransformManager() *paletteTransformManager {
|
|
return &paletteTransformManager{d2common.CreateCache(paletteTransformBudget)}
|
|
}
|
|
|
|
func (pm *paletteTransformManager) loadPaletteTransform(path string) (*d2pl2.PL2File, error) {
|
|
if pl2, found := pm.cache.Retrieve(path); found {
|
|
return pl2.(*d2pl2.PL2File), nil
|
|
}
|
|
|
|
data, err := LoadFile(path);
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pl2, err := d2pl2.LoadPL2(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pm.cache.Insert(path, pl2, 1)
|
|
return pl2, nil
|
|
}
|