2020-01-25 23:28:21 -05:00
|
|
|
package d2input
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-07-06 21:26:08 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-07-03 15:09:16 -04:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
|
|
|
|
ebiten_input "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input/ebiten"
|
2020-01-25 23:28:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-07-01 14:03:40 -04:00
|
|
|
// 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")
|
2020-07-01 14:03:40 -04:00
|
|
|
// 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")
|
2020-01-25 23:28:21 -05:00
|
|
|
)
|
|
|
|
|
2020-07-03 15:09:16 -04:00
|
|
|
var singleton *inputManager // TODO remove this singleton
|
2020-01-25 23:28:21 -05:00
|
|
|
|
2020-07-01 14:03:40 -04:00
|
|
|
// Initialize creates a single global input manager based on a specific input service
|
2020-07-03 15:09:16 -04:00
|
|
|
func Create() (d2interface.InputManager, error) {
|
|
|
|
singleton = &inputManager{
|
|
|
|
inputService: ebiten_input.InputService{},
|
2020-06-23 18:12:08 -04:00
|
|
|
}
|
2020-07-03 15:09:16 -04:00
|
|
|
|
|
|
|
return singleton, nil
|
2020-06-23 18:12:08 -04:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:03:40 -04:00
|
|
|
// Advance moves the input manager with the elapsed number of seconds.
|
2020-07-03 15:09:16 -04:00
|
|
|
func Advance(elapsed, current float64) error {
|
|
|
|
return singleton.Advance(elapsed, current)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:03:40 -04:00
|
|
|
// BindHandlerWithPriority adds an event handler with a specific call priority
|
2020-07-06 21:26:08 -04:00
|
|
|
func BindHandlerWithPriority(handler d2interface.InputEventHandler, priority d2enum.Priority) error {
|
2020-07-03 15:09:16 -04:00
|
|
|
return singleton.BindHandlerWithPriority(handler, priority)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:03:40 -04:00
|
|
|
// BindHandler adds an event handler
|
2020-07-03 15:09:16 -04:00
|
|
|
func BindHandler(handler d2interface.InputEventHandler) error {
|
2020-07-06 21:26:08 -04:00
|
|
|
return BindHandlerWithPriority(handler, d2enum.PriorityDefault)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:03:40 -04:00
|
|
|
// UnbindHandler removes a previously bound event handler
|
2020-07-03 15:09:16 -04:00
|
|
|
func UnbindHandler(handler d2interface.InputEventHandler) error {
|
|
|
|
return singleton.UnbindHandler(handler)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|