2020-10-10 22:49:17 -04:00
|
|
|
package d2systems
|
|
|
|
|
|
|
|
import (
|
2020-10-12 17:35:11 -04:00
|
|
|
"io"
|
2020-10-10 22:49:17 -04:00
|
|
|
|
2020-11-22 04:37:55 -05:00
|
|
|
"github.com/gravestench/akara"
|
2020-10-13 04:19:38 -04:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2cache"
|
2020-11-22 04:37:55 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-10-12 17:35:11 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2animdata"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2tbl"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
2020-11-22 04:37:55 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-10-10 22:49:17 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2components"
|
|
|
|
)
|
|
|
|
|
2020-10-13 04:19:38 -04:00
|
|
|
const (
|
|
|
|
assetCacheBudget = 1024
|
|
|
|
assetCacheEntryWeight = 1 // may want to make different weights for different asset types
|
|
|
|
)
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
const (
|
2020-11-22 04:37:55 -05:00
|
|
|
logPrefixAssetLoader = "Asset Loader System"
|
2020-11-14 12:52:07 -05:00
|
|
|
)
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
// NewAssetLoader creates a new asset loader instance
|
2020-10-10 22:49:17 -04:00
|
|
|
func NewAssetLoader() *AssetLoaderSystem {
|
2020-10-12 17:35:11 -04:00
|
|
|
// we are going to check entities that dont yet have loaded asset types
|
|
|
|
filesToLoad := akara.NewFilter().
|
2020-11-14 12:52:07 -05:00
|
|
|
Require(d2components.FilePath). // we want to process entities with these file components
|
2020-10-12 17:35:11 -04:00
|
|
|
Require(d2components.FileType).
|
|
|
|
Require(d2components.FileHandle).
|
2020-11-14 12:52:07 -05:00
|
|
|
Forbid(d2components.FileSource). // but we forbid files that are already loaded
|
2020-10-12 17:35:11 -04:00
|
|
|
Forbid(d2components.GameConfig).
|
|
|
|
Forbid(d2components.StringTable).
|
|
|
|
Forbid(d2components.DataDictionary).
|
|
|
|
Forbid(d2components.Palette).
|
|
|
|
Forbid(d2components.PaletteTransform).
|
|
|
|
Forbid(d2components.Cof).
|
|
|
|
Forbid(d2components.Dc6).
|
|
|
|
Forbid(d2components.Dcc).
|
|
|
|
Forbid(d2components.Ds1).
|
|
|
|
Forbid(d2components.Dt1).
|
|
|
|
Forbid(d2components.Wav).
|
|
|
|
Forbid(d2components.AnimData).
|
2020-10-10 22:49:17 -04:00
|
|
|
Build()
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
fileSources := akara.NewFilter().
|
2020-10-10 22:49:17 -04:00
|
|
|
Require(d2components.FileSource).
|
|
|
|
Build()
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
assetLoader := &AssetLoaderSystem{
|
2020-11-19 17:17:01 -05:00
|
|
|
BaseSubscriberSystem: akara.NewBaseSubscriberSystem(filesToLoad, fileSources),
|
2020-11-22 04:37:55 -05:00
|
|
|
cache: d2cache.CreateCache(assetCacheBudget).(*d2cache.Cache),
|
|
|
|
Logger: d2util.NewLogger(),
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
2020-11-14 12:52:07 -05:00
|
|
|
|
2020-11-22 04:37:55 -05:00
|
|
|
assetLoader.SetPrefix(logPrefixAssetLoader)
|
2020-11-14 12:52:07 -05:00
|
|
|
|
|
|
|
return assetLoader
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
var _ akara.System = &AssetLoaderSystem{}
|
2020-10-10 22:49:17 -04:00
|
|
|
|
2020-11-22 04:37:55 -05:00
|
|
|
// AssetLoaderSystem is responsible for parsing data from file handles into various structs, like COF or DC6
|
2020-10-10 22:49:17 -04:00
|
|
|
type AssetLoaderSystem struct {
|
2020-11-19 17:17:01 -05:00
|
|
|
*akara.BaseSubscriberSystem
|
2020-11-14 12:52:07 -05:00
|
|
|
*d2util.Logger
|
2020-11-22 04:37:55 -05:00
|
|
|
fileSub *akara.Subscription
|
|
|
|
sourceSub *akara.Subscription
|
|
|
|
cache *d2cache.Cache
|
2020-11-18 21:33:22 -05:00
|
|
|
*d2components.FilePathMap
|
|
|
|
*d2components.FileTypeMap
|
|
|
|
*d2components.FileHandleMap
|
|
|
|
*d2components.FileSourceMap
|
|
|
|
*d2components.StringTableMap
|
|
|
|
*d2components.FontTableMap
|
|
|
|
*d2components.DataDictionaryMap
|
|
|
|
*d2components.PaletteMap
|
|
|
|
*d2components.PaletteTransformMap
|
|
|
|
*d2components.CofMap
|
|
|
|
*d2components.Dc6Map
|
|
|
|
*d2components.DccMap
|
|
|
|
*d2components.Ds1Map
|
|
|
|
*d2components.Dt1Map
|
|
|
|
*d2components.WavMap
|
|
|
|
*d2components.AnimDataMap
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
// Init injects component maps related to various asset types
|
2020-11-22 04:37:55 -05:00
|
|
|
func (m *AssetLoaderSystem) Init(_ *akara.World) {
|
2020-11-14 12:52:07 -05:00
|
|
|
m.Info("initializing ...")
|
|
|
|
|
2020-10-10 22:49:17 -04:00
|
|
|
m.fileSub = m.Subscriptions[0]
|
|
|
|
m.sourceSub = m.Subscriptions[1]
|
|
|
|
|
|
|
|
// try to inject the components we require, then cast the returned
|
|
|
|
// abstract ComponentMap back to the concrete implementation
|
2020-11-18 21:33:22 -05:00
|
|
|
m.FilePathMap = m.InjectMap(d2components.FilePath).(*d2components.FilePathMap)
|
|
|
|
m.FileTypeMap = m.InjectMap(d2components.FileType).(*d2components.FileTypeMap)
|
|
|
|
m.FileHandleMap = m.InjectMap(d2components.FileHandle).(*d2components.FileHandleMap)
|
|
|
|
m.FileSourceMap = m.InjectMap(d2components.FileSource).(*d2components.FileSourceMap)
|
|
|
|
m.StringTableMap = m.InjectMap(d2components.StringTable).(*d2components.StringTableMap)
|
|
|
|
m.DataDictionaryMap = m.InjectMap(d2components.DataDictionary).(*d2components.DataDictionaryMap)
|
|
|
|
m.PaletteMap = m.InjectMap(d2components.Palette).(*d2components.PaletteMap)
|
|
|
|
m.PaletteTransformMap = m.InjectMap(d2components.PaletteTransform).(*d2components.PaletteTransformMap)
|
|
|
|
m.FontTableMap = m.InjectMap(d2components.FontTable).(*d2components.FontTableMap)
|
|
|
|
m.CofMap = m.InjectMap(d2components.Cof).(*d2components.CofMap)
|
|
|
|
m.Dc6Map = m.InjectMap(d2components.Dc6).(*d2components.Dc6Map)
|
|
|
|
m.DccMap = m.InjectMap(d2components.Dcc).(*d2components.DccMap)
|
|
|
|
m.Ds1Map = m.InjectMap(d2components.Ds1).(*d2components.Ds1Map)
|
|
|
|
m.Dt1Map = m.InjectMap(d2components.Dt1).(*d2components.Dt1Map)
|
|
|
|
m.WavMap = m.InjectMap(d2components.Wav).(*d2components.WavMap)
|
|
|
|
m.AnimDataMap = m.InjectMap(d2components.AnimData).(*d2components.AnimDataMap)
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
// Update processes all of the Entities in the subscription of file entities that need to be processed
|
|
|
|
func (m *AssetLoaderSystem) Update() {
|
2020-10-10 22:49:17 -04:00
|
|
|
for _, eid := range m.fileSub.GetEntities() {
|
2020-10-12 17:35:11 -04:00
|
|
|
m.loadAsset(eid)
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
func (m *AssetLoaderSystem) loadAsset(id akara.EID) {
|
2020-11-14 12:52:07 -05:00
|
|
|
// make sure everything is kosher
|
2020-11-18 21:33:22 -05:00
|
|
|
fp, found := m.GetFilePath(id)
|
2020-10-13 04:19:38 -04:00
|
|
|
if !found {
|
2020-11-14 12:52:07 -05:00
|
|
|
m.Errorf("filepath component not found for entity %d", id)
|
2020-10-13 04:19:38 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
ft, found := m.GetFileType(id)
|
2020-10-10 22:49:17 -04:00
|
|
|
if !found {
|
2020-11-14 12:52:07 -05:00
|
|
|
m.Errorf("filetype component not found for entity %d", id)
|
2020-10-10 22:49:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
fh, found := m.GetFileHandle(id)
|
2020-10-10 22:49:17 -04:00
|
|
|
if !found {
|
2020-11-14 12:52:07 -05:00
|
|
|
m.Errorf("filehandle component not found for entity %d", id)
|
2020-10-10 22:49:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
// try to pull from the cache and assign to the given entity id
|
|
|
|
if found := m.assignFromCache(id, fp.Path, ft.Type); found {
|
|
|
|
m.Debugf("Retrieving %s from cache", fp.Path)
|
2020-10-13 04:19:38 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
// make sure to seek back to 0 if the filehandle was cached
|
2020-10-13 04:19:38 -04:00
|
|
|
_, _ = fh.Data.Seek(0, 0)
|
|
|
|
|
2020-10-10 22:49:17 -04:00
|
|
|
data, buf := make([]byte, 0), make([]byte, 16)
|
2020-10-12 17:35:11 -04:00
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
// read, parse, and cache the data
|
2020-10-10 22:49:17 -04:00
|
|
|
for {
|
|
|
|
numRead, err := fh.Data.Read(buf)
|
|
|
|
data = append(data, buf[:numRead]...)
|
2020-10-12 17:35:11 -04:00
|
|
|
|
2020-10-10 22:49:17 -04:00
|
|
|
if numRead < 1 || err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 18:49:49 -04:00
|
|
|
m.parseAndCache(id, fp.Path, ft.Type, data)
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
func (m *AssetLoaderSystem) assignFromCache(id akara.EID, path string, t d2enum.FileType) bool {
|
2020-10-13 04:19:38 -04:00
|
|
|
entry, found := m.cache.Retrieve(path)
|
|
|
|
if !found {
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
// if we found what we're looking for, create the appropriate component and assign what we retrieved
|
2020-10-13 04:19:38 -04:00
|
|
|
switch t {
|
|
|
|
case d2enum.FileTypeStringTable:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddStringTable(id).TextDictionary = entry.(*d2tbl.TextDictionary)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeFontTable:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddFontTable(id).Data = entry.([]byte)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeDataDictionary:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDataDictionary(id).DataDictionary = entry.(*d2txt.DataDictionary)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypePalette:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddPalette(id).Palette = entry.(d2interface.Palette)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypePaletteTransform:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddPaletteTransform(id).Transform = entry.(*d2pl2.PL2)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeCOF:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddCof(id).COF = entry.(*d2cof.COF)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeDC6:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDc6(id).DC6 = entry.(*d2dc6.DC6)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeDCC:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDcc(id).DCC = entry.(*d2dcc.DCC)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeDS1:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDs1(id).DS1 = entry.(*d2ds1.DS1)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeDT1:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDt1(id).DT1 = entry.(*d2dt1.DT1)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeWAV:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddWav(id).Data = entry.(d2interface.DataStream)
|
2020-10-13 04:19:38 -04:00
|
|
|
case d2enum.FileTypeD2:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddAnimData(id).AnimationData = entry.(*d2animdata.AnimationData)
|
2020-10-13 04:19:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
2020-11-22 04:37:55 -05:00
|
|
|
//nolint:gocyclo // this big switch statement is unfortunate, but necessary
|
2020-10-28 18:49:49 -04:00
|
|
|
func (m *AssetLoaderSystem) parseAndCache(id akara.EID, path string, t d2enum.FileType, data []byte) {
|
|
|
|
go func() {
|
|
|
|
switch t {
|
|
|
|
case d2enum.FileTypeStringTable:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading string table: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
m.loadStringTable(id, path, data)
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeFontTable:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading font table: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
m.loadFontTable(id, path, data)
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeDataDictionary:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading data dictionary: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
m.loadDataDictionary(id, path, data)
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypePalette:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading palette: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadPalette(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypePaletteTransform:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading palette transform: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadPaletteTransform(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeCOF:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading COF: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadCOF(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeDC6:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading DC6: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadDC6(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeDCC:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading DCC: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadDCC(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeDS1:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading DS1: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadDS1(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeDT1:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading DT1: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadDT1(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeWAV:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading WAV: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
fh, found := m.GetFileHandle(id)
|
2020-10-28 18:49:49 -04:00
|
|
|
if !found {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
m.loadWAV(id, path, fh.Data)
|
2020-10-28 18:49:49 -04:00
|
|
|
case d2enum.FileTypeD2:
|
2020-11-18 21:33:22 -05:00
|
|
|
m.Infof("Loading animation data: %s", path)
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if err := m.loadAnimData(id, path, data); err != nil {
|
|
|
|
m.Error(err.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
2020-10-28 18:49:49 -04:00
|
|
|
}()
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadStringTable(id akara.EID, path string, data []byte) {
|
2020-10-12 17:35:11 -04:00
|
|
|
txt := d2tbl.LoadTextDictionary(data)
|
2020-10-13 04:19:38 -04:00
|
|
|
loaded := &txt
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddStringTable(id).TextDictionary = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-13 04:19:38 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadFontTable(id akara.EID, path string, data []byte) {
|
|
|
|
m.AddFontTable(id).Data = data
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, data, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadDataDictionary(id akara.EID, path string, data []byte) {
|
2020-10-13 04:19:38 -04:00
|
|
|
loaded := d2txt.LoadDataDictionary(data)
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDataDictionary(id).DataDictionary = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadPalette(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2dat.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddPalette(id).Palette = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadPaletteTransform(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2pl2.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddPaletteTransform(id).Transform = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
|
|
|
|
return err
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadCOF(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2cof.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddCof(id).COF = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadDC6(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2dc6.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDc6(id).DC6 = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadDCC(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2dcc.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDcc(id).DCC = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadDS1(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2ds1.LoadDS1(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDs1(id).DS1 = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadDT1(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2dt1.LoadDT1(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddDt1(id).DT1 = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadWAV(id akara.EID, path string, seeker io.ReadSeeker) {
|
|
|
|
component := m.AddWav(id)
|
2020-10-12 17:35:11 -04:00
|
|
|
component.Data = seeker
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, seeker, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (m *AssetLoaderSystem) loadAnimData(id akara.EID, path string, data []byte) error {
|
2020-10-12 17:35:11 -04:00
|
|
|
loaded, err := d2animdata.Load(data)
|
|
|
|
if err == nil {
|
2020-11-18 21:33:22 -05:00
|
|
|
m.AddAnimData(id).AnimationData = loaded
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
if cacheErr := m.cache.Insert(path, loaded, assetCacheEntryWeight); cacheErr != nil {
|
|
|
|
m.Error(cacheErr.Error())
|
|
|
|
}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|