From 12ed41022b6243dc925afd23831dbb770b04b261 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Fri, 12 Jul 2024 14:30:10 -0500 Subject: [PATCH] feat: Add manual tick keybind --- internal/game/game.go | 10 +++++++++- internal/game/keymap.go | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/game/game.go b/internal/game/game.go index d58a987..ce5c64e 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -93,7 +93,9 @@ func (g Game) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } } - return g, Tick(g.ctx) + if g.ctx != nil { + return g, Tick(g.ctx) + } case tea.WindowSizeMsg: if msg.Width != 0 && msg.Height != 0 { g.w, g.h = msg.Width/2, msg.Height-1 @@ -151,6 +153,12 @@ func (g Game) Update(msg tea.Msg) (tea.Model, tea.Cmd) { g.cancel() g.ctx, g.cancel = nil, nil } + case key.Matches(msg, g.keymap.tick): + if g.ctx == nil { + return g, func() tea.Msg { + return tick{} + } + } case key.Matches(msg, g.keymap.placeErase): switch g.mode { case ModePlace: diff --git a/internal/game/keymap.go b/internal/game/keymap.go index df62c9c..427eda8 100644 --- a/internal/game/keymap.go +++ b/internal/game/keymap.go @@ -10,6 +10,10 @@ func newKeymap() keymap { key.WithKeys(" ", "enter"), key.WithHelp("space", "play"), ), + tick: key.NewBinding( + key.WithKeys("t"), + key.WithHelp("t", "tick"), + ), placeErase: key.NewBinding( key.WithKeys("m"), key.WithHelp("m", "erase"), @@ -31,6 +35,7 @@ func newKeymap() keymap { type keymap struct { playPause key.Binding + tick key.Binding placeErase key.Binding wrap key.Binding reset key.Binding @@ -40,6 +45,7 @@ type keymap struct { func (k keymap) ShortHelp() []key.Binding { return []key.Binding{ k.playPause, + k.tick, k.placeErase, k.wrap, k.reset,