Skip to content

Commit

Permalink
feat(game): Make speed help text change dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jul 13, 2024
1 parent 57889ee commit 796f7fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"image"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -192,6 +193,8 @@ func (g Game) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, g.keymap.speedUp):
if g.speed < len(speeds)-1 {
g.speed++
tps := int(time.Second / speeds[g.speed])
g.keymap.changeSpeed.SetHelp(g.keymap.changeSpeed.Help().Key, "change speed: "+strconv.Itoa(tps)+" fps")
if g.ctx != nil {
g.cancel()
g.ctx, g.cancel = context.WithCancel(context.Background())
Expand All @@ -201,6 +204,8 @@ func (g Game) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, g.keymap.speedDown):
if g.speed > 0 {
g.speed--
tps := int(time.Second / speeds[g.speed])
g.keymap.changeSpeed.SetHelp(g.keymap.changeSpeed.Help().Key, "change speed: "+strconv.Itoa(tps)+" fps")
if g.ctx != nil {
g.cancel()
g.ctx, g.cancel = context.WithCancel(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion internal/game/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func newKeymap() keymap {
),
changeSpeed: key.NewBinding(
key.WithKeys("<", ".", ">", ","),
key.WithHelp("<>", "change speed"),
key.WithHelp("<>", "change speed: 30 fps"),
),
reset: key.NewBinding(
key.WithKeys("r"),
Expand Down

0 comments on commit 796f7fb

Please sign in to comment.