diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 21:30:37 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 21:30:37 +0200 |
commit | 4ab1c16455efcce48ba7ff4c92dc1030c9700208 (patch) | |
tree | 432c86e669007b1903892381c2ce53c6c6c37915 | |
parent | 42d68aa99d59339dbdf928a54c28242635728daa (diff) |
Avoid to recall `newGameCallback()` if not in landing page
-rw-r--r-- | pkg/ui/views/play_keymap.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/pkg/ui/views/play_keymap.go b/pkg/ui/views/play_keymap.go index 200f427..fa3caec 100644 --- a/pkg/ui/views/play_keymap.go +++ b/pkg/ui/views/play_keymap.go @@ -67,14 +67,20 @@ func (m PlayModel) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) { switch { case key.Matches(msg, m.keys.EnterNewGame): - m.page = InsertCodePage - return m, cmd + if m.page == LandingPage { + m.page = InsertCodePage + return m, cmd + } case key.Matches(msg, m.keys.StartNewGame): - m.page = StartGamePage - if !m.isLoading { - m.isLoading = true - return m, m.newGameCallback() + if m.page == LandingPage { + m.page = StartGamePage + if !m.isLoading { + m.isLoading = true + return m, m.newGameCallback() + } + + return m, cmd } case key.Matches(msg, m.keys.RestoreGame): |