aboutsummaryrefslogtreecommitdiff
path: root/go/client/game.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-08-09 20:13:09 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:54 +0100
commit5c0d148471a9822bc2799df28a13b2f3232acb9a (patch)
tree0d773ecd79e6bd82a01f6425ba21dcf0d1493d06 /go/client/game.go
parent58e15d20d9fa880d4d66ab080a307ae2c88afb2f (diff)
downloadmuhqs-game-5c0d148471a9822bc2799df28a13b2f3232acb9a.tar.gz
muhqs-game-5c0d148471a9822bc2799df28a13b2f3232acb9a.zip
client: make key bindings dynamic
Diffstat (limited to 'go/client/game.go')
-rw-r--r--go/client/game.go44
1 files changed, 12 insertions, 32 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 9c95deb2..58e4c63c 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -35,6 +35,8 @@ const (
type Game struct {
app *app
+ keyBindings keyBindings
+
selectedObject interface{}
handLayer *ui.HandView
@@ -61,13 +63,19 @@ type Game struct {
func newGame(app *app) *Game {
g := &Game{
- app: app,
+ app: app,
+ keyBindings: make(keyBindings),
Collection: ui.Collection{
Width: app.windowWidth,
Height: app.windowHeight,
},
}
+ // default key bindings
+ g.keyBindings[ebiten.MouseButtonLeft] = selection
+ g.keyBindings[ebiten.KeySpace] = pass
+ g.keyBindings[ebiten.KeyEscape] = reset
+
g.gameState = game.NewState()
g.passButton = ui.NewSimpleButton(g.Width-PASS_BUTTON_WIDTH,
@@ -520,38 +528,10 @@ func (g *Game) updateHighlight() {
func (g *Game) Update() error {
g.handlePlayerNotifications()
- if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
- x, y := ebiten.CursorPosition()
- 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)
- }
- } else if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
- g.passButton.Click(0, 0)
- } else if inpututil.IsKeyJustPressed(ebiten.KeyQ) {
+ g.handleKeyBindings(g.keyBindings)
+
+ if inpututil.IsKeyJustPressed(ebiten.KeyQ) {
return ebiten.Termination
- } else if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
- g.removeChoice()
- g.selectedObject = nil
- g.ResetHover()
- g.clearHighlights()
- g.hideStore()
- g.RemoveWidget(g.discardPileView)
- if g.prompt != nil {
- if g.prompt.Action().Targets().NoSelections() {
- g.removePrompt()
- } else {
- g.prompt.ClearSelections()
- }
- }
}
if err := g.Collection.Update(); err != nil {