mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-10 10:36:42 -05:00
* component ID's are dynamically allocated now * removed `akara.BaseComponent` member from components * component declarations drastically reduced
43 lines
1.3 KiB
Go
43 lines
1.3 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/d2interface"
|
|
)
|
|
|
|
// static check that Palette implements Component
|
|
var _ akara.Component = &Palette{}
|
|
|
|
// Palette is a component that contains an embedded palette interface
|
|
type Palette struct {
|
|
d2interface.Palette
|
|
}
|
|
|
|
// New returns a new Palette component. By default, it contains a nil instance.
|
|
func (*Palette) New() akara.Component {
|
|
return &Palette{}
|
|
}
|
|
|
|
// PaletteFactory is a wrapper for the generic component factory that returns Palette component instances.
|
|
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a Palette.
|
|
type PaletteFactory struct {
|
|
Palette *akara.ComponentFactory
|
|
}
|
|
|
|
// AddPalette adds a Palette component to the given entity and returns it
|
|
func (m *PaletteFactory) AddPalette(id akara.EID) *Palette {
|
|
return m.Palette.Add(id).(*Palette)
|
|
}
|
|
|
|
// GetPalette returns the Palette component for the given entity, and a bool for whether or not it exists
|
|
func (m *PaletteFactory) GetPalette(id akara.EID) (*Palette, bool) {
|
|
component, found := m.Palette.Get(id)
|
|
if !found {
|
|
return nil, found
|
|
}
|
|
|
|
return component.(*Palette), found
|
|
}
|