1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 00:07:17 -04:00
OpenDiablo2/d2core/d2input/d2input.go
dk 62b8a610c0
D2input abstraction (#532)
* abstract d2input manager/service/events/keys/buttons to interface

* abstract d2input manager/service/events/keys/buttons to interface

* fixing lint error
2020-07-03 15:09:16 -04:00

48 lines
1.5 KiB
Go

package d2input
import (
"errors"
"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
ErrHasReg = errors.New("input system already has provided handler")
// ErrNotReg shows the input system has no registered handler
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 d2interface.Priority) error {
return singleton.BindHandlerWithPriority(handler, priority)
}
// BindHandler adds an event handler
func BindHandler(handler d2interface.InputEventHandler) error {
return BindHandlerWithPriority(handler, d2interface.PriorityDefault)
}
// UnbindHandler removes a previously bound event handler
func UnbindHandler(handler d2interface.InputEventHandler) error {
return singleton.UnbindHandler(handler)
}