diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-04-29 14:33:38 -0500 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-05-01 09:46:15 -0500 |
| commit | c04fda8e5c2f097947843736f18b8af96a801daa (patch) | |
| tree | bc789b4b9fa28ed856f85303d87fea8739353929 | |
| parent | 39a35e9f498b39926d4e4a4cfbe154bb8395e9eb (diff) | |
| download | muhqs-game-c04fda8e5c2f097947843736f18b8af96a801daa.tar.gz muhqs-game-c04fda8e5c2f097947843736f18b8af96a801daa.zip | |
support touch input as selection
| -rw-r--r-- | go/client/game.go | 13 | ||||
| -rw-r--r-- | go/client/keybindings.go | 29 |
2 files changed, 37 insertions, 5 deletions
diff --git a/go/client/game.go b/go/client/game.go index 72bb9c4e..92708f3c 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -74,7 +74,8 @@ func newGame(app *app, gameState game.State) *Game { } // default key bindings - g.keyBindings[ebiten.MouseButtonLeft] = selection + g.keyBindings[ebiten.MouseButtonLeft] = clickSelection + g.keyBindings[ui.TouchTypes.Tap] = touchSelection g.keyBindings[ebiten.KeySpace] = pass g.keyBindings[ebiten.KeyEscape] = reset @@ -556,17 +557,21 @@ func (g *Game) updateHighlight() { } func (g *Game) Update() error { - g.handlePlayerNotifications() - g.handleKeyBindings(g.keyBindings) - if inpututil.IsKeyJustPressed(ebiten.KeyQ) { return ebiten.Termination } + if err := ui.TouchManager.Update(); err != nil { + return err + } + if err := g.Collection.Update(); err != nil { return err } + g.handlePlayerNotifications() + g.handleKeyBindings(g.keyBindings) + g.updatePassButton() return nil } 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 { |
