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