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
|
|
|
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-28 00:45:58 -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-28 00:45:58 -05:00
|
|
|
d2components.FilePathFactory
|
|
|
|
d2components.FileTypeFactory
|
|
|
|
d2components.FileHandleFactory
|
|
|
|
d2components.FileSourceFactory
|
|
|
|
d2components.StringTableFactory
|
|
|
|
d2components.FontTableFactory
|
|
|
|
d2components.DataDictionaryFactory
|
|
|
|
d2components.PaletteFactory
|
|
|
|
d2components.PaletteTransformFactory
|
|
|
|
d2components.CofFactory
|
|
|
|
d2components.Dc6Factory
|
|
|
|
d2components.DccFactory
|
|
|
|
d2components.Ds1Factory
|
|
|
|
d2components.Dt1Factory
|
|
|
|
d2components.WavFactory
|
|
|
|
d2components.AnimationDataFactory
|
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-28 00:45:58 -05:00
|
|
|
func (m *AssetLoaderSystem) Init(world *akara.World) {
|
|
|
|
m.World = world
|
|
|
|
|
|
|
|
m.setupLogger()
|
|
|
|
|
2020-11-14 12:52:07 -05:00
|
|
|
m.Info("initializing ...")
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
m.setupSubscriptions()
|
|
|
|
m.setupFactories()
|
|
|
|
|
|
|
|
m.cache = d2cache.CreateCache(assetCacheBudget).(*d2cache.Cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *AssetLoaderSystem) setupLogger() {
|
|
|
|
m.Logger = d2util.NewLogger()
|
|
|
|
m.SetPrefix(logPrefixAssetLoader)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *AssetLoaderSystem) setupSubscriptions() {
|
|
|
|
m.Info("setting up component subscriptions")
|
|
|
|
|
|
|
|
// we are going to check entities that dont yet have loaded asset types
|
|
|
|
filesToLoad := m.NewComponentFilter().
|
|
|
|
Require(
|
|
|
|
&d2components.FilePath{}, // we want to process entities with these file components
|
|
|
|
&d2components.FileType{},
|
|
|
|
&d2components.FileHandle{},
|
|
|
|
).
|
|
|
|
Forbid(
|
|
|
|
&d2components.FileSource{}, // but we forbid files that are already loaded
|
|
|
|
&d2components.GameConfig{},
|
|
|
|
&d2components.StringTable{},
|
|
|
|
&d2components.DataDictionary{},
|
|
|
|
&d2components.Palette{},
|
|
|
|
&d2components.PaletteTransform{},
|
|
|
|
&d2components.Cof{},
|
|
|
|
&d2components.Dc6{},
|
|
|
|
&d2components.Dcc{},
|
|
|
|
&d2components.Ds1{},
|
|
|
|
&d2components.Dt1{},
|
|
|
|
&d2components.Wav{},
|
|
|
|
&d2components.AnimationData{},
|
|
|
|
).
|
|
|
|
Build()
|
|
|
|
|
|
|
|
fileSources := m.NewComponentFilter().
|
|
|
|
Require(&d2components.FileSource{}).
|
|
|
|
Build()
|
|
|
|
|
|
|
|
m.fileSub = m.AddSubscription(filesToLoad)
|
|
|
|
m.sourceSub = m.AddSubscription(fileSources)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *AssetLoaderSystem) setupFactories() {
|
|
|
|
m.Info("setting up component factories")
|
|
|
|
|
|
|
|
filePathID := m.RegisterComponent(&d2components.FilePath{})
|
|
|
|
fileTypeID := m.RegisterComponent(&d2components.FileType{})
|
|
|
|
fileHandleID := m.RegisterComponent(&d2components.FileHandle{})
|
|
|
|
fileSourceID := m.RegisterComponent(&d2components.FileSource{})
|
|
|
|
stringTableID := m.RegisterComponent(&d2components.StringTable{})
|
|
|
|
fontTableID := m.RegisterComponent(&d2components.FontTable{})
|
|
|
|
dataDictionaryID := m.RegisterComponent(&d2components.DataDictionary{})
|
|
|
|
paletteID := m.RegisterComponent(&d2components.Palette{})
|
|
|
|
paletteTransformID := m.RegisterComponent(&d2components.PaletteTransform{})
|
|
|
|
cofID := m.RegisterComponent(&d2components.Cof{})
|
|
|
|
dc6ID := m.RegisterComponent(&d2components.Dc6{})
|
|
|
|
dccID := m.RegisterComponent(&d2components.Dcc{})
|
|
|
|
ds1ID := m.RegisterComponent(&d2components.Ds1{})
|
|
|
|
dt1ID := m.RegisterComponent(&d2components.Dt1{})
|
|
|
|
wavID := m.RegisterComponent(&d2components.Wav{})
|
|
|
|
animationDataID := m.RegisterComponent(&d2components.AnimationData{})
|
|
|
|
|
|
|
|
m.FilePath = m.GetComponentFactory(filePathID)
|
|
|
|
m.FileType = m.GetComponentFactory(fileTypeID)
|
|
|
|
m.FileHandle = m.GetComponentFactory(fileHandleID)
|
|
|
|
m.FileSource = m.GetComponentFactory(fileSourceID)
|
|
|
|
m.StringTable = m.GetComponentFactory(stringTableID)
|
|
|
|
m.DataDictionary = m.GetComponentFactory(dataDictionaryID)
|
|
|
|
m.Palette = m.GetComponentFactory(paletteID)
|
|
|
|
m.PaletteTransform = m.GetComponentFactory(paletteTransformID)
|
|
|
|
m.FontTable = m.GetComponentFactory(fontTableID)
|
|
|
|
m.Cof = m.GetComponentFactory(cofID)
|
|
|
|
m.Dc6 = m.GetComponentFactory(dc6ID)
|
|
|
|
m.Dcc = m.GetComponentFactory(dccID)
|
|
|
|
m.Ds1 = m.GetComponentFactory(ds1ID)
|
|
|
|
m.Dt1 = m.GetComponentFactory(dt1ID)
|
|
|
|
m.Wav = m.GetComponentFactory(wavID)
|
|
|
|
m.AnimationData = m.GetComponentFactory(animationDataID)
|
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-28 00:45:58 -05:00
|
|
|
m.AddPaletteTransform(id).PL2 = 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-28 00:45:58 -05:00
|
|
|
m.AddAnimationData(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
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
if err := m.loadAnimationData(id, path, data); err != nil {
|
2020-11-22 04:37:55 -05:00
|
|
|
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-28 00:45:58 -05:00
|
|
|
m.AddPaletteTransform(id).PL2 = 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-28 00:45:58 -05:00
|
|
|
func (m *AssetLoaderSystem) loadAnimationData(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-28 00:45:58 -05:00
|
|
|
m.AddAnimationData(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
|
|
|
|
}
|