mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-14 12:36:41 -05:00
* component ID's are dynamically allocated now * removed `akara.BaseComponent` member from components * component declarations drastically reduced
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
|
|
package d2components
|
|
|
|
import (
|
|
"github.com/gravestench/akara"
|
|
)
|
|
|
|
// static check that Priority implements Component
|
|
var _ akara.Component = new(Priority)
|
|
|
|
// Priority is a component that is used to add a priority value.
|
|
// This can generally be used for sorting entities when order matters.
|
|
type Priority struct {
|
|
Priority int
|
|
}
|
|
|
|
// New returns a new Priority instance. The default is 0.
|
|
func (Priority) New() akara.Component {
|
|
return &Priority{}
|
|
}
|
|
|
|
// PriorityFactory is a wrapper for the generic component factory that returns Priority component instances.
|
|
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a Priority.
|
|
type PriorityFactory struct {
|
|
Priority *akara.ComponentFactory
|
|
}
|
|
|
|
// AddPriority adds a Priority component to the given entity and returns it
|
|
func (m *PriorityFactory) AddPriority(id akara.EID) *Priority {
|
|
return m.Priority.Add(id).(*Priority)
|
|
}
|
|
|
|
// GetPriority returns the Priority component for the given entity, and a bool for whether or not it exists
|
|
func (m *PriorityFactory) GetPriority(id akara.EID) (*Priority, bool) {
|
|
component, found := m.Priority.Get(id)
|
|
if !found {
|
|
return nil, found
|
|
}
|
|
|
|
return component.(*Priority), found
|
|
}
|