1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-06 18:27:20 -05:00
OpenDiablo2/d2core/d2input/d2input.go

49 lines
1.5 KiB
Go
Raw Normal View History

package d2input
import (
"errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
ebiten_input "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input/ebiten"
)
var (
// ErrHasReg shows the input system already has a registered handler
2020-02-09 14:12:04 -05:00
ErrHasReg = errors.New("input system already has provided handler")
// ErrNotReg shows the input system has no registered handler
2020-02-09 14:12:04 -05:00
ErrNotReg = errors.New("input system does not have provided handler")
)
var singleton *inputManager // TODO remove this singleton
// Initialize creates a single global input manager based on a specific input service
func Create() (d2interface.InputManager, error) {
singleton = &inputManager{
inputService: ebiten_input.InputService{},
}
return singleton, nil
}
// Advance moves the input manager with the elapsed number of seconds.
func Advance(elapsed, current float64) error {
return singleton.Advance(elapsed, current)
}
// BindHandlerWithPriority adds an event handler with a specific call priority
func BindHandlerWithPriority(handler d2interface.InputEventHandler, priority d2enum.Priority) error {
return singleton.BindHandlerWithPriority(handler, priority)
}
// BindHandler adds an event handler
func BindHandler(handler d2interface.InputEventHandler) error {
return BindHandlerWithPriority(handler, d2enum.PriorityDefault)
}
// UnbindHandler removes a previously bound event handler
func UnbindHandler(handler d2interface.InputEventHandler) error {
return singleton.UnbindHandler(handler)
}