package main import ( "log" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" "muhq.space/muhqs-game/go/ui" ) type ( keyAction func(*Game) bool 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) { case ebiten.MouseButton: 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) } } if remove { delete(bindings, _k) } } } 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 { if err := g.prompt.Add(obj); err != nil { log.Println("Not added", obj, "to active prompt:", err) g.handleSelection(obj, x, y) } else { g.updateHighlight() } } else { g.handleSelection(obj, x, y) } return false } func pass(g *Game) bool { g.passButton.Click(0, 0) return false } func reset(g *Game) bool { g.removeChoice() g.selectedObject = nil g.ResetHover() g.clearHighlights() g.hideStore() g.RemoveWidget(g.discardPileView) g.RemoveWidget(g.resetButton) if g.prompt != nil { if g.prompt.Action().Targets().NoSelections() { g.removePrompt() } else { g.prompt.ClearSelections() } } return false }