2020-11-22 13:02:42 -08:00
|
|
|
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
|
2020-10-13 01:19:38 -07:00
|
|
|
package d2components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gravestench/akara"
|
|
|
|
)
|
|
|
|
|
|
|
|
// static check that FontTableComponent implements Component
|
|
|
|
var _ akara.Component = &FontTableComponent{}
|
|
|
|
|
|
|
|
// static check that FontTableMap implements ComponentMap
|
|
|
|
var _ akara.ComponentMap = &FontTableMap{}
|
|
|
|
|
2020-11-22 13:02:42 -08:00
|
|
|
// FontTableComponent is a component that contains font table data as a byte slice
|
2020-10-13 01:19:38 -07:00
|
|
|
type FontTableComponent struct {
|
2020-11-22 13:02:42 -08:00
|
|
|
*akara.BaseComponent
|
2020-10-13 01:19:38 -07:00
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// FontTableMap is a map of entity ID's to FontTable
|
|
|
|
type FontTableMap struct {
|
2020-11-22 13:02:42 -08:00
|
|
|
*akara.BaseComponentMap
|
2020-10-13 01:19:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddFontTable adds a new FontTableComponent for the given entity id and returns it.
|
|
|
|
// this is a convenience method for the generic Add method, as it returns a
|
|
|
|
// *FontTableComponent instead of an akara.Component
|
|
|
|
func (cm *FontTableMap) AddFontTable(id akara.EID) *FontTableComponent {
|
|
|
|
return cm.Add(id).(*FontTableComponent)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFontTable returns the FontTableComponent associated with the given entity id
|
|
|
|
func (cm *FontTableMap) GetFontTable(id akara.EID) (*FontTableComponent, bool) {
|
2020-11-22 13:02:42 -08:00
|
|
|
entry, found := cm.Get(id)
|
|
|
|
if entry == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry.(*FontTableComponent), found
|
2020-10-13 01:19:38 -07:00
|
|
|
}
|
|
|
|
|
2020-11-22 13:02:42 -08:00
|
|
|
// FontTable is a convenient reference to be used as a component identifier
|
|
|
|
var FontTable = newFontTable() // nolint:gochecknoglobals // global by design
|
|
|
|
|
|
|
|
func newFontTable() akara.Component {
|
|
|
|
return &FontTableComponent{
|
|
|
|
BaseComponent: akara.NewBaseComponent(AssetFontTableCID, newFontTable, newFontTableMap),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFontTableMap() akara.ComponentMap {
|
|
|
|
baseComponent := akara.NewBaseComponent(AssetFontTableCID, newFontTable, newFontTableMap)
|
|
|
|
baseMap := akara.NewBaseComponentMap(baseComponent)
|
|
|
|
|
|
|
|
cm := &FontTableMap{
|
|
|
|
BaseComponentMap: baseMap,
|
|
|
|
}
|
|
|
|
|
|
|
|
return cm
|
2020-10-13 01:19:38 -07:00
|
|
|
}
|