1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-04 07:37:48 -05:00
OpenDiablo2/d2core/d2components/asset_dcc.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/d2dcc"
2020-10-12 17:35:11 -04:00
)
// static check that DccComponent implements Component
var _ akara.Component = &DccComponent{}
// static check that DccMap implements ComponentMap
var _ akara.ComponentMap = &DccMap{}
// DccComponent is a component that contains an embedded DCC struct
2020-10-12 17:35:11 -04:00
type DccComponent struct {
*akara.BaseComponent
2020-10-12 17:35:11 -04:00
*d2dcc.DCC
}
// DccMap is a map of entity ID's to Dcc
type DccMap struct {
*akara.BaseComponentMap
2020-10-12 17:35:11 -04:00
}
// AddDcc adds a new DccComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *DccComponent instead of an akara.Component
func (cm *DccMap) AddDcc(id akara.EID) *DccComponent {
return cm.Add(id).(*DccComponent)
}
// GetDcc returns the DccComponent associated with the given entity id
func (cm *DccMap) GetDcc(id akara.EID) (*DccComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*DccComponent), found
2020-10-12 17:35:11 -04:00
}
// Dcc is a convenient reference to be used as a component identifier
var Dcc = newDcc() // nolint:gochecknoglobals // global by design
func newDcc() akara.Component {
return &DccComponent{
BaseComponent: akara.NewBaseComponent(AssetDccCID, newDcc, newDccMap),
}
}
func newDccMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDccCID, newDcc, newDccMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &DccMap{
BaseComponentMap: baseMap,
}
return cm
2020-10-12 17:35:11 -04:00
}