diff options
Diffstat (limited to 'go/client/keybindings.go')
| -rw-r--r-- | go/client/keybindings.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/go/client/keybindings.go b/go/client/keybindings.go index a6b32cf9..7f52b9df 100644 --- a/go/client/keybindings.go +++ b/go/client/keybindings.go @@ -5,6 +5,8 @@ import ( "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" + + "muhq.space/muhqs-game/go/ui" ) type ( @@ -12,7 +14,10 @@ type ( keyBindings map[interface{}]keyAction ) +var tapToHandle ui.Tap + func (g *Game) handleKeyBindings(bindings keyBindings) { + for _k, a := range bindings { var remove bool switch k := _k.(type) { @@ -20,6 +25,19 @@ func (g *Game) handleKeyBindings(bindings keyBindings) { if inpututil.IsMouseButtonJustPressed(k) { remove = a(g) } + + case ui.TouchType: + if k == ui.TouchTypes.Tap { + for _, tap := range ui.TouchManager.Taps { + tapToHandle = tap + log.Println("handle tap", tap) + remove := a(g) + if remove { + break + } + } + } + case ebiten.Key: if inpututil.IsKeyJustPressed(k) { remove = a(g) @@ -32,8 +50,17 @@ func (g *Game) handleKeyBindings(bindings keyBindings) { } } -func selection(g *Game) bool { +func clickSelection(g *Game) bool { x, y := ebiten.CursorPosition() + return selection(g, x, y) +} + +func touchSelection(g *Game) bool { + log.Println("touch selection") + return selection(g, tapToHandle.X, tapToHandle.Y) +} + +func selection(g *Game, x, y int) bool { obj := g.findObjectAt(x, y) if g.prompt != nil { |
