1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-13 12:06:31 -05:00
OpenDiablo2/d2core/d2components/viewport_main.go
gravestench 3f5d2c0938 major refactor of akara ecs
* component ID's are dynamically allocated now
* removed `akara.BaseComponent` member from components
* component declarations drastically reduced
2020-12-07 12:44:11 -08:00

38 lines
1.2 KiB
Go

package d2components
import (
"github.com/gravestench/akara"
)
// static check that MainViewport implements Component
var _ akara.Component = &MainViewport{}
// MainViewport is used to flag viewports as the main viewport of a scene
type MainViewport struct{}
// New returns a new MainViewport instance. It is always a nil instance.
func (*MainViewport) New() akara.Component {
return (*MainViewport)(nil)
}
// MainViewportFactory is a wrapper for the generic component factory that returns MainViewport component instances.
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a MainViewport.
type MainViewportFactory struct {
MainViewport *akara.ComponentFactory
}
// AddMainViewport adds a MainViewport component to the given entity and returns it
func (m *MainViewportFactory) AddMainViewport(id akara.EID) *MainViewport {
return m.MainViewport.Add(id).(*MainViewport)
}
// GetMainViewport returns the MainViewport component for the given entity, and a bool for whether or not it exists
func (m *MainViewportFactory) GetMainViewport(id akara.EID) (*MainViewport, bool) {
component, found := m.MainViewport.Get(id)
if !found {
return nil, found
}
return component.(*MainViewport), found
}