package client import ( "slices" "github.com/chompy/roguelike_rpg/internal/client/hud" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" ) type InputType int const ( InputUp InputType = iota InputRight InputDown InputLeft InputConfirm InputCancel ) func (i InputType) ToHudInput() hud.HudInput { switch i { case InputUp: return hud.InputUp case InputRight: return hud.InputRight case InputDown: return hud.InputDown case InputLeft: return hud.InputLeft } return -1 } var keyboardBinds = map[InputType][]ebiten.Key{ InputUp: {ebiten.KeyUp, ebiten.KeyW}, InputRight: {ebiten.KeyRight, ebiten.KeyD}, InputDown: {ebiten.KeyDown, ebiten.KeyS}, InputLeft: {ebiten.KeyLeft, ebiten.KeyA}, InputConfirm: {ebiten.KeyEnter, ebiten.KeySpace, ebiten.KeyShiftLeft}, InputCancel: {ebiten.KeyEscape, ebiten.KeyZ}, } var gamepadBinds = map[InputType][]ebiten.StandardGamepadButton{ InputUp: {ebiten.StandardGamepadButtonLeftTop}, InputRight: {ebiten.StandardGamepadButtonLeftRight}, InputDown: {ebiten.StandardGamepadButtonLeftBottom}, InputLeft: {ebiten.StandardGamepadButtonLeftLeft}, InputConfirm: {ebiten.StandardGamepadButtonRightRight}, InputCancel: {ebiten.StandardGamepadButtonRightBottom}, } func HasInput(input InputType) bool { if slices.ContainsFunc(gamepadBinds[input], func(btn ebiten.StandardGamepadButton) bool { return inpututil.IsStandardGamepadButtonJustPressed(0, btn) }) { return true } return slices.ContainsFunc(keyboardBinds[input], inpututil.IsKeyJustPressed) }