Skip to content

Commit

Permalink
feat: Add manual tick keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jul 12, 2024
1 parent af1b312 commit 12ed410
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions internal/game/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 12ed410

Please sign in to comment.