1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-07-26 11:24:38 -04:00

akara update: BaseComponent and BaseComponentMap

* common component methods have been put into BaseComponent and
BaseComponentMap
* boilerplate code for components has been significantly reduced
* all lint errors fixed in d2components
This commit is contained in:
gravestench 2020-11-22 13:02:42 -08:00
parent caafe7592c
commit b86ac4df84
40 changed files with 1027 additions and 2359 deletions

View File

@ -24,13 +24,10 @@ const (
AssetWavCID
AssetD2AnimDataCID
PositionCID
StaticPositionCID
VelocityCID
DirtyCID
PriorityCID
SurfaceCID
RenderCullCID
SceneCID
RenderableCID
CameraCID
ViewportCID
ViewportFilterCID

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
// static check that AnimationComponent implements Component
@ -13,64 +15,13 @@ var _ akara.ComponentMap = &AnimationMap{}
// AnimationComponent is a component that contains a width and height
type AnimationComponent struct {
*akara.BaseComponent
d2interface.Animation
}
// ID returns a unique identifier for the component type
func (*AnimationComponent) ID() akara.ComponentID {
return AnimationCID
}
// NewMap returns a new component map for the component type
func (*AnimationComponent) NewMap() akara.ComponentMap {
return NewAnimationMap()
}
// Animation is a convenient reference to be used as a component identifier
var Animation = (*AnimationComponent)(nil) // nolint:gochecknoglobals // global by design
// NewAnimationMap creates a new map of entity ID's to Animation
func NewAnimationMap() *AnimationMap {
cm := &AnimationMap{
components: make(map[akara.EID]*AnimationComponent),
}
return cm
}
// AnimationMap is a map of entity ID's to Animation
type AnimationMap struct {
world *akara.World
components map[akara.EID]*AnimationComponent
}
// Init initializes the component map with the given world
func (cm *AnimationMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*AnimationMap) ID() akara.ComponentID {
return AnimationCID
}
// NewMap returns a new component map for the component type
func (*AnimationMap) NewMap() akara.ComponentMap {
return NewAnimationMap()
}
// Add a new AnimationComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *AnimationMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &AnimationComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddAnimation adds a new AnimationComponent for the given entity id and returns it.
@ -80,20 +31,32 @@ func (cm *AnimationMap) AddAnimation(id akara.EID) *AnimationComponent {
return cm.Add(id).(*AnimationComponent)
}
// Get returns the component associated with the given entity id
func (cm *AnimationMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetAnimation returns the AnimationComponent associated with the given entity id
func (cm *AnimationMap) GetAnimation(id akara.EID) (*AnimationComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*AnimationComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *AnimationMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Animation is a convenient reference to be used as a component identifier
var Animation = newAnimation() // nolint:gochecknoglobals // global by design
func newAnimation() akara.Component {
return &AnimationComponent{
BaseComponent: akara.NewBaseComponent(AnimationCID, newAnimation, newAnimationMap),
}
}
func newAnimationMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AnimationCID, newAnimation, newAnimationMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &AnimationMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
)
// static check that CofComponent implements Component
@ -13,88 +15,48 @@ var _ akara.ComponentMap = &CofMap{}
// CofComponent is a component that contains an embedded cof struct
type CofComponent struct {
*akara.BaseComponent
*d2cof.COF
}
// ID returns a unique identifier for the component type
func (*CofComponent) ID() akara.ComponentID {
return AssetCofCID
}
// NewMap returns a new component map for the component type
func (*CofComponent) NewMap() akara.ComponentMap {
return NewCofMap()
}
// Cof is a convenient reference to be used as a component identifier
var Cof = (*CofComponent)(nil) // nolint:gochecknoglobals // global by design
// NewCofMap creates a new map of entity ID's to Cof
func NewCofMap() *CofMap {
cm := &CofMap{
components: make(map[akara.EID]*CofComponent),
}
return cm
}
// CofMap is a map of entity ID's to Cof
type CofMap struct {
world *akara.World
components map[akara.EID]*CofComponent
}
// Init initializes the component map with the given world
func (cm *CofMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*CofMap) ID() akara.ComponentID {
return AssetCofCID
}
// NewMap returns a new component map for the component type
func (*CofMap) NewMap() akara.ComponentMap {
return NewCofMap()
}
// Add a new CofComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *CofMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &CofComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddCof adds a new CofComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *CofComponent instead of an akara.Component
func (cm *CofMap) AddCof(id akara.EID) *CofComponent {
return cm.Add(id).(*CofComponent)
}
// Get returns the component associated with the given entity id
func (cm *CofMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetCof returns the CofComponent associated with the given entity id
func (cm *CofMap) GetCof(id akara.EID) (*CofComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*CofComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *CofMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Cof is a convenient reference to be used as a component identifier
var Cof = newCof() // nolint:gochecknoglobals // global by design
func newCof() akara.Component {
return &CofComponent{
BaseComponent: akara.NewBaseComponent(AssetCofCID, newCof, newCofMap),
}
}
func newCofMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetCofCID, newCof, newCofMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &CofMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2animdata"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2animdata"
)
// static check that AnimDataComponent implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &AnimDataComponent{}
// static check that AnimDataMap implements ComponentMap
var _ akara.ComponentMap = &AnimDataMap{}
// AnimDataComponent is a component that contains an embedded animdata struct
// AnimDataComponent is a component that contains an embedded AnimationData struct
type AnimDataComponent struct {
*akara.BaseComponent
*d2animdata.AnimationData
}
// ID returns a unique identifier for the component type
func (*AnimDataComponent) ID() akara.ComponentID {
return AssetD2AnimDataCID
}
// NewMap returns a new component map for the component type
func (*AnimDataComponent) NewMap() akara.ComponentMap {
return NewAnimDataMap()
}
// AnimData is a convenient reference to be used as a component identifier
var AnimData = (*AnimDataComponent)(nil) // nolint:gochecknoglobals // global by design
// NewAnimDataMap creates a new map of entity ID's to AnimData
func NewAnimDataMap() *AnimDataMap {
cm := &AnimDataMap{
components: make(map[akara.EID]*AnimDataComponent),
}
return cm
}
// AnimDataMap is a map of entity ID's to AnimData
type AnimDataMap struct {
world *akara.World
components map[akara.EID]*AnimDataComponent
}
// Init initializes the component map with the given world
func (cm *AnimDataMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*AnimDataMap) ID() akara.ComponentID {
return AssetD2AnimDataCID
}
// NewMap returns a new component map for the component type
func (*AnimDataMap) NewMap() akara.ComponentMap {
return NewAnimDataMap()
}
// Add a new AnimDataComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *AnimDataMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &AnimDataComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddAnimData adds a new AnimDataComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *AnimDataComponent instead of an akara.Component
func (cm *AnimDataMap) AddAnimData(id akara.EID) *AnimDataComponent {
return cm.Add(id).(*AnimDataComponent)
}
// Get returns the component associated with the given entity id
func (cm *AnimDataMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetAnimData returns the AnimDataComponent associated with the given entity id
func (cm *AnimDataMap) GetAnimData(id akara.EID) (*AnimDataComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*AnimDataComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *AnimDataMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// AnimData is a convenient reference to be used as a component identifier
var AnimData = newAnimData() // nolint:gochecknoglobals // global by design
func newAnimData() akara.Component {
return &AnimDataComponent{
BaseComponent: akara.NewBaseComponent(AssetD2AnimDataCID, newAnimData, newAnimDataMap),
}
}
func newAnimDataMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetD2AnimDataCID, newAnimData, newAnimDataMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &AnimDataMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,90 +13,50 @@ var _ akara.Component = &DataDictionaryComponent{}
// static check that DataDictionaryMap implements ComponentMap
var _ akara.ComponentMap = &DataDictionaryMap{}
// DataDictionaryComponent is a component that contains a file Type
// DataDictionaryComponent is a component that contains an embedded txt data dictionary struct
type DataDictionaryComponent struct {
*akara.BaseComponent
*d2txt.DataDictionary
}
// ID returns a unique identifier for the component type
func (*DataDictionaryComponent) ID() akara.ComponentID {
return AssetDataDictionaryCID
}
// NewMap returns a new component map for the component type
func (*DataDictionaryComponent) NewMap() akara.ComponentMap {
return NewDataDictionaryMap()
}
// DataDictionary is a convenient reference to be used as a component identifier
var DataDictionary = (*DataDictionaryComponent)(nil) // nolint:gochecknoglobals // global by design
// NewDataDictionaryMap creates a new map of entity ID's to DataDictionary
func NewDataDictionaryMap() *DataDictionaryMap {
cm := &DataDictionaryMap{
components: make(map[akara.EID]*DataDictionaryComponent),
}
return cm
}
// DataDictionaryMap is a map of entity ID's to DataDictionary
type DataDictionaryMap struct {
world *akara.World
components map[akara.EID]*DataDictionaryComponent
}
// Init initializes the component map with the given world
func (cm *DataDictionaryMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*DataDictionaryMap) ID() akara.ComponentID {
return AssetDataDictionaryCID
}
// NewMap returns a new component map for the component type
func (*DataDictionaryMap) NewMap() akara.ComponentMap {
return NewDataDictionaryMap()
}
// Add a new DataDictionaryComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *DataDictionaryMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &DataDictionaryComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDataDictionary adds a new DataDictionaryComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *DataDictionaryComponent instead of an akara.Component
func (cm *DataDictionaryMap) AddDataDictionary(id akara.EID) *DataDictionaryComponent {
return cm.Add(id).(*DataDictionaryComponent)
}
// Get returns the component associated with the given entity id
func (cm *DataDictionaryMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetDataDictionary returns the DataDictionaryComponent associated with the given entity id
func (cm *DataDictionaryMap) GetDataDictionary(id akara.EID) (*DataDictionaryComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*DataDictionaryComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *DataDictionaryMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// DataDictionary is a convenient reference to be used as a component identifier
var DataDictionary = newDataDictionary() // nolint:gochecknoglobals // global by design
func newDataDictionary() akara.Component {
return &DataDictionaryComponent{
BaseComponent: akara.NewBaseComponent(AssetDataDictionaryCID, newDataDictionary, newDataDictionaryMap),
}
}
func newDataDictionaryMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDataDictionaryCID, newDataDictionary, newDataDictionaryMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &DataDictionaryMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
)
// static check that Dc6Component implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &Dc6Component{}
// static check that Dc6Map implements ComponentMap
var _ akara.ComponentMap = &Dc6Map{}
// Dc6Component is a component that contains an embedded dc6 struct
// Dc6Component is a component that contains an embedded DC6 struct
type Dc6Component struct {
*akara.BaseComponent
*d2dc6.DC6
}
// ID returns a unique identifier for the component type
func (*Dc6Component) ID() akara.ComponentID {
return AssetDc6CID
}
// NewMap returns a new component map for the component type
func (*Dc6Component) NewMap() akara.ComponentMap {
return NewDc6Map()
}
// Dc6 is a convenient reference to be used as a component identifier
var Dc6 = (*Dc6Component)(nil) // nolint:gochecknoglobals // global by design
// NewDc6Map creates a new map of entity ID's to Dc6
func NewDc6Map() *Dc6Map {
cm := &Dc6Map{
components: make(map[akara.EID]*Dc6Component),
}
return cm
}
// Dc6Map is a map of entity ID's to Dc6
type Dc6Map struct {
world *akara.World
components map[akara.EID]*Dc6Component
}
// Init initializes the component map with the given world
func (cm *Dc6Map) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*Dc6Map) ID() akara.ComponentID {
return AssetDc6CID
}
// NewMap returns a new component map for the component type
func (*Dc6Map) NewMap() akara.ComponentMap {
return NewDc6Map()
}
// Add a new Dc6Component for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *Dc6Map) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &Dc6Component{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDc6 adds a new Dc6Component for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *Dc6Component instead of an akara.Component
func (cm *Dc6Map) AddDc6(id akara.EID) *Dc6Component {
return cm.Add(id).(*Dc6Component)
}
// Get returns the component associated with the given entity id
func (cm *Dc6Map) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetDc6 returns the Dc6Component associated with the given entity id
func (cm *Dc6Map) GetDc6(id akara.EID) (*Dc6Component, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*Dc6Component), found
}
// Remove a component for the given entity id, return the component.
func (cm *Dc6Map) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Dc6 is a convenient reference to be used as a component identifier
var Dc6 = newDc6() // nolint:gochecknoglobals // global by design
func newDc6() akara.Component {
return &Dc6Component{
BaseComponent: akara.NewBaseComponent(AssetDc6CID, newDc6, newDc6Map),
}
}
func newDc6Map() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDc6CID, newDc6, newDc6Map)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &Dc6Map{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
)
// static check that DccComponent implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &DccComponent{}
// static check that DccMap implements ComponentMap
var _ akara.ComponentMap = &DccMap{}
// DccComponent is a component that contains an embedded dcc struct
// DccComponent is a component that contains an embedded DCC struct
type DccComponent struct {
*akara.BaseComponent
*d2dcc.DCC
}
// ID returns a unique identifier for the component type
func (*DccComponent) ID() akara.ComponentID {
return AssetDccCID
}
// NewMap returns a new component map for the component type
func (*DccComponent) NewMap() akara.ComponentMap {
return NewDccMap()
}
// Dcc is a convenient reference to be used as a component identifier
var Dcc = (*DccComponent)(nil) // nolint:gochecknoglobals // global by design
// NewDccMap creates a new map of entity ID's to Dcc
func NewDccMap() *DccMap {
cm := &DccMap{
components: make(map[akara.EID]*DccComponent),
}
return cm
}
// DccMap is a map of entity ID's to Dcc
type DccMap struct {
world *akara.World
components map[akara.EID]*DccComponent
}
// Init initializes the component map with the given world
func (cm *DccMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*DccMap) ID() akara.ComponentID {
return AssetDccCID
}
// NewMap returns a new component map for the component type
func (*DccMap) NewMap() akara.ComponentMap {
return NewDccMap()
}
// Add a new DccComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *DccMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &DccComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDcc adds a new DccComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *DccComponent instead of an akara.Component
func (cm *DccMap) AddDcc(id akara.EID) *DccComponent {
return cm.Add(id).(*DccComponent)
}
// Get returns the component associated with the given entity id
func (cm *DccMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetDcc returns the DccComponent associated with the given entity id
func (cm *DccMap) GetDcc(id akara.EID) (*DccComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*DccComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *DccMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Dcc is a convenient reference to be used as a component identifier
var Dcc = newDcc() // nolint:gochecknoglobals // global by design
func newDcc() akara.Component {
return &DccComponent{
BaseComponent: akara.NewBaseComponent(AssetDccCID, newDcc, newDccMap),
}
}
func newDccMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDccCID, newDcc, newDccMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &DccMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2ds1"
)
// static check that Ds1Component implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &Ds1Component{}
// static check that Ds1Map implements ComponentMap
var _ akara.ComponentMap = &Ds1Map{}
// Ds1Component is a component that contains an embedded ds1 struct
// Ds1Component is a component that contains an embedded DS1 struct
type Ds1Component struct {
*akara.BaseComponent
*d2ds1.DS1
}
// ID returns a unique identifier for the component type
func (*Ds1Component) ID() akara.ComponentID {
return AssetDs1CID
}
// NewMap returns a new component map for the component type
func (*Ds1Component) NewMap() akara.ComponentMap {
return NewDs1Map()
}
// Ds1 is a convenient reference to be used as a component identifier
var Ds1 = (*Ds1Component)(nil) // nolint:gochecknoglobals // global by design
// NewDs1Map creates a new map of entity ID's to Ds1Component
func NewDs1Map() *Ds1Map {
cm := &Ds1Map{
components: make(map[akara.EID]*Ds1Component),
}
return cm
}
// Ds1Map is a map of entity ID's to Ds1Component
// Ds1Map is a map of entity ID's to Ds1
type Ds1Map struct {
world *akara.World
components map[akara.EID]*Ds1Component
}
// Init initializes the component map with the given world
func (cm *Ds1Map) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*Ds1Map) ID() akara.ComponentID {
return AssetDs1CID
}
// NewMap returns a new component map for the component type
func (*Ds1Map) NewMap() akara.ComponentMap {
return NewDs1Map()
}
// Add a new Ds1Component for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *Ds1Map) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &Ds1Component{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDs1 adds a new Ds1Component for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *Ds1Component instead of an akara.Component
func (cm *Ds1Map) AddDs1(id akara.EID) *Ds1Component {
return cm.Add(id).(*Ds1Component)
}
// Get returns the component associated with the given entity id
func (cm *Ds1Map) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
// GetDs1 returns the Ds1Component associated with the given entity id
func (cm *Ds1Map) GetDs1(id akara.EID) (*Ds1Component, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*Ds1Component), found
}
// GetDs1Component returns the Ds1Component associated with the given entity id
func (cm *Ds1Map) GetDs1Component(id akara.EID) (*Ds1Component, bool) {
entry, found := cm.components[id]
return entry, found
// Ds1 is a convenient reference to be used as a component identifier
var Ds1 = newDs1() // nolint:gochecknoglobals // global by design
func newDs1() akara.Component {
return &Ds1Component{
BaseComponent: akara.NewBaseComponent(AssetDs1CID, newDs1, newDs1Map),
}
}
// Remove a component for the given entity id, return the component.
func (cm *Ds1Map) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
func newDs1Map() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDs1CID, newDs1, newDs1Map)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &Ds1Map{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
)
// static check that Dt1Component implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &Dt1Component{}
// static check that Dt1Map implements ComponentMap
var _ akara.ComponentMap = &Dt1Map{}
// Dt1Component is a component that contains an embedded dt1 struct
// Dt1Component is a component that contains an embedded DT1 struct
type Dt1Component struct {
*akara.BaseComponent
*d2dt1.DT1
}
// ID returns a unique identifier for the component type
func (*Dt1Component) ID() akara.ComponentID {
return AssetDt1CID
}
// NewMap returns a new component map for the component type
func (*Dt1Component) NewMap() akara.ComponentMap {
return NewDt1Map()
}
// Dt1 is a convenient reference to be used as a component identifier
var Dt1 = (*Dt1Component)(nil) // nolint:gochecknoglobals // global by design
// NewDt1Map creates a new map of entity ID's to Dt1
func NewDt1Map() *Dt1Map {
cm := &Dt1Map{
components: make(map[akara.EID]*Dt1Component),
}
return cm
}
// Dt1Map is a map of entity ID's to Dt1
type Dt1Map struct {
world *akara.World
components map[akara.EID]*Dt1Component
}
// Init initializes the component map with the given world
func (cm *Dt1Map) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*Dt1Map) ID() akara.ComponentID {
return AssetDt1CID
}
// NewMap returns a new component map for the component type
func (*Dt1Map) NewMap() akara.ComponentMap {
return NewDt1Map()
}
// Add a new Dt1Component for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *Dt1Map) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &Dt1Component{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDt1 adds a new Dt1Component for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *Dt1Component instead of an akara.Component
func (cm *Dt1Map) AddDt1(id akara.EID) *Dt1Component {
return cm.Add(id).(*Dt1Component)
}
// Get returns the component associated with the given entity id
func (cm *Dt1Map) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetDt1 returns the Dt1Component associated with the given entity id
func (cm *Dt1Map) GetDt1(id akara.EID) (*Dt1Component, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*Dt1Component), found
}
// Remove a component for the given entity id, return the component.
func (cm *Dt1Map) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Dt1 is a convenient reference to be used as a component identifier
var Dt1 = newDt1() // nolint:gochecknoglobals // global by design
func newDt1() akara.Component {
return &Dt1Component{
BaseComponent: akara.NewBaseComponent(AssetDt1CID, newDt1, newDt1Map),
}
}
func newDt1Map() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetDt1CID, newDt1, newDt1Map)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &Dt1Map{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -10,90 +11,50 @@ var _ akara.Component = &FontTableComponent{}
// static check that FontTableMap implements ComponentMap
var _ akara.ComponentMap = &FontTableMap{}
// FontTableComponent is a component that contains a file Type
// FontTableComponent is a component that contains font table data as a byte slice
type FontTableComponent struct {
*akara.BaseComponent
Data []byte
}
// ID returns a unique identifier for the component type
func (*FontTableComponent) ID() akara.ComponentID {
return AssetFontTableCID
}
// NewMap returns a new component map for the component type
func (*FontTableComponent) NewMap() akara.ComponentMap {
return NewFontTableMap()
}
// FontTable is a convenient reference to be used as a component identifier
var FontTable = (*FontTableComponent)(nil) // nolint:gochecknoglobals // global by design
// NewFontTableMap creates a new map of entity ID's to FontTable
func NewFontTableMap() *FontTableMap {
cm := &FontTableMap{
components: make(map[akara.EID]*FontTableComponent),
}
return cm
}
// FontTableMap is a map of entity ID's to FontTable
type FontTableMap struct {
world *akara.World
components map[akara.EID]*FontTableComponent
}
// Init initializes the component map with the given world
func (cm *FontTableMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*FontTableMap) ID() akara.ComponentID {
return AssetFontTableCID
}
// NewMap returns a new component map for the component type
func (*FontTableMap) NewMap() akara.ComponentMap {
return NewFontTableMap()
}
// Add a new FontTableComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *FontTableMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &FontTableComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddFontTable adds a new FontTableComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// 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)
}
// Get returns the component associated with the given entity id
func (cm *FontTableMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetFontTable returns the FontTableComponent associated with the given entity id
func (cm *FontTableMap) GetFontTable(id akara.EID) (*FontTableComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*FontTableComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *FontTableMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// 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
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
// static check that PaletteComponent implements Component
@ -11,90 +13,50 @@ var _ akara.Component = &PaletteComponent{}
// static check that PaletteMap implements ComponentMap
var _ akara.ComponentMap = &PaletteMap{}
// PaletteComponent is a component that contains a n embedded DATPalette struct
// PaletteComponent is a component that contains an embedded palette interface
type PaletteComponent struct {
*akara.BaseComponent
d2interface.Palette
}
// ID returns a unique identifier for the component type
func (*PaletteComponent) ID() akara.ComponentID {
return AssetPaletteCID
}
// NewMap returns a new component map for the component type
func (*PaletteComponent) NewMap() akara.ComponentMap {
return NewPaletteMap()
}
// Palette is a convenient reference to be used as a component identifier
var Palette = (*PaletteComponent)(nil) // nolint:gochecknoglobals // global by design
// NewPaletteMap creates a new map of entity ID's to Palette
func NewPaletteMap() *PaletteMap {
cm := &PaletteMap{
components: make(map[akara.EID]*PaletteComponent),
}
return cm
}
// PaletteMap is a map of entity ID's to Palette
type PaletteMap struct {
world *akara.World
components map[akara.EID]*PaletteComponent
}
// Init initializes the component map with the given world
func (cm *PaletteMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*PaletteMap) ID() akara.ComponentID {
return AssetPaletteCID
}
// NewMap returns a new component map for the component type
func (*PaletteMap) NewMap() akara.ComponentMap {
return NewPaletteMap()
}
// Add a new PaletteComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *PaletteMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &PaletteComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddPalette adds a new PaletteComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *PaletteComponent instead of an akara.Component
func (cm *PaletteMap) AddPalette(id akara.EID) *PaletteComponent {
return cm.Add(id).(*PaletteComponent)
}
// Get returns the component associated with the given entity id
func (cm *PaletteMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetPalette returns the PaletteComponent associated with the given entity id
func (cm *PaletteMap) GetPalette(id akara.EID) (*PaletteComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*PaletteComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *PaletteMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Palette is a convenient reference to be used as a component identifier
var Palette = newPalette() // nolint:gochecknoglobals // global by design
func newPalette() akara.Component {
return &PaletteComponent{
BaseComponent: akara.NewBaseComponent(AssetPaletteCID, newPalette, newPaletteMap),
}
}
func newPaletteMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetPaletteCID, newPalette, newPaletteMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &PaletteMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2pl2"
)
// static check that PaletteTransformComponent implements Component
@ -11,92 +13,50 @@ var _ akara.Component = &PaletteTransformComponent{}
// static check that PaletteTransformMap implements ComponentMap
var _ akara.ComponentMap = &PaletteTransformMap{}
// PaletteTransformComponent is a component that contains an embedded PL2 struct
// PaletteTransformComponent is a component that contains an embedded palette transform (pl2) struct
type PaletteTransformComponent struct {
*akara.BaseComponent
Transform *d2pl2.PL2
}
// ID returns a unique identifier for the component type
func (*PaletteTransformComponent) ID() akara.ComponentID {
return AssetPaletteTransformCID
}
// NewMap returns a new component map for the component type
func (*PaletteTransformComponent) NewMap() akara.ComponentMap {
return NewPaletteTransformMap()
}
// PaletteTransform is a convenient reference to be used as a component identifier
var PaletteTransform = (*PaletteTransformComponent)(
nil) // nolint:gochecknoglobals // global by design
// NewPaletteTransformMap creates a new map of entity ID's to PaletteTransform
func NewPaletteTransformMap() *PaletteTransformMap {
cm := &PaletteTransformMap{
components: make(map[akara.EID]*PaletteTransformComponent),
}
return cm
}
// PaletteTransformMap is a map of entity ID's to PaletteTransform
type PaletteTransformMap struct {
world *akara.World
components map[akara.EID]*PaletteTransformComponent
}
// Init initializes the component map with the given world
func (cm *PaletteTransformMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*PaletteTransformMap) ID() akara.ComponentID {
return AssetPaletteTransformCID
}
// NewMap returns a new component map for the component type
func (*PaletteTransformMap) NewMap() akara.ComponentMap {
return NewPaletteTransformMap()
}
// Add a new PaletteTransformComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *PaletteTransformMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &PaletteTransformComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddPaletteTransform adds a new PaletteTransformComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *PaletteTransformComponent instead of an akara.Component
func (cm *PaletteTransformMap) AddPaletteTransform(id akara.EID) *PaletteTransformComponent {
return cm.Add(id).(*PaletteTransformComponent)
}
// Get returns the component associated with the given entity id
func (cm *PaletteTransformMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetPaletteTransform returns the PaletteTransformComponent associated with the given entity id
func (cm *PaletteTransformMap) GetPaletteTransform(id akara.EID) (*PaletteTransformComponent,
bool) {
entry, found := cm.components[id]
return entry, found
func (cm *PaletteTransformMap) GetPaletteTransform(id akara.EID) (*PaletteTransformComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*PaletteTransformComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *PaletteTransformMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// PaletteTransform is a convenient reference to be used as a component identifier
var PaletteTransform = newPaletteTransform() // nolint:gochecknoglobals // global by design
func newPaletteTransform() akara.Component {
return &PaletteTransformComponent{
BaseComponent: akara.NewBaseComponent(AssetPaletteTransformCID, newPaletteTransform, newPaletteTransformMap),
}
}
func newPaletteTransformMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetPaletteTransformCID, newPaletteTransform, newPaletteTransformMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &PaletteTransformMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,90 +13,50 @@ var _ akara.Component = &StringTableComponent{}
// static check that StringTableMap implements ComponentMap
var _ akara.ComponentMap = &StringTableMap{}
// StringTableComponent is a component that contains an embedded string table struct
// StringTableComponent is a component that contains an embedded text table struct
type StringTableComponent struct {
*akara.BaseComponent
*d2tbl.TextDictionary
}
// ID returns a unique identifier for the component type
func (*StringTableComponent) ID() akara.ComponentID {
return AssetStringTableCID
}
// NewMap returns a new component map for the component type
func (*StringTableComponent) NewMap() akara.ComponentMap {
return NewStringTableMap()
}
// StringTable is a convenient reference to be used as a component identifier
var StringTable = (*StringTableComponent)(nil) // nolint:gochecknoglobals // global by design
// NewStringTableMap creates a new map of entity ID's to StringTable
func NewStringTableMap() *StringTableMap {
cm := &StringTableMap{
components: make(map[akara.EID]*StringTableComponent),
}
return cm
}
// StringTableMap is a map of entity ID's to StringTable
type StringTableMap struct {
world *akara.World
components map[akara.EID]*StringTableComponent
}
// Init initializes the component map with the given world
func (cm *StringTableMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*StringTableMap) ID() akara.ComponentID {
return AssetStringTableCID
}
// NewMap returns a new component map for the component type
func (*StringTableMap) NewMap() akara.ComponentMap {
return NewStringTableMap()
}
// Add a new StringTableComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *StringTableMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &StringTableComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddStringTable adds a new StringTableComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *StringTableComponent instead of an akara.Component
func (cm *StringTableMap) AddStringTable(id akara.EID) *StringTableComponent {
return cm.Add(id).(*StringTableComponent)
}
// Get returns the component associated with the given entity id
func (cm *StringTableMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetStringTable returns the StringTableComponent associated with the given entity id
func (cm *StringTableMap) GetStringTable(id akara.EID) (*StringTableComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*StringTableComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *StringTableMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// StringTable is a convenient reference to be used as a component identifier
var StringTable = newStringTable() // nolint:gochecknoglobals // global by design
func newStringTable() akara.Component {
return &StringTableComponent{
BaseComponent: akara.NewBaseComponent(AssetStringTableCID, newStringTable, newStringTableMap),
}
}
func newStringTableMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetStringTableCID, newStringTable, newStringTableMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &StringTableMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,90 +13,50 @@ var _ akara.Component = &WavComponent{}
// static check that WavMap implements ComponentMap
var _ akara.ComponentMap = &WavMap{}
// WavComponent is a component that contains an embedded wav.Stream
// WavComponent is a component that contains an embedded io.ReadSeeker for streaming wav audio files
type WavComponent struct {
*akara.BaseComponent
Data io.ReadSeeker
}
// ID returns a unique identifier for the component type
func (*WavComponent) ID() akara.ComponentID {
return AssetWavCID
}
// NewMap returns a new component map for the component type
func (*WavComponent) NewMap() akara.ComponentMap {
return NewWavMap()
}
// Wav is a convenient reference to be used as a component identifier
var Wav = (*WavComponent)(nil) // nolint:gochecknoglobals // global by design
// NewWavMap creates a new map of entity ID's to Wav
func NewWavMap() *WavMap {
cm := &WavMap{
components: make(map[akara.EID]*WavComponent),
}
return cm
}
// WavMap is a map of entity ID's to Wav
type WavMap struct {
world *akara.World
components map[akara.EID]*WavComponent
}
// Init initializes the component map with the given world
func (cm *WavMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*WavMap) ID() akara.ComponentID {
return AssetWavCID
}
// NewMap returns a new component map for the component type
func (*WavMap) NewMap() akara.ComponentMap {
return NewWavMap()
}
// Add a new WavComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *WavMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &WavComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddWav adds a new WavComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *WavComponent instead of an akara.Component
func (cm *WavMap) AddWav(id akara.EID) *WavComponent {
return cm.Add(id).(*WavComponent)
}
// Get returns the component associated with the given entity id
func (cm *WavMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetWav returns the WavComponent associated with the given entity id
func (cm *WavMap) GetWav(id akara.EID) (*WavComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*WavComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *WavMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Wav is a convenient reference to be used as a component identifier
var Wav = newWav() // nolint:gochecknoglobals // global by design
func newWav() akara.Component {
return &WavComponent{
BaseComponent: akara.NewBaseComponent(AssetWavCID, newWav, newWavMap),
}
}
func newWavMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(AssetWavCID, newWav, newWavMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &WavMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
)
// static check that CameraComponent implements Component
@ -13,92 +15,55 @@ var _ akara.ComponentMap = &CameraMap{}
// CameraComponent represents a camera that can be rendered to
type CameraComponent struct {
*akara.BaseComponent
*d2vector.Vector
Width int
Height int
Zoom float64
}
// ID returns a unique identifier for the component type
func (*CameraComponent) ID() akara.ComponentID {
return CameraCID
}
// NewMap returns a new component map for the component type
func (*CameraComponent) NewMap() akara.ComponentMap {
return NewCameraMap()
}
// Camera is a convenient reference to be used as a component identifier
var Camera = (*CameraComponent)(nil) // nolint:gochecknoglobals // global by design
// NewCameraMap creates a new map of entity ID's to Camera
func NewCameraMap() *CameraMap {
cm := &CameraMap{
components: make(map[akara.EID]*CameraComponent),
}
return cm
}
// CameraMap is a map of entity ID's to Camera
type CameraMap struct {
world *akara.World
components map[akara.EID]*CameraComponent
}
// Init initializes the component map with the given world
func (cm *CameraMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*CameraMap) ID() akara.ComponentID {
return CameraCID
}
// NewMap returns a new component map for the component type
func (*CameraMap) NewMap() akara.ComponentMap {
return NewCameraMap()
}
// Add a new CameraComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *CameraMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
position := d2vector.NewVector(0, 0)
cm.components[id] = &CameraComponent{Vector: position}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddCamera adds a new CameraComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *CameraComponent instead of an akara.Component
func (cm *CameraMap) AddCamera(id akara.EID) *CameraComponent {
return cm.Add(id).(*CameraComponent)
}
camera := cm.Add(id).(*CameraComponent)
// Get returns the component associated with the given entity id
func (cm *CameraMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
camera.Vector = d2vector.NewVector(0, 0)
return camera
}
// GetCamera returns the CameraComponent associated with the given entity id
func (cm *CameraMap) GetCamera(id akara.EID) (*CameraComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*CameraComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *CameraMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Camera is a convenient reference to be used as a component identifier
var Camera = newCamera() // nolint:gochecknoglobals // global by design
func newCamera() akara.Component {
return &CameraComponent{
BaseComponent: akara.NewBaseComponent(CameraCID, newCamera, newCameraMap),
}
}
func newCameraMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(CameraCID, newCamera, newCameraMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &CameraMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -10,92 +11,50 @@ var _ akara.Component = &DirtyComponent{}
// static check that DirtyMap implements ComponentMap
var _ akara.ComponentMap = &DirtyMap{}
// DirtyComponent is a component that is used to signify when something is "dirty".
// What this means depends on the context, but it is typically used as a condition to
// perform some processing.
// DirtyComponent is a flag component that is used to denote a "dirty" state
type DirtyComponent struct {
*akara.BaseComponent
IsDirty bool
}
// ID returns a unique identifier for the component type
func (*DirtyComponent) ID() akara.ComponentID {
return DirtyCID
}
// NewMap returns a new component map for the component type
func (*DirtyComponent) NewMap() akara.ComponentMap {
return NewDirtyMap()
}
// Dirty is a convenient reference to be used as a component identifier
var Dirty = (*DirtyComponent)(nil) // nolint:gochecknoglobals // global by design
// NewDirtyMap creates a new map of entity ID's to Dirty
func NewDirtyMap() *DirtyMap {
cm := &DirtyMap{
components: make(map[akara.EID]*DirtyComponent),
}
return cm
}
// DirtyMap is a map of entity ID's to Dirty
type DirtyMap struct {
world *akara.World
components map[akara.EID]*DirtyComponent
}
// Init initializes the component map with the given world
func (cm *DirtyMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*DirtyMap) ID() akara.ComponentID {
return DirtyCID
}
// NewMap returns a new component map for the component type
func (*DirtyMap) NewMap() akara.ComponentMap {
return NewDirtyMap()
}
// Add a new DirtyComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *DirtyMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &DirtyComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddDirty adds a new DirtyComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *DirtyComponent instead of an akara.Component
func (cm *DirtyMap) AddDirty(id akara.EID) *DirtyComponent {
return cm.Add(id).(*DirtyComponent)
}
// Get returns the component associated with the given entity id
func (cm *DirtyMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetDirty returns the DirtyComponent associated with the given entity id
func (cm *DirtyMap) GetDirty(id akara.EID) (*DirtyComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*DirtyComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *DirtyMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Dirty is a convenient reference to be used as a component identifier
var Dirty = newDirty() // nolint:gochecknoglobals // global by design
func newDirty() akara.Component {
return &DirtyComponent{
BaseComponent: akara.NewBaseComponent(DirtyCID, newDirty, newDirtyMap),
}
}
func newDirtyMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(DirtyCID, newDirty, newDirtyMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &DirtyMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,90 +13,50 @@ var _ akara.Component = &FileHandleComponent{}
// static check that FileHandleMap implements ComponentMap
var _ akara.ComponentMap = &FileHandleMap{}
// FileHandleComponent is a component that contains a data stream
// FileHandleComponent is a component that contains a data stream for file data
type FileHandleComponent struct {
*akara.BaseComponent
Data d2interface.DataStream
}
// ID returns a unique identifier for the component type
func (*FileHandleComponent) ID() akara.ComponentID {
return FileHandleCID
}
// NewMap returns a new component map for the component type
func (*FileHandleComponent) NewMap() akara.ComponentMap {
return NewFileHandleMap()
}
// FileHandle is a convenient reference to be used as a component identifier
var FileHandle = (*FileHandleComponent)(nil) // nolint:gochecknoglobals // global by design
// NewFileHandleMap creates a new map of entity ID's to FileHandleComponent components
func NewFileHandleMap() *FileHandleMap {
cm := &FileHandleMap{
components: make(map[akara.EID]*FileHandleComponent),
}
return cm
}
// FileHandleMap is a map of entity ID's to FileHandleComponent components
// FileHandleMap is a map of entity ID's to FileHandle
type FileHandleMap struct {
world *akara.World
components map[akara.EID]*FileHandleComponent
}
// Init initializes the component map with the given world
func (cm *FileHandleMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*FileHandleMap) ID() akara.ComponentID {
return FileHandleCID
}
// NewMap returns a new component map for the component type
func (*FileHandleMap) NewMap() akara.ComponentMap {
return NewFileHandleMap()
}
// Add a new FileHandleComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *FileHandleMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &FileHandleComponent{Data: nil}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddFileHandle adds a new FileHandleComponent for the given entity id and returns it.
// If the entity already has a FileHandleComponent, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *FileHandleComponent instead of an akara.Component
func (cm *FileHandleMap) AddFileHandle(id akara.EID) *FileHandleComponent {
return cm.Add(id).(*FileHandleComponent)
}
// Get returns the component associated with the given entity id
func (cm *FileHandleMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetFileHandle returns the FileHandleComponent component associated with the given entity id
// GetFileHandle returns the FileHandleComponent associated with the given entity id
func (cm *FileHandleMap) GetFileHandle(id akara.EID) (*FileHandleComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*FileHandleComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *FileHandleMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// FileHandle is a convenient reference to be used as a component identifier
var FileHandle = newFileHandle() // nolint:gochecknoglobals // global by design
func newFileHandle() akara.Component {
return &FileHandleComponent{
BaseComponent: akara.NewBaseComponent(FileHandleCID, newFileHandle, newFileHandleMap),
}
}
func newFileHandleMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(FileHandleCID, newFileHandle, newFileHandleMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &FileHandleMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -10,90 +11,50 @@ var _ akara.Component = &FilePathComponent{}
// static check that FilePathMap implements ComponentMap
var _ akara.ComponentMap = &FilePathMap{}
// FilePathComponent is a component that contains a file Path string
// FilePathComponent represents a file path for a file
type FilePathComponent struct {
*akara.BaseComponent
Path string
}
// ID returns a unique identifier for the component type
func (*FilePathComponent) ID() akara.ComponentID {
return FilePathCID
}
// NewMap returns a new component map for the component type
func (*FilePathComponent) NewMap() akara.ComponentMap {
return NewFilePathMap()
}
// FilePath is a convenient reference to be used as a component identifier
var FilePath = (*FilePathComponent)(nil) // nolint:gochecknoglobals // global by design
// NewFilePathMap creates a new map of entity ID's to FilePath
func NewFilePathMap() *FilePathMap {
cm := &FilePathMap{
components: make(map[akara.EID]*FilePathComponent),
}
return cm
}
// FilePathMap is a map of entity ID's to FilePath
type FilePathMap struct {
world *akara.World
components map[akara.EID]*FilePathComponent
}
// Init initializes the component map with the given world
func (cm *FilePathMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*FilePathMap) ID() akara.ComponentID {
return FilePathCID
}
// NewMap returns a new component map for the component type
func (*FilePathMap) NewMap() akara.ComponentMap {
return NewFilePathMap()
}
// Add a new FilePathComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *FilePathMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &FilePathComponent{Path: ""}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddFilePath adds a new FilePathComponent for the given entity id and returns it.
// If the entity already has a FilePathComponent, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *FilePathComponent instead of an akara.Component
func (cm *FilePathMap) AddFilePath(id akara.EID) *FilePathComponent {
return cm.Add(id).(*FilePathComponent)
}
// Get returns the component associated with the given entity id
func (cm *FilePathMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetFilePath returns the FilePathComponent associated with the given entity id
func (cm *FilePathMap) GetFilePath(id akara.EID) (*FilePathComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*FilePathComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *FilePathMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// FilePath is a convenient reference to be used as a component identifier
var FilePath = newFilePath() // nolint:gochecknoglobals // global by design
func newFilePath() akara.Component {
return &FilePathComponent{
BaseComponent: akara.NewBaseComponent(FilePathCID, newFilePath, newFilePathMap),
}
}
func newFilePathMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(FilePathCID, newFilePath, newFilePathMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &FilePathMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -6,102 +7,62 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
// AbstractSource is the abstract representation of what a file source is
type AbstractSource interface {
Path() string // the path of the source itself
Open(path *FilePathComponent) (d2interface.DataStream, error)
}
// static check that FileSourceComponent implements Component
var _ akara.Component = &FileSourceComponent{}
// static check that FileSourceMap implements ComponentMap
var _ akara.ComponentMap = &FileSourceMap{}
// AbstractSource is the abstract representation of what a file source is
type AbstractSource interface {
Path() string
Open(path *FilePathComponent) (d2interface.DataStream, error)
}
// FileSourceComponent is a component that contains a FileSourceComponent instance
// FileSourceComponent contains an embedded file source interface, something that can open files
type FileSourceComponent struct {
*akara.BaseComponent
AbstractSource
}
// ID returns a unique identifier for the component type
func (*FileSourceComponent) ID() akara.ComponentID {
return FileSourceCID
}
// NewMap returns a new component map for the component type
func (*FileSourceComponent) NewMap() akara.ComponentMap {
return NewFileSourceMap()
}
// FileSource is a convenient reference to be used as a component identifier
var FileSource = (*FileSourceComponent)(nil) // nolint:gochecknoglobals // global by design
// NewFileSourceMap creates a new map of entity ID's to FileSourceComponent components
func NewFileSourceMap() *FileSourceMap {
cm := &FileSourceMap{
components: make(map[akara.EID]*FileSourceComponent),
}
return cm
}
// FileSourceMap is a map of entity ID's to FileSourceComponent type components
// FileSourceMap is a map of entity ID's to FileSource
type FileSourceMap struct {
world *akara.World
components map[akara.EID]*FileSourceComponent
}
// Init initializes the component map with the given world
func (cm *FileSourceMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*FileSourceMap) ID() akara.ComponentID {
return FileSourceCID
}
// NewMap returns a new component map for the component type
func (*FileSourceMap) NewMap() akara.ComponentMap {
return NewFileSourceMap()
}
// Add a new FileSourceComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *FileSourceMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &FileSourceComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddFileSource adds a new FileSourceComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *FileSourceComponent instead of an akara.Component
func (cm *FileSourceMap) AddFileSource(id akara.EID) *FileSourceComponent {
return cm.Add(id).(*FileSourceComponent)
}
// Get returns the component associated with the given entity id
func (cm *FileSourceMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetFileSource returns the FileSourceComponent type component associated with the given entity id
// GetFileSource returns the FileSourceComponent associated with the given entity id
func (cm *FileSourceMap) GetFileSource(id akara.EID) (*FileSourceComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*FileSourceComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *FileSourceMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// FileSource is a convenient reference to be used as a component identifier
var FileSource = newFileSource() // nolint:gochecknoglobals // global by design
func newFileSource() akara.Component {
return &FileSourceComponent{
BaseComponent: akara.NewBaseComponent(FileSourceCID, newFileSource, newFileSourceMap),
}
}
func newFileSourceMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(FileSourceCID, newFileSource, newFileSourceMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &FileSourceMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,90 +13,50 @@ var _ akara.Component = &FileTypeComponent{}
// static check that FileTypeMap implements ComponentMap
var _ akara.ComponentMap = &FileTypeMap{}
// FileTypeComponent is a component that contains a file Type
// FileTypeComponent is used to flag file entities with a file type
type FileTypeComponent struct {
*akara.BaseComponent
Type d2enum.FileType
}
// ID returns a unique identifier for the component type
func (*FileTypeComponent) ID() akara.ComponentID {
return FileTypeCID
}
// NewMap returns a new component map for the component type
func (*FileTypeComponent) NewMap() akara.ComponentMap {
return NewFileTypeMap()
}
// FileType is a convenient reference to be used as a component identifier
var FileType = (*FileTypeComponent)(nil) // nolint:gochecknoglobals // global by design
// NewFileTypeMap creates a new map of entity ID's to FileType
func NewFileTypeMap() *FileTypeMap {
cm := &FileTypeMap{
components: make(map[akara.EID]*FileTypeComponent),
}
return cm
}
// FileTypeMap is a map of entity ID's to FileType
type FileTypeMap struct {
world *akara.World
components map[akara.EID]*FileTypeComponent
}
// Init initializes the component map with the given world
func (cm *FileTypeMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*FileTypeMap) ID() akara.ComponentID {
return FileTypeCID
}
// NewMap returns a new component map for the component type
func (*FileTypeMap) NewMap() akara.ComponentMap {
return NewFileTypeMap()
}
// Add a new FileTypeComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *FileTypeMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &FileTypeComponent{Type: d2enum.FileTypeUnknown}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddFileType adds a new FileTypeComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *FileTypeComponent instead of an akara.Component
func (cm *FileTypeMap) AddFileType(id akara.EID) *FileTypeComponent {
return cm.Add(id).(*FileTypeComponent)
}
// Get returns the component associated with the given entity id
func (cm *FileTypeMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetFileType returns the FileTypeComponent associated with the given entity id
func (cm *FileTypeMap) GetFileType(id akara.EID) (*FileTypeComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*FileTypeComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *FileTypeMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// FileType is a convenient reference to be used as a component identifier
var FileType = newFileType() // nolint:gochecknoglobals // global by design
func newFileType() akara.Component {
return &FileTypeComponent{
BaseComponent: akara.NewBaseComponent(FileTypeCID, newFileType, newFileTypeMap),
}
}
func newFileTypeMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(FileTypeCID, newFileType, newFileTypeMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &FileTypeMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,11 +1,13 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"os/user"
"path"
"runtime"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"github.com/gravestench/akara"
)
@ -15,9 +17,10 @@ var _ akara.Component = &GameConfigComponent{}
// static check that GameConfigMap implements ComponentMap
var _ akara.ComponentMap = &GameConfigMap{}
// GameConfigComponent represents an OpenDiablo2 game configuration
type GameConfigComponent struct {
*akara.BaseComponent
MpqLoadOrder []string
Language string
MpqPath string
TicksPerSecond int
FpsCap int
@ -30,120 +33,76 @@ type GameConfigComponent struct {
LogLevel d2util.LogLevel
}
// ID returns a unique identifier for the component type
func (*GameConfigComponent) ID() akara.ComponentID {
return GameConfigCID
// GameConfigMap is a map of entity ID's to GameConfig
type GameConfigMap struct {
*akara.BaseComponentMap
}
// NewMap returns a new component map for the component type
func (*GameConfigComponent) NewMap() akara.ComponentMap {
return NewGameConfigMap()
// AddGameConfig adds a new GameConfigComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *GameConfigComponent instead of an akara.Component
func (cm *GameConfigMap) AddGameConfig(id akara.EID) *GameConfigComponent {
return defaultConfig(cm.Add(id).(*GameConfigComponent))
}
// GetGameConfig returns the GameConfigComponent associated with the given entity id
func (cm *GameConfigMap) GetGameConfig(id akara.EID) (*GameConfigComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*GameConfigComponent), found
}
// GameConfig is a convenient reference to be used as a component identifier
var GameConfig = (*GameConfigComponent)(nil) // nolint:gochecknoglobals // global by design
var GameConfig = newGameConfig() // nolint:gochecknoglobals // global by design
func newGameConfig() akara.Component {
return &GameConfigComponent{
BaseComponent: akara.NewBaseComponent(GameConfigCID, newGameConfig, newGameConfigMap),
}
}
func newGameConfigMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(GameConfigCID, newGameConfig, newGameConfigMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
// NewGameConfigMap creates a new map of entity ID's to GameConfigComponent components
func NewGameConfigMap() *GameConfigMap {
cm := &GameConfigMap{
components: make(map[akara.EID]*GameConfigComponent),
BaseComponentMap: baseMap,
}
return cm
}
// GameConfigMap is a map of entity ID's to GameConfigComponent components
type GameConfigMap struct {
world *akara.World
components map[akara.EID]*GameConfigComponent
}
// Init initializes the component map with the given world
func (cm *GameConfigMap) Init(world *akara.World) {
cm.world = world
}
// Add a new GameConfigComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *GameConfigMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = defaultConfig()
cm.world.UpdateEntity(id)
return cm.components[id]
}
// ID returns a unique identifier for the component type
func (*GameConfigMap) ID() akara.ComponentID {
return GameConfigCID
}
// NewMap returns a new component map for the component type
func (*GameConfigMap) NewMap() akara.ComponentMap {
return NewGameConfigMap()
}
// AddGameConfig adds a new GameConfigComponent for the given entity id and returns it.
// If the entity already has a GameConfigComponent component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *GameConfigComponent instead of an akara.Component
func (cm *GameConfigMap) AddGameConfig(id akara.EID) *GameConfigComponent {
return cm.Add(id).(*GameConfigComponent)
}
// Get returns the component associated with the given entity id
func (cm *GameConfigMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetGameConfig returns the GameConfigComponent component associated with the given entity id
func (cm *GameConfigMap) GetGameConfig(id akara.EID) (*GameConfigComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *GameConfigMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}
func defaultConfig() *GameConfigComponent {
func defaultConfig(config *GameConfigComponent) *GameConfigComponent {
const (
defaultSfxVolume = 1.0
defaultBgmVolume = 0.3
)
config := &GameConfigComponent{
Language: "ENG",
FullScreen: false,
TicksPerSecond: -1,
RunInBackground: true,
VsyncEnabled: true,
SfxVolume: defaultSfxVolume,
BgmVolume: defaultBgmVolume,
MpqPath: "C:/Program Files (x86)/Diablo II",
Backend: "Ebiten",
MpqLoadOrder: []string{
"Patch_D2.mpq",
"d2exp.mpq",
"d2xmusic.mpq",
"d2xtalk.mpq",
"d2xvideo.mpq",
"d2data.mpq",
"d2char.mpq",
"d2music.mpq",
"d2sfx.mpq",
"d2video.mpq",
"d2speech.mpq",
},
LogLevel: d2util.LogLevelDefault,
config.FullScreen = false
config.TicksPerSecond = -1
config.RunInBackground = true
config.VsyncEnabled = true
config.SfxVolume = defaultSfxVolume
config.BgmVolume = defaultBgmVolume
config.MpqPath = "C:/Program Files (x86)/Diablo II"
config.Backend = "Ebiten"
config.MpqLoadOrder = []string{
"Patch_D2.mpq",
"d2exp.mpq",
"d2xmusic.mpq",
"d2xtalk.mpq",
"d2xvideo.mpq",
"d2data.mpq",
"d2char.mpq",
"d2music.mpq",
"d2sfx.mpq",
"d2video.mpq",
"d2speech.mpq",
}
config.LogLevel = d2util.LogLevelDefault
switch runtime.GOOS {
case "windows":

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -14,88 +15,48 @@ var _ akara.ComponentMap = &OriginMap{}
// The values are normalized to the display width/height.
// For example, origin (0,0) is top-left corner, (0.5, 0.5) is center
type OriginComponent struct {
X, Y float64 // normalized
}
// ID returns a unique identifier for the component type
func (*OriginComponent) ID() akara.ComponentID {
return OriginCID
}
// NewMap returns a new component map for the component type
func (*OriginComponent) NewMap() akara.ComponentMap {
return NewOriginMap()
}
// Origin is a convenient reference to be used as a component identifier
var Origin = (*OriginComponent)(nil) // nolint:gochecknoglobals // global by design
// NewOriginMap creates a new map of entity ID's to Origin
func NewOriginMap() *OriginMap {
cm := &OriginMap{
components: make(map[akara.EID]*OriginComponent),
}
return cm
*akara.BaseComponent
X, Y float64
}
// OriginMap is a map of entity ID's to Origin
type OriginMap struct {
world *akara.World
components map[akara.EID]*OriginComponent
}
// Init initializes the component map with the given world
func (cm *OriginMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*OriginMap) ID() akara.ComponentID {
return OriginCID
}
// NewMap returns a new component map for the component type
func (*OriginMap) NewMap() akara.ComponentMap {
return NewOriginMap()
}
// Add a new OriginComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *OriginMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &OriginComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddOrigin adds a new OriginComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *OriginComponent instead of an akara.Component
func (cm *OriginMap) AddOrigin(id akara.EID) *OriginComponent {
return cm.Add(id).(*OriginComponent)
}
// Get returns the component associated with the given entity id
func (cm *OriginMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetOrigin returns the OriginComponent associated with the given entity id
func (cm *OriginMap) GetOrigin(id akara.EID) (*OriginComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*OriginComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *OriginMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Origin is a convenient reference to be used as a component identifier
var Origin = newOrigin() // nolint:gochecknoglobals // global by design
func newOrigin() akara.Component {
return &OriginComponent{
BaseComponent: akara.NewBaseComponent(OriginCID, newOrigin, newOriginMap),
}
}
func newOriginMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(OriginCID, newOrigin, newOriginMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &OriginMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,91 +13,56 @@ var _ akara.Component = &PositionComponent{}
// static check that PositionMap implements ComponentMap
var _ akara.ComponentMap = &PositionMap{}
// PositionComponent stores an x,y position
// PositionComponent contains an embedded d2vector.Position
type PositionComponent struct {
*akara.BaseComponent
*d2vector.Position
}
// ID returns a unique identifier for the component type
func (*PositionComponent) ID() akara.ComponentID {
return PositionCID
// PositionMap is a map of entity ID's to Position
type PositionMap struct {
*akara.BaseComponentMap
}
// NewMap returns a new component map for the component type
func (*PositionComponent) NewMap() akara.ComponentMap {
return NewPositionMap()
// AddPosition adds a new PositionComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *PositionComponent instead of an akara.Component
func (cm *PositionMap) AddPosition(id akara.EID) *PositionComponent {
pos := cm.Add(id).(*PositionComponent)
p := d2vector.NewPosition(0, 0)
pos.Position = &p
return pos
}
// GetPosition returns the PositionComponent associated with the given entity id
func (cm *PositionMap) GetPosition(id akara.EID) (*PositionComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*PositionComponent), found
}
// Position is a convenient reference to be used as a component identifier
var Position = (*PositionComponent)(nil) // nolint:gochecknoglobals // global by design
var Position = newPosition() // nolint:gochecknoglobals // global by design
func newPosition() akara.Component {
return &PositionComponent{
BaseComponent: akara.NewBaseComponent(PositionCID, newPosition, newPositionMap),
}
}
func newPositionMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(PositionCID, newPosition, newPositionMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
// NewPositionMap creates a new map of entity ID's to position components
func NewPositionMap() *PositionMap {
cm := &PositionMap{
components: make(map[akara.EID]*PositionComponent),
BaseComponentMap: baseMap,
}
return cm
}
// PositionMap is a map of entity ID's to position components
type PositionMap struct {
world *akara.World
components map[akara.EID]*PositionComponent
}
// Init initializes the component map with the given world
func (cm *PositionMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*PositionMap) ID() akara.ComponentID {
return PositionCID
}
// NewMap returns a new component map for the component type
func (*PositionMap) NewMap() akara.ComponentMap {
return NewPositionMap()
}
// Add a new PositionComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *PositionMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
position := d2vector.NewPosition(0, 0)
cm.components[id] = &PositionComponent{Position: &position}
cm.world.UpdateEntity(id)
return cm.components[id]
}
// AddPosition adds a new PositionComponent for the given entity id and returns it.
// If the entity already has a position component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *PositionComponent instead of an akara.Component
func (cm *PositionMap) AddPosition(id akara.EID) *PositionComponent {
return cm.Add(id).(*PositionComponent)
}
// Get returns the component associated with the given entity id
func (cm *PositionMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetPosition returns the position component associated with the given entity id
func (cm *PositionMap) GetPosition(id akara.EID) (*PositionComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *PositionMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}

View File

@ -1,102 +0,0 @@
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
"github.com/gravestench/akara"
)
// static check that StaticPositionComponent implements Component
var _ akara.Component = &StaticPositionComponent{}
// static check that StaticPositionMap implements ComponentMap
var _ akara.ComponentMap = &StaticPositionMap{}
// StaticPositionComponent is a component that contains an embedded position struct.
// StaticPosition is used for positions that do not change with camera position (like ui overlay)
type StaticPositionComponent struct {
*d2vector.Position
}
// ID returns a unique identifier for the component type
func (*StaticPositionComponent) ID() akara.ComponentID {
return StaticPositionCID
}
// NewMap returns a new component map for the component type
func (*StaticPositionComponent) NewMap() akara.ComponentMap {
return NewStaticPositionMap()
}
// StaticPosition is a convenient reference to be used as a component identifier
var StaticPosition = (*StaticPositionComponent)(nil) // nolint:gochecknoglobals // global by design
// NewStaticPositionMap creates a new map of entity ID's to StaticPosition
func NewStaticPositionMap() *StaticPositionMap {
cm := &StaticPositionMap{
components: make(map[akara.EID]*StaticPositionComponent),
}
return cm
}
// StaticPositionMap is a map of entity ID's to StaticPosition
type StaticPositionMap struct {
world *akara.World
components map[akara.EID]*StaticPositionComponent
}
// Init initializes the component map with the given world
func (cm *StaticPositionMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*StaticPositionMap) ID() akara.ComponentID {
return StaticPositionCID
}
// NewMap returns a new component map for the component type
func (*StaticPositionMap) NewMap() akara.ComponentMap {
return NewStaticPositionMap()
}
// Add a new StaticPositionComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *StaticPositionMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
position := d2vector.NewPosition(0, 0)
cm.components[id] = &StaticPositionComponent{Position: &position}
cm.world.UpdateEntity(id)
return cm.components[id]
}
// AddStaticPosition adds a new StaticPositionComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *StaticPositionComponent instead of an akara.Component
func (cm *StaticPositionMap) AddStaticPosition(id akara.EID) *StaticPositionComponent {
return cm.Add(id).(*StaticPositionComponent)
}
// Get returns the component associated with the given entity id
func (cm *StaticPositionMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetStaticPosition returns the StaticPositionComponent associated with the given entity id
func (cm *StaticPositionMap) GetStaticPosition(id akara.EID) (*StaticPositionComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *StaticPositionMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -13,88 +14,48 @@ var _ akara.ComponentMap = &PriorityMap{}
// PriorityComponent is a component that is used to add a priority value.
// This can generally be used for sorting entities when order matters.
type PriorityComponent struct {
*akara.BaseComponent
Priority int
}
// ID returns a unique identifier for the component type
func (*PriorityComponent) ID() akara.ComponentID {
return PriorityCID
}
// NewMap returns a new component map for the component type
func (*PriorityComponent) NewMap() akara.ComponentMap {
return NewPriorityMap()
}
// Priority is a convenient reference to be used as a component identifier
var Priority = (*PriorityComponent)(nil) // nolint:gochecknoglobals // global by design
// NewPriorityMap creates a new map of entity ID's to Priority
func NewPriorityMap() *PriorityMap {
cm := &PriorityMap{
components: make(map[akara.EID]*PriorityComponent),
}
return cm
}
// PriorityMap is a map of entity ID's to Priority
type PriorityMap struct {
world *akara.World
components map[akara.EID]*PriorityComponent
}
// Init initializes the component map with the given world
func (cm *PriorityMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*PriorityMap) ID() akara.ComponentID {
return PriorityCID
}
// NewMap returns a new component map for the component type
func (*PriorityMap) NewMap() akara.ComponentMap {
return NewPriorityMap()
}
// Add a new PriorityComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *PriorityMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &PriorityComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddPriority adds a new PriorityComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *PriorityComponent instead of an akara.Component
func (cm *PriorityMap) AddPriority(id akara.EID) *PriorityComponent {
return cm.Add(id).(*PriorityComponent)
}
// Get returns the component associated with the given entity id
func (cm *PriorityMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetPriority returns the PriorityComponent associated with the given entity id
func (cm *PriorityMap) GetPriority(id akara.EID) (*PriorityComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*PriorityComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *PriorityMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Priority is a convenient reference to be used as a component identifier
var Priority = newPriority() // nolint:gochecknoglobals // global by design
func newPriority() akara.Component {
return &PriorityComponent{
BaseComponent: akara.NewBaseComponent(PriorityCID, newPriority, newPriorityMap),
}
}
func newPriorityMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(PriorityCID, newPriority, newPriorityMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &PriorityMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,98 +0,0 @@
package d2components
import (
"github.com/gravestench/akara"
)
// static check that RenderCullComponent implements Component
var _ akara.Component = &RenderCullComponent{}
// static check that RenderCullMap implements ComponentMap
var _ akara.ComponentMap = &RenderCullMap{}
// RenderCullComponent is an empty component used for
// tagging entities that should not be rendered
type RenderCullComponent struct{}
// ID returns a unique identifier for the component type
func (*RenderCullComponent) ID() akara.ComponentID {
return RenderCullCID
}
// NewMap returns a new component map for the component type
func (*RenderCullComponent) NewMap() akara.ComponentMap {
return NewRenderCullMap()
}
// RenderCull is a convenient reference to be used as a component identifier
var RenderCull = (*RenderCullComponent)(nil) // nolint:gochecknoglobals // global by design
// NewRenderCullMap creates a new map of entity ID's to RenderCull
func NewRenderCullMap() *RenderCullMap {
cm := &RenderCullMap{
components: make(map[akara.EID]*RenderCullComponent),
}
return cm
}
// RenderCullMap is a map of entity ID's to RenderCull
type RenderCullMap struct {
world *akara.World
components map[akara.EID]*RenderCullComponent
}
// Init initializes the component map with the given world
func (cm *RenderCullMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*RenderCullMap) ID() akara.ComponentID {
return RenderCullCID
}
// NewMap returns a new component map for the component type
func (*RenderCullMap) NewMap() akara.ComponentMap {
return NewRenderCullMap()
}
// Add a new RenderCullComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *RenderCullMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &RenderCullComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
}
// AddRenderCull adds a new RenderCullComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *RenderCullComponent instead of an akara.Component
func (cm *RenderCullMap) AddRenderCull(id akara.EID) *RenderCullComponent {
return cm.Add(id).(*RenderCullComponent)
}
// Get returns the component associated with the given entity id
func (cm *RenderCullMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetRenderCull returns the RenderCullComponent associated with the given entity id
func (cm *RenderCullMap) GetRenderCull(id akara.EID) (*RenderCullComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *RenderCullMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}

View File

@ -1,100 +0,0 @@
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/gravestench/akara"
)
// static check that SurfaceComponent implements Component
var _ akara.Component = &SurfaceComponent{}
// static check that SurfaceMap implements ComponentMap
var _ akara.ComponentMap = &SurfaceMap{}
// SurfaceComponent is a component that contains an embedded surface interface
type SurfaceComponent struct {
d2interface.Surface
}
// ID returns a unique identifier for the component type
func (*SurfaceComponent) ID() akara.ComponentID {
return SurfaceCID
}
// NewMap returns a new component map for the component type
func (*SurfaceComponent) NewMap() akara.ComponentMap {
return NewSurfaceMap()
}
// Surface is a convenient reference to be used as a component identifier
var Surface = (*SurfaceComponent)(nil) // nolint:gochecknoglobals // global by design
// NewSurfaceMap creates a new map of entity ID's to Surface
func NewSurfaceMap() *SurfaceMap {
cm := &SurfaceMap{
components: make(map[akara.EID]*SurfaceComponent),
}
return cm
}
// SurfaceMap is a map of entity ID's to Surface
type SurfaceMap struct {
world *akara.World
components map[akara.EID]*SurfaceComponent
}
// Init initializes the component map with the given world
func (cm *SurfaceMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*SurfaceMap) ID() akara.ComponentID {
return SurfaceCID
}
// NewMap returns a new component map for the component type
func (*SurfaceMap) NewMap() akara.ComponentMap {
return NewSurfaceMap()
}
// Add a new SurfaceComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *SurfaceMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &SurfaceComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
}
// AddSurface adds a new SurfaceComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *SurfaceComponent instead of an akara.Component
func (cm *SurfaceMap) AddSurface(id akara.EID) *SurfaceComponent {
return cm.Add(id).(*SurfaceComponent)
}
// Get returns the component associated with the given entity id
func (cm *SurfaceMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetSurface returns the SurfaceComponent associated with the given entity id
func (cm *SurfaceMap) GetSurface(id akara.EID) (*SurfaceComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *SurfaceMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}

View File

@ -0,0 +1,62 @@
//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 RenderableComponent implements Component
var _ akara.Component = &RenderableComponent{}
// static check that RenderableMap implements ComponentMap
var _ akara.ComponentMap = &RenderableMap{}
// RenderableComponent is a component that contains an embedded surface interface, which is used for rendering
type RenderableComponent struct {
*akara.BaseComponent
d2interface.Surface
}
// RenderableMap is a map of entity ID's to Surface
type RenderableMap struct {
*akara.BaseComponentMap
}
// AddRenderable adds a new RenderableComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *RenderableComponent instead of an akara.Component
func (cm *RenderableMap) AddRenderable(id akara.EID) *RenderableComponent {
return cm.Add(id).(*RenderableComponent)
}
// GetRenderable returns the RenderableComponent associated with the given entity id
func (cm *RenderableMap) GetRenderable(id akara.EID) (*RenderableComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*RenderableComponent), found
}
// Surface is a convenient reference to be used as a component identifier
var Surface = newRenderable() // nolint:gochecknoglobals // global by design
func newRenderable() akara.Component {
return &RenderableComponent{
BaseComponent: akara.NewBaseComponent(RenderableCID, newRenderable, newRenderableMap),
}
}
func newRenderableMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(RenderableCID, newRenderable, newRenderableMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &RenderableMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
)
// static check that ScaleComponent implements Component
@ -11,92 +13,54 @@ var _ akara.Component = &ScaleComponent{}
// static check that ScaleMap implements ComponentMap
var _ akara.ComponentMap = &ScaleMap{}
// ScaleComponent is a component that contains scale for x and y axis
// ScaleComponent represents an entities x,y axis scale as a vector
type ScaleComponent struct {
*akara.BaseComponent
*d2vector.Vector
}
// ID returns a unique identifier for the component type
func (*ScaleComponent) ID() akara.ComponentID {
return ScaleCID
}
// NewMap returns a new component map for the component type
func (*ScaleComponent) NewMap() akara.ComponentMap {
return NewScaleMap()
}
// Scale is a convenient reference to be used as a component identifier
var Scale = (*ScaleComponent)(nil) // nolint:gochecknoglobals // global by design
// NewScaleMap creates a new map of entity ID's to Scale
func NewScaleMap() *ScaleMap {
cm := &ScaleMap{
components: make(map[akara.EID]*ScaleComponent),
}
return cm
}
// ScaleMap is a map of entity ID's to Scale
type ScaleMap struct {
world *akara.World
components map[akara.EID]*ScaleComponent
}
// Init initializes the component map with the given world
func (cm *ScaleMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*ScaleMap) ID() akara.ComponentID {
return ScaleCID
}
// NewMap returns a new component map for the component type
func (*ScaleMap) NewMap() akara.ComponentMap {
return NewScaleMap()
}
// Add a new ScaleComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *ScaleMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &ScaleComponent{
Vector: d2vector.NewVector(1, 1),
}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddScale adds a new ScaleComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *ScaleComponent instead of an akara.Component
func (cm *ScaleMap) AddScale(id akara.EID) *ScaleComponent {
return cm.Add(id).(*ScaleComponent)
}
c := cm.Add(id).(*ScaleComponent)
// Get returns the component associated with the given entity id
func (cm *ScaleMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
c.Vector = d2vector.NewVector(1, 1)
return c
}
// GetScale returns the ScaleComponent associated with the given entity id
func (cm *ScaleMap) GetScale(id akara.EID) (*ScaleComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*ScaleComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *ScaleMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Scale is a convenient reference to be used as a component identifier
var Scale = newScale() // nolint:gochecknoglobals // global by design
func newScale() akara.Component {
return &ScaleComponent{
BaseComponent: akara.NewBaseComponent(ScaleCID, newScale, newScaleMap),
}
}
func newScaleMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(ScaleCID, newScale, newScaleMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &ScaleMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,97 +0,0 @@
package d2components
import (
"github.com/gravestench/akara"
)
// static check that MainViewportComponent implements Component
var _ akara.Component = &MainViewportComponent{}
// static check that MainViewportMap implements ComponentMap
var _ akara.ComponentMap = &MainViewportMap{}
// MainViewportComponent is a component that is used to tag the main viewport of a scene
type MainViewportComponent struct {}
// ID returns a unique identifier for the component type
func (*MainViewportComponent) ID() akara.ComponentID {
return MainViewportCID
}
// NewMap returns a new component map for the component type
func (*MainViewportComponent) NewMap() akara.ComponentMap {
return NewMainViewportMap()
}
// MainViewport is a convenient reference to be used as a component identifier
var MainViewport = (*MainViewportComponent)(nil) // nolint:gochecknoglobals // global by design
// NewMainViewportMap creates a new map of entity ID's to MainViewport
func NewMainViewportMap() *MainViewportMap {
cm := &MainViewportMap{
components: make(map[akara.EID]*MainViewportComponent),
}
return cm
}
// MainViewportMap is a map of entity ID's to MainViewport
type MainViewportMap struct {
world *akara.World
components map[akara.EID]*MainViewportComponent
}
// Init initializes the component map with the given world
func (cm *MainViewportMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*MainViewportMap) ID() akara.ComponentID {
return MainViewportCID
}
// NewMap returns a new component map for the component type
func (*MainViewportMap) NewMap() akara.ComponentMap {
return NewMainViewportMap()
}
// Add a new MainViewportComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *MainViewportMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &MainViewportComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
}
// AddMainViewport adds a new MainViewportComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *MainViewportComponent instead of an akara.Component
func (cm *MainViewportMap) AddMainViewport(id akara.EID) *MainViewportComponent {
return cm.Add(id).(*MainViewportComponent)
}
// Get returns the component associated with the given entity id
func (cm *MainViewportMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetMainViewport returns the MainViewportComponent associated with the given entity id
func (cm *MainViewportMap) GetMainViewport(id akara.EID) (*MainViewportComponent, bool) {
entry, found := cm.components[id]
return entry, found
}
// Remove a component for the given entity id, return the component.
func (cm *MainViewportMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
}

View File

@ -1,7 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
)
// static check that SizeComponent implements Component
@ -10,90 +13,54 @@ var _ akara.Component = &SizeComponent{}
// static check that SizeMap implements ComponentMap
var _ akara.ComponentMap = &SizeMap{}
// SizeComponent is a component that contains a width and height
// SizeComponent represents an entities width and height as a vector
type SizeComponent struct {
Width, Height uint
}
// ID returns a unique identifier for the component type
func (*SizeComponent) ID() akara.ComponentID {
return SizeCID
}
// NewMap returns a new component map for the component type
func (*SizeComponent) NewMap() akara.ComponentMap {
return NewSizeMap()
}
// Size is a convenient reference to be used as a component identifier
var Size = (*SizeComponent)(nil) // nolint:gochecknoglobals // global by design
// NewSizeMap creates a new map of entity ID's to Size
func NewSizeMap() *SizeMap {
cm := &SizeMap{
components: make(map[akara.EID]*SizeComponent),
}
return cm
*akara.BaseComponent
*d2vector.Vector
}
// SizeMap is a map of entity ID's to Size
type SizeMap struct {
world *akara.World
components map[akara.EID]*SizeComponent
}
// Init initializes the component map with the given world
func (cm *SizeMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*SizeMap) ID() akara.ComponentID {
return SizeCID
}
// NewMap returns a new component map for the component type
func (*SizeMap) NewMap() akara.ComponentMap {
return NewSizeMap()
}
// Add a new SizeComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *SizeMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &SizeComponent{}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddSize adds a new SizeComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *SizeComponent instead of an akara.Component
func (cm *SizeMap) AddSize(id akara.EID) *SizeComponent {
return cm.Add(id).(*SizeComponent)
}
c := cm.Add(id).(*SizeComponent)
// Get returns the component associated with the given entity id
func (cm *SizeMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
c.Vector = d2vector.NewVector(1, 1)
return c
}
// GetSize returns the SizeComponent associated with the given entity id
func (cm *SizeMap) GetSize(id akara.EID) (*SizeComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*SizeComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *SizeMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Size is a convenient reference to be used as a component identifier
var Size = newSize() // nolint:gochecknoglobals // global by design
func newSize() akara.Component {
return &SizeComponent{
BaseComponent: akara.NewBaseComponent(SizeCID, newSize, newSizeMap),
}
}
func newSizeMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(SizeCID, newSize, newSizeMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &SizeMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -12,91 +13,54 @@ var _ akara.Component = &VelocityComponent{}
// static check that VelocityMap implements ComponentMap
var _ akara.ComponentMap = &VelocityMap{}
// VelocityComponent stores the velocity as a vec2
// VelocityComponent contains an embedded velocity as a vector
type VelocityComponent struct {
*akara.BaseComponent
*d2vector.Vector
}
// ID returns a unique identifier for the component type
func (*VelocityComponent) ID() akara.ComponentID {
return VelocityCID
}
// NewMap returns a new component map for the component type
func (*VelocityComponent) NewMap() akara.ComponentMap {
return NewVelocityMap()
}
// Velocity is a convenient reference to be used as a component identifier
var Velocity = (*VelocityComponent)(nil) // nolint:gochecknoglobals // global by design
// NewVelocityMap creates a new map of entity ID's to velocity components
func NewVelocityMap() *VelocityMap {
return &VelocityMap{
components: make(map[akara.EID]*VelocityComponent),
}
}
// VelocityMap is a map of entity ID's to velocity components
// VelocityMap is a map of entity ID's to Velocity
type VelocityMap struct {
world *akara.World
components map[akara.EID]*VelocityComponent
}
// Init initializes the component map with the given world
func (cm *VelocityMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*VelocityMap) ID() akara.ComponentID {
return VelocityCID
}
// NewMap returns a new component map for the component type
func (*VelocityMap) NewMap() akara.ComponentMap {
return NewVelocityMap()
}
// Add a new VelocityComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *VelocityMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
v := d2vector.NewVector(0, 0)
com := &VelocityComponent{Vector: v}
cm.components[id] = com
cm.world.UpdateEntity(id)
return com
*akara.BaseComponentMap
}
// AddVelocity adds a new VelocityComponent for the given entity id and returns it.
// If the entity already has a component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *VelocityComponent instead of an akara.Component
func (cm *VelocityMap) AddVelocity(id akara.EID) *VelocityComponent {
return cm.Add(id).(*VelocityComponent)
c := cm.Add(id).(*VelocityComponent)
c.Vector = d2vector.NewVector(0, 0)
return c
}
// Get returns the component associated with the given entity id
func (cm *VelocityMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
}
// GetVelocity returns the velocity component associated with the given entity id.
// This is used to return a *VelocityComponent, as opposed to an akara.Component
// GetVelocity returns the VelocityComponent associated with the given entity id
func (cm *VelocityMap) GetVelocity(id akara.EID) (*VelocityComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*VelocityComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *VelocityMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Velocity is a convenient reference to be used as a component identifier
var Velocity = newVelocity() // nolint:gochecknoglobals // global by design
func newVelocity() akara.Component {
return &VelocityComponent{
BaseComponent: akara.NewBaseComponent(VelocityCID, newVelocity, newVelocityMap),
}
}
func newVelocityMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(VelocityCID, newVelocity, newVelocityMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &VelocityMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,8 +1,10 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom"
"github.com/gravestench/akara"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2geom"
)
// static check that ViewportComponent implements Component
@ -11,92 +13,62 @@ var _ akara.Component = &ViewportComponent{}
// static check that ViewportMap implements ComponentMap
var _ akara.ComponentMap = &ViewportMap{}
// ViewportComponent is a component that contains a file Type
// ViewportComponent represents the size and position of a scene viewport. This is used
// to control where on screen a viewport is rendered.
type ViewportComponent struct {
*akara.BaseComponent
*d2geom.Rectangle
}
// ID returns a unique identifier for the component type
func (*ViewportComponent) ID() akara.ComponentID {
return ViewportCID
}
// NewMap returns a new component map for the component type
func (*ViewportComponent) NewMap() akara.ComponentMap {
return NewViewportMap()
}
// Viewport is a convenient reference to be used as a component identifier
var Viewport = (*ViewportComponent)(nil) // nolint:gochecknoglobals // global by design
// NewViewportMap creates a new map of entity ID's to Viewport
func NewViewportMap() *ViewportMap {
cm := &ViewportMap{
components: make(map[akara.EID]*ViewportComponent),
}
return cm
}
// ViewportMap is a map of entity ID's to Viewport
type ViewportMap struct {
world *akara.World
components map[akara.EID]*ViewportComponent
}
// Init initializes the component map with the given world
func (cm *ViewportMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*ViewportMap) ID() akara.ComponentID {
return ViewportCID
}
// NewMap returns a new component map for the component type
func (*ViewportMap) NewMap() akara.ComponentMap {
return NewViewportMap()
}
// Add a new ViewportComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *ViewportMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &ViewportComponent{
Rectangle: &d2geom.Rectangle{},
}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddViewport adds a new ViewportComponent for the given entity id and returns it.
// If the entity already has a file type component, just return that one.
// this is a convenience method for the generic Add method, as it returns a
// *ViewportComponent instead of an akara.Component
func (cm *ViewportMap) AddViewport(id akara.EID) *ViewportComponent {
return cm.Add(id).(*ViewportComponent)
}
c := cm.Add(id).(*ViewportComponent)
// Get returns the component associated with the given entity id
func (cm *ViewportMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
const defaultWidth, defaultHeight = 800, 600
c.Rectangle = &d2geom.Rectangle{
Left: 0,
Top: 0,
Width: defaultWidth,
Height: defaultHeight,
}
return c
}
// GetViewport returns the ViewportComponent associated with the given entity id
func (cm *ViewportMap) GetViewport(id akara.EID) (*ViewportComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*ViewportComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *ViewportMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// Viewport is a convenient reference to be used as a component identifier
var Viewport = newViewport() // nolint:gochecknoglobals // global by design
func newViewport() akara.Component {
return &ViewportComponent{
BaseComponent: akara.NewBaseComponent(ViewportCID, newViewport, newViewportMap),
}
}
func newViewportMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(ViewportCID, newViewport, newViewportMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &ViewportMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -1,3 +1,4 @@
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
package d2components
import (
@ -13,90 +14,52 @@ var _ akara.ComponentMap = &ViewportFilterMap{}
// ViewportFilterComponent is a component that contains a bitset that denotes which viewport
// the entity will be rendered.
type ViewportFilterComponent struct {
*akara.BaseComponent
*akara.BitSet
}
// ID returns a unique identifier for the component type
func (*ViewportFilterComponent) ID() akara.ComponentID {
return ViewportFilterCID
}
// NewMap returns a new component map for the component type
func (*ViewportFilterComponent) NewMap() akara.ComponentMap {
return NewViewportFilterMap()
}
// ViewportFilter is a convenient reference to be used as a component identifier
var ViewportFilter = (*ViewportFilterComponent)(nil) // nolint:gochecknoglobals // global by design
// NewViewportFilterMap creates a new map of entity ID's to ViewportFilter
func NewViewportFilterMap() *ViewportFilterMap {
cm := &ViewportFilterMap{
components: make(map[akara.EID]*ViewportFilterComponent),
}
return cm
}
// ViewportFilterMap is a map of entity ID's to ViewportFilter
type ViewportFilterMap struct {
world *akara.World
components map[akara.EID]*ViewportFilterComponent
}
// Init initializes the component map with the given world
func (cm *ViewportFilterMap) Init(world *akara.World) {
cm.world = world
}
// ID returns a unique identifier for the component type
func (*ViewportFilterMap) ID() akara.ComponentID {
return ViewportFilterCID
}
// NewMap returns a new component map for the component type
func (*ViewportFilterMap) NewMap() akara.ComponentMap {
return NewViewportFilterMap()
}
// Add a new ViewportFilterComponent for the given entity id, return that component.
// If the entity already has a component, just return that one.
func (cm *ViewportFilterMap) Add(id akara.EID) akara.Component {
if com, has := cm.components[id]; has {
return com
}
cm.components[id] = &ViewportFilterComponent{
BitSet: akara.NewBitSet(),
}
cm.world.UpdateEntity(id)
return cm.components[id]
*akara.BaseComponentMap
}
// AddViewportFilter adds a new ViewportFilterComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *ViewportFilterComponent instead of an akara.Component
func (cm *ViewportFilterMap) AddViewportFilter(id akara.EID) *ViewportFilterComponent {
return cm.Add(id).(*ViewportFilterComponent)
}
c := cm.Add(id).(*ViewportFilterComponent)
// Get returns the component associated with the given entity id
func (cm *ViewportFilterMap) Get(id akara.EID) (akara.Component, bool) {
entry, found := cm.components[id]
return entry, found
c.BitSet = akara.NewBitSet(0)
return c
}
// GetViewportFilter returns the ViewportFilterComponent associated with the given entity id
func (cm *ViewportFilterMap) GetViewportFilter(id akara.EID) (*ViewportFilterComponent, bool) {
entry, found := cm.components[id]
return entry, found
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*ViewportFilterComponent), found
}
// Remove a component for the given entity id, return the component.
func (cm *ViewportFilterMap) Remove(id akara.EID) {
delete(cm.components, id)
cm.world.UpdateEntity(id)
// ViewportFilter is a convenient reference to be used as a component identifier
var ViewportFilter = newViewportFilter() // nolint:gochecknoglobals // global by design
func newViewportFilter() akara.Component {
return &ViewportFilterComponent{
BaseComponent: akara.NewBaseComponent(ViewportFilterCID, newViewportFilter, newViewportFilterMap),
}
}
func newViewportFilterMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(ViewportFilterCID, newViewportFilter, newViewportFilterMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &ViewportFilterMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -0,0 +1,58 @@
package d2components
import (
"github.com/gravestench/akara"
)
// static check that MainViewportComponent implements Component
var _ akara.Component = &MainViewportComponent{}
// static check that MainViewportMap implements ComponentMap
var _ akara.ComponentMap = &MainViewportMap{}
// MainViewportComponent is used to flag viewports as the main viewport of a scene
type MainViewportComponent struct {
*akara.BaseComponent
}
// MainViewportMap is a map of entity ID's to MainViewport
type MainViewportMap struct {
*akara.BaseComponentMap
}
// AddMainViewport adds a new MainViewportComponent for the given entity id and returns it.
// this is a convenience method for the generic Add method, as it returns a
// *MainViewportComponent instead of an akara.Component
func (cm *MainViewportMap) AddMainViewport(id akara.EID) *MainViewportComponent {
return cm.Add(id).(*MainViewportComponent)
}
// GetMainViewport returns the MainViewportComponent associated with the given entity id
func (cm *MainViewportMap) GetMainViewport(id akara.EID) (*MainViewportComponent, bool) {
entry, found := cm.Get(id)
if entry == nil {
return nil, false
}
return entry.(*MainViewportComponent), found
}
// MainViewport is a convenient reference to be used as a component identifier
var MainViewport = newMainViewport() // nolint:gochecknoglobals // global by design
func newMainViewport() akara.Component {
return &MainViewportComponent{
BaseComponent: akara.NewBaseComponent(MainViewportCID, newMainViewport, newMainViewportMap),
}
}
func newMainViewportMap() akara.ComponentMap {
baseComponent := akara.NewBaseComponent(MainViewportCID, newMainViewport, newMainViewportMap)
baseMap := akara.NewBaseComponentMap(baseComponent)
cm := &MainViewportMap{
BaseComponentMap: baseMap,
}
return cm
}

View File

@ -54,7 +54,7 @@ type RenderSystem struct {
*d2components.GameConfigMap
*d2components.ViewportMap
*d2components.MainViewportMap
*d2components.SurfaceMap
*d2components.RenderableMap
lastUpdate time.Time
gameLoopInitDelay time.Duration // there is a race condition, this is a hack
}
@ -73,7 +73,7 @@ func (m *RenderSystem) Init(_ *akara.World) {
m.GameConfigMap = m.InjectMap(d2components.GameConfig).(*d2components.GameConfigMap)
m.ViewportMap = m.InjectMap(d2components.Viewport).(*d2components.ViewportMap)
m.MainViewportMap = m.InjectMap(d2components.MainViewport).(*d2components.MainViewportMap)
m.SurfaceMap = m.InjectMap(d2components.Surface).(*d2components.SurfaceMap)
m.RenderableMap = m.InjectMap(d2components.Surface).(*d2components.RenderableMap)
}
// Update will initialize the renderer, start the game loop, and
@ -156,7 +156,7 @@ func (m *RenderSystem) render(screen d2interface.Surface) error {
return errors.New("main viewport not found")
}
sfc, found := m.GetSurface(id)
sfc, found := m.GetRenderable(id)
if !found {
return errors.New("main viewport doesn't have a surface")
}

View File

@ -56,7 +56,7 @@ type BaseScene struct {
*d2components.ViewportMap
*d2components.ViewportFilterMap
*d2components.CameraMap
*d2components.SurfaceMap
*d2components.RenderableMap
*d2components.PositionMap
*d2components.ScaleMap
*d2components.AnimationMap
@ -128,7 +128,7 @@ func (s *BaseScene) injectComponentMaps() {
s.ViewportMap = s.World.InjectMap(d2components.Viewport).(*d2components.ViewportMap)
s.ViewportFilterMap = s.World.InjectMap(d2components.ViewportFilter).(*d2components.ViewportFilterMap)
s.CameraMap = s.World.InjectMap(d2components.Camera).(*d2components.CameraMap)
s.SurfaceMap = s.World.InjectMap(d2components.Surface).(*d2components.SurfaceMap)
s.RenderableMap = s.World.InjectMap(d2components.Surface).(*d2components.RenderableMap)
s.PositionMap = s.World.InjectMap(d2components.Position).(*d2components.PositionMap)
s.ScaleMap = s.World.InjectMap(d2components.Scale).(*d2components.ScaleMap)
s.AnimationMap = s.World.InjectMap(d2components.Animation).(*d2components.AnimationMap)
@ -144,7 +144,7 @@ func (s *BaseScene) createDefaultViewport() {
camera.Height = 600
camera.Zoom = 1
s.AddSurface(viewportID).Surface = s.systems.renderer.NewSurface(camera.Width, camera.Height)
s.AddRenderable(viewportID).Surface = s.systems.renderer.NewSurface(camera.Width, camera.Height)
s.AddMainViewport(viewportID)
s.Viewports = append(s.Viewports, viewportID)
@ -231,7 +231,7 @@ func (s *BaseScene) renderViewport(idx int, objects []akara.EID) {
return
}
sfc, found := s.GetSurface(id)
sfc, found := s.GetRenderable(id)
if !found {
return
}
@ -254,7 +254,7 @@ func (s *BaseScene) renderViewport(idx int, objects []akara.EID) {
}
func (s *BaseScene) renderObject(target d2interface.Surface, id akara.EID) {
sfc, found := s.GetSurface(id)
sfc, found := s.GetRenderable(id)
if !found {
return
}

View File

@ -51,7 +51,7 @@ type SpriteFactory struct {
*d2components.DccMap
*d2components.PaletteMap
*d2components.AnimationMap
*d2components.SurfaceMap
*d2components.RenderableMap
loadQueue spriteLoadQueue
spritesToRender *akara.Subscription
}
@ -70,7 +70,7 @@ func (t *SpriteFactory) Init(world *akara.World) {
t.DccMap = t.InjectMap(d2components.Dcc).(*d2components.DccMap)
t.PaletteMap = t.InjectMap(d2components.Palette).(*d2components.PaletteMap)
t.AnimationMap = t.InjectMap(d2components.Animation).(*d2components.AnimationMap)
t.SurfaceMap = t.InjectMap(d2components.Surface).(*d2components.SurfaceMap)
t.RenderableMap = t.InjectMap(d2components.Surface).(*d2components.RenderableMap)
}
// Update processes the load queue which attempting to create animations, as well as
@ -169,7 +169,7 @@ func (t *SpriteFactory) tryRenderingSprite(eid akara.EID) {
sfc := anim.GetCurrentFrameSurface()
t.AddSurface(eid).Surface = sfc
t.AddRenderable(eid).Surface = sfc
}
func (t *SpriteFactory) createDc6Animation(

2
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265 // indirect
github.com/go-restruct/restruct v1.2.0-alpha
github.com/google/uuid v1.1.2
github.com/gravestench/akara v0.0.0-20201119221449-924b47999403
github.com/gravestench/akara v0.0.0-20201122210148-a1ee8ea83994
github.com/hajimehoshi/ebiten/v2 v2.0.0
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.5.0

2
go.sum
View File

@ -21,6 +21,8 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gravestench/akara v0.0.0-20201119221449-924b47999403 h1:hoCEhoSD+4Hvg3xdbfbVleJXhyHqP/1jUa1QqexE1UQ=
github.com/gravestench/akara v0.0.0-20201119221449-924b47999403/go.mod h1:fTeda1SogMg5Lkd4lXMEd/Pk/a5/gQuLGaAI2rn1PBQ=
github.com/gravestench/akara v0.0.0-20201122210148-a1ee8ea83994 h1:Wp+4kZ0Pkap2ueAkTrE22rk++3VZE8TsU1bewpnzmsM=
github.com/gravestench/akara v0.0.0-20201122210148-a1ee8ea83994/go.mod h1:fTeda1SogMg5Lkd4lXMEd/Pk/a5/gQuLGaAI2rn1PBQ=
github.com/hajimehoshi/bitmapfont/v2 v2.1.0/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
github.com/hajimehoshi/ebiten/v2 v2.0.0 h1:G8mhkKFtnDPPZ/ChaGWx4Bm0NusYEcafGCJ8QLxEaYs=
github.com/hajimehoshi/ebiten/v2 v2.0.0/go.mod h1:hpZZQ/kk8DZqft7QsQ5hZLRQXHSZPdKnaa0tcJ3CZFE=