From 796f7fbf622a273af8535859db735d765887d26e Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Sat, 13 Jul 2024 15:03:44 -0500 Subject: [PATCH] feat(game): Make speed help text change dynamically --- internal/game/game.go | 5 +++++ internal/game/keymap.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/game/game.go b/internal/game/game.go index 3df220c..4a8d5c4 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -4,6 +4,7 @@ import ( "context" "image" "slices" + "strconv" "strings" "time" @@ -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()) @@ -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()) diff --git a/internal/game/keymap.go b/internal/game/keymap.go index c7d976c..eacb15d 100644 --- a/internal/game/keymap.go +++ b/internal/game/keymap.go @@ -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"),