From d48b9489db731e7ec0367918cbdc4568bfb74e9b Mon Sep 17 00:00:00 2001 From: funman300 Date: Wed, 6 May 2026 15:36:09 +0000 Subject: [PATCH] feat(engine): Esc dismisses Home / accepts default on Restore prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Home and Restore-prompt previously ignored Esc, which after the last fix meant Esc just did nothing on those screens. Now both honor the "Esc closes the modal" convention every other modal already follows. - Home: Esc behaves like the Cancel button — despawns the modal so the player keeps the underlying default deal. - Restore: Esc maps to Continue rather than New Game; a reflexive dismiss press preserves the saved game, matching how the primary action already advertises the Enter accelerator. Co-Authored-By: Claude Opus 4.7 (1M context) --- solitaire_engine/src/game_plugin.rs | 12 +++++++++--- solitaire_engine/src/home_plugin.rs | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/solitaire_engine/src/game_plugin.rs b/solitaire_engine/src/game_plugin.rs index 9505ef3..290d16b 100644 --- a/solitaire_engine/src/game_plugin.rs +++ b/solitaire_engine/src/game_plugin.rs @@ -590,9 +590,15 @@ fn handle_restore_prompt( if screens.is_empty() { return; } - let key_continue = keys - .as_ref() - .is_some_and(|k| k.just_pressed(KeyCode::Enter) || k.just_pressed(KeyCode::KeyC)); + // Esc maps to Continue rather than New Game so a stray dismiss + // press preserves the saved game — the data-preserving default is + // the safer fallback when a player hits Esc reflexively to "close + // this dialog" without reading it. + let key_continue = keys.as_ref().is_some_and(|k| { + k.just_pressed(KeyCode::Enter) + || k.just_pressed(KeyCode::KeyC) + || k.just_pressed(KeyCode::Escape) + }); let key_new = keys.as_ref().is_some_and(|k| k.just_pressed(KeyCode::KeyN)); let click_continue = continue_buttons .iter() diff --git a/solitaire_engine/src/home_plugin.rs b/solitaire_engine/src/home_plugin.rs index e2de230..ddae6be 100644 --- a/solitaire_engine/src/home_plugin.rs +++ b/solitaire_engine/src/home_plugin.rs @@ -333,10 +333,16 @@ fn handle_home_card_click( fn handle_home_cancel_button( mut commands: Commands, + keys: Option>>, cancel_buttons: Query<&Interaction, (With, Changed)>, screens: Query>, ) { - if !cancel_buttons.iter().any(|i| *i == Interaction::Pressed) { + if screens.is_empty() { + return; + } + let click = cancel_buttons.iter().any(|i| *i == Interaction::Pressed); + let esc = keys.is_some_and(|k| k.just_pressed(KeyCode::Escape)); + if !click && !esc { return; } for entity in &screens {