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
|
|
|
)
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// static check that Dt1 implements Component
|
|
|
|
var _ akara.Component = &Dt1{}
|
2020-10-12 17:35:11 -04:00
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// Dt1 is a component that contains an embedded DT1 struct
|
|
|
|
type Dt1 struct {
|
2020-10-12 17:35:11 -04:00
|
|
|
*d2dt1.DT1
|
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// New returns a Dt1 component. By default, it contains a nil instance.
|
|
|
|
func (*Dt1) New() akara.Component {
|
|
|
|
return &Dt1{}
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// Dt1Factory is a wrapper for the generic component factory that returns Dt1 component instances.
|
|
|
|
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a Dt1.
|
|
|
|
type Dt1Factory struct {
|
|
|
|
Dt1 *akara.ComponentFactory
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// AddDt1 adds a Dt1 component to the given entity and returns it
|
|
|
|
func (m *Dt1Factory) AddDt1(id akara.EID) *Dt1 {
|
|
|
|
return m.Dt1.Add(id).(*Dt1)
|
2020-11-22 16:02:42 -05:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// GetDt1 returns the Dt1 component for the given entity, and a bool for whether or not it exists
|
|
|
|
func (m *Dt1Factory) GetDt1(id akara.EID) (*Dt1, bool) {
|
|
|
|
component, found := m.Dt1.Get(id)
|
|
|
|
if !found {
|
|
|
|
return nil, found
|
2020-11-22 16:02:42 -05:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
return component.(*Dt1), found
|
2020-10-12 17:35:11 -04:00
|
|
|
}
|