From 0ce60277d02a3ed62620deb21f53b9f8b3b7f43e Mon Sep 17 00:00:00 2001 From: omesser Date: Wed, 2 Sep 2026 06:47:13 +0300 Subject: [PATCH] fix(engine): Sit the Character down when Do Not Disturb turns on (#84) Walk velocity outlives the Primitive that started it, so refusing Director proposals left a pacing sprite on screen. Co-authored-by: Cursor --- crates/core/src/engine.rs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/crates/core/src/engine.rs b/crates/core/src/engine.rs index 4542df46e..919ec2369 100644 --- a/crates/core/src/engine.rs +++ b/crates/core/src/engine.rs @@ -385,8 +385,20 @@ impl Engine { /// #84: toggle Do Not Disturb. The Character stays visible but stops /// starting things: no Director proposals are applied and no unprompted /// dialogue is spoken. Poke, Grab, and Throw still work. + /// + /// A walk already under way has to be sat down too. Walk velocity + /// outlives the Primitive that started it, so refusing the next + /// proposal would otherwise leave the sprite pacing. pub fn set_do_not_disturb(&mut self, enabled: bool) { self.do_not_disturb = enabled; + if enabled + && matches!(self.state, State::Grounded | State::Perched) + && (self.is_walking() + || matches!(self.on_screen(), Some(Primitive::Walk | Primitive::Chase))) + { + let _ = self.play(&[Primitive::Sit]); + self.velocity.x = 0.0; + } } pub fn do_not_disturb(&self) -> bool { @@ -4812,6 +4824,46 @@ mod tests { ); } + /// #84: walk velocity outlives the Primitive that started it, so refusing + /// the next proposal is not enough. Sit is what stops the feet. + #[test] + fn toggling_do_not_disturb_stops_a_walk_and_sits_the_sprite_down() { + let mut engine = a_character_at(Point { x: 200.0, y: 0.0 }); + settle(&mut engine, &a_long_perch()); + + engine.tick(&WorldSnapshot { + proposal: walk(), + ..a_long_perch() + }); + let strolling = engine.tick(&a_long_perch()); + assert_eq!( + strolling.animation, "walk", + "precondition: the sprite is walking" + ); + assert_ne!( + strolling.velocity.x, 0.0, + "precondition: the walk has a heading" + ); + + engine.set_do_not_disturb(true); + let settled = engine.tick(&a_long_perch()); + + assert_eq!(settled.animation, "sit"); + assert_eq!(settled.velocity.x, 0.0, "sit is what stops the walk"); + assert_eq!( + settled.state, + State::Perched, + "quiet is sit, not gone and not asleep" + ); + + let rest: Vec = (0..20).map(|_| engine.tick(&a_long_perch())).collect(); + assert!( + rest.iter() + .all(|frame| frame.velocity.x == 0.0 && frame.animation == "sit"), + "the walk does not resume: {rest:?}" + ); + } + #[test] fn a_sprite_standing_at_the_left_edge_faces_right() { let mut engine = Engine::new(Point { x: 0.0, y: 400.0 });