1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-13 12:06:31 -05:00
OpenDiablo2/d2core/d2components/asset_cof.go

63 lines
1.6 KiB
Go
Raw Normal View History

//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
2020-10-12 17:35:11 -04:00
package d2components
import (
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
2020-10-12 17:35:11 -04:00
)
// static check that CofComponent implements Component
var _ akara.Component = &CofComponent{}
// static check that CofMap implements ComponentMap
var _ akara.ComponentMap = &CofMap{}
// CofComponent is a component that contains an embedded cof struct
type CofComponent struct {
*akara.BaseComponent
2020-10-12 17:35:11 -04:00
*d2cof.COF
}
// CofMap is a map of entity ID's to Cof
type CofMap struct {
*akara.BaseComponentMap
2020-10-12 17:35:11 -04:00
}
// AddCof adds a new CofComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *CofComponent instead of an akara.Component
func (cm *CofMap) AddCof(id akara.EID) *CofComponent {
return cm.Add(id).(*CofComponent)
}
// GetCof returns the CofComponent associated with the given entity id
func (cm *CofMap) GetCof(id akara.EID) (*CofComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*CofComponent), found
2020-10-12 17:35:11 -04:00
}
// Cof is a convenient reference to be used as a component identifier
var Cof = newCof() // nolint:gochecknoglobals // global by design
func newCof() akara.Component {
return &CofComponent{
BaseComponent: akara.NewBaseComponent(AssetCofCID, newCof, newCofMap),
}
}
func newCofMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetCofCID, newCof, newCofMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &CofMap{
BaseComponentMap: baseMap,
}
return cm
2020-10-12 17:35:11 -04:00
}