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