1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-07-26 11:24:38 -04:00
OpenDiablo2/d2core/d2components/asset_palette_transform.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.5 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/d2pl2"
)
// static check that PaletteTransform implements Component
var _ akara.Component = &PaletteTransform{}
// PaletteTransform is a component that contains an embedded palette transform (pl2) struct
type PaletteTransform struct {
*d2pl2.PL2
}
// New returns a new PaletteTransform component. By default, it contains a nil instance.
func (*PaletteTransform) New() akara.Component {
return &PaletteTransform{}
}
// 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 {
PaletteTransform *akara.ComponentFactory
}
// AddPaletteTransform adds a PaletteTransform component to the given entity and returns it
func (m *PaletteTransformFactory) AddPaletteTransform(id akara.EID) *PaletteTransform {
return m.PaletteTransform.Add(id).(*PaletteTransform)
}
// GetPaletteTransform returns the PaletteTransform component for the given entity, and a bool for whether or not it exists
func (m *PaletteTransformFactory) GetPaletteTransform(id akara.EID) (*PaletteTransform, bool) {
component, found := m.PaletteTransform.Get(id)
if !found {
return nil, found
}
return component.(*PaletteTransform), found
}