mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-06 18:27:20 -05:00
30 lines
682 B
Go
30 lines
682 B
Go
|
package d2asset
|
||
|
|
||
|
type animationManager struct {
|
||
|
cache *cache
|
||
|
}
|
||
|
|
||
|
func createAnimationManager() *animationManager {
|
||
|
return &animationManager{cache: createCache(AnimationBudget)}
|
||
|
}
|
||
|
|
||
|
func (sm *animationManager) loadAnimation(animationPath, palettePath string) (*Animation, error) {
|
||
|
cachePath := animationPath + palettePath
|
||
|
if animation, found := sm.cache.retrieve(cachePath); found {
|
||
|
return animation.(*Animation).clone(), nil
|
||
|
}
|
||
|
|
||
|
dc6, err := loadDC6(animationPath, palettePath)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
animation, err := createAnimationFromDC6(dc6)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
sm.cache.insert(cachePath, animation.clone(), 1)
|
||
|
return animation, err
|
||
|
}
|