1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-10 18:47:23 -05:00
OpenDiablo2/d2core/d2components/asset_ds1.go
gravestench 3f5d2c0938 major refactor of akara ecs
* component ID's are dynamically allocated now
* removed `akara.BaseComponent` member from components
* component declarations drastically reduced
2020-12-07 12:44:11 -08:00

43 lines
1.2 KiB
Go

//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
)
// static check that Ds1 implements Component
var _ akara.Component = &Ds1{}
// Ds1 is a component that contains an embedded DS1 struct
type Ds1 struct {
*d2ds1.DS1
}
// New returns a Ds1 component. By default, it contains a nil instance.
func (*Ds1) New() akara.Component {
return &Ds1{}
}
// Ds1Factory is a wrapper for the generic component factory that returns Ds1 component instances.
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a Ds1.
type Ds1Factory struct {
Ds1 *akara.ComponentFactory
}
// AddDs1 adds a Ds1 component to the given entity and returns it
func (m *Ds1Factory) AddDs1(id akara.EID) *Ds1 {
return m.Ds1.Add(id).(*Ds1)
}
// GetDs1 returns the Ds1 component for the given entity, and a bool for whether or not it exists
func (m *Ds1Factory) GetDs1(id akara.EID) (*Ds1, bool) {
component, found := m.Ds1.Get(id)
if !found {
return nil, found
}
return component.(*Ds1), found
}