fix(engine): auto-complete delay + right-click shake on no legal move
Closes #80: add AUTO_COMPLETE_INITIAL_DELAY (0.75 s) before the first auto-complete move fires. Previously cooldown was 0.0, causing the sequence to hijack the board the same frame the condition was met. Closes #81: fire MoveRejectedEvent in radial_open_on_right_click when the right-clicked card has no legal destinations, so the shake animation and invalid-move sound play consistently on desktop/web. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,12 @@ const AUTO_COMPLETE_CHIME_VOLUME: f64 = 0.5;
|
||||
/// Seconds between consecutive auto-complete moves.
|
||||
const STEP_INTERVAL: f32 = 0.12;
|
||||
|
||||
/// Seconds to wait after detection before firing the first auto-complete move.
|
||||
///
|
||||
/// This pause gives the player a moment to register that the game is
|
||||
/// transitioning into auto-complete mode before cards start moving.
|
||||
const AUTO_COMPLETE_INITIAL_DELAY: f32 = 0.75;
|
||||
|
||||
/// Tracks whether auto-complete is active and when the next move fires.
|
||||
#[derive(Resource, Default, Debug)]
|
||||
pub struct AutoCompleteState {
|
||||
@@ -74,7 +80,7 @@ fn detect_auto_complete(
|
||||
}
|
||||
if game.0.is_auto_completable && !state.active {
|
||||
state.active = true;
|
||||
state.cooldown = 0.0; // fire first move immediately
|
||||
state.cooldown = AUTO_COMPLETE_INITIAL_DELAY;
|
||||
}
|
||||
// Intentionally no `else if !is_auto_completable` branch here.
|
||||
// Deactivating on every frame where `is_auto_completable` is false
|
||||
@@ -210,6 +216,12 @@ mod tests {
|
||||
app.world_mut().resource_mut::<GameStateResource>().0 = nearly_won_state();
|
||||
app.world_mut().write_message(StateChangedEvent);
|
||||
app.update(); // detect runs, sets active
|
||||
|
||||
// Zero out the cooldown so drive fires on the next update regardless
|
||||
// of the initial delay constant.
|
||||
app.world_mut()
|
||||
.resource_mut::<AutoCompleteState>()
|
||||
.cooldown = 0.0;
|
||||
app.update(); // drive fires the move
|
||||
|
||||
let events = app.world().resource::<Messages<MoveRequestEvent>>();
|
||||
|
||||
Reference in New Issue
Block a user