2020-11-22 16:02:42 -05:00
|
|
|
//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"
|
2020-11-22 16:02:42 -05:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
|
2020-10-12 17:35:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// static check that Dc6Component implements Component
|
|
|
|
var _ akara.Component = &Dc6Component{}
|
|
|
|
|
|
|
|
// static check that Dc6Map implements ComponentMap
|
|
|
|
var _ akara.ComponentMap = &Dc6Map{}
|
|
|
|
|
2020-11-22 16:02:42 -05:00
|
|
|
// Dc6Component is a component that contains an embedded DC6 struct
|
2020-10-12 17:35:11 -04:00
|
|
|
type Dc6Component struct {
|
2020-11-22 16:02:42 -05:00
|
|
|
*akara.BaseComponent
|
2020-10-12 17:35:11 -04:00
|
|
|
*d2dc6.DC6
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dc6Map is a map of entity ID's to Dc6
|
|
|
|
type Dc6Map struct {
|
2020-11-22 16:02:42 -05:00
|
|
|
*akara.BaseComponentMap
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddDc6 adds a new Dc6Component for the given entity id and returns it.
|
|
|
|
// this is a convenience method for the generic Add method, as it returns a
|
|
|
|
// *Dc6Component instead of an akara.Component
|
|
|
|
func (cm *Dc6Map) AddDc6(id akara.EID) *Dc6Component {
|
|
|
|
return cm.Add(id).(*Dc6Component)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDc6 returns the Dc6Component associated with the given entity id
|
|
|
|
func (cm *Dc6Map) GetDc6(id akara.EID) (*Dc6Component, bool) {
|
2020-11-22 16:02:42 -05:00
|
|
|
entry, found := cm.Get(id)
|
|
|
|
if entry == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry.(*Dc6Component), found
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-22 16:02:42 -05:00
|
|
|
// Dc6 is a convenient reference to be used as a component identifier
|
|
|
|
var Dc6 = newDc6() // nolint:gochecknoglobals // global by design
|
|
|
|
|
|
|
|
func newDc6() akara.Component {
|
|
|
|
return &Dc6Component{
|
|
|
|
BaseComponent: akara.NewBaseComponent(AssetDc6CID, newDc6, newDc6Map),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDc6Map() akara.ComponentMap {
|
|
|
|
baseComponent := akara.NewBaseComponent(AssetDc6CID, newDc6, newDc6Map)
|
|
|
|
baseMap := akara.NewBaseComponentMap(baseComponent)
|
|
|
|
|
|
|
|
cm := &Dc6Map{
|
|
|
|
BaseComponentMap: baseMap,
|
|
|
|
}
|
|
|
|
|
|
|
|
return cm
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|