From efc00138ea0b20e8285e8c964665b0b92992861e Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Thu, 22 Aug 2024 17:26:15 -0400 Subject: [PATCH] fix tests --- tests/input_capture.rs | 3 ++- tests/input_playback.rs | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/input_capture.rs b/tests/input_capture.rs index 3583511..6eee593 100644 --- a/tests/input_capture.rs +++ b/tests/input_capture.rs @@ -7,6 +7,7 @@ use bevy::prelude::*; use bevy::window::WindowPlugin; use leafwing_input_playback::frame_counting::FrameCount; +use leafwing_input_playback::input_capture::BeginInputCapture; use leafwing_input_playback::input_capture::{InputCapturePlugin, InputModesCaptured}; use leafwing_input_playback::timestamped_input::{ InputEvent, TimestampedInputEvent, TimestampedInputs, @@ -41,7 +42,7 @@ fn capture_app() -> App { InputPlugin, InputCapturePlugin, )); - + app.world_mut().send_event(BeginInputCapture::default()); app } diff --git a/tests/input_playback.rs b/tests/input_playback.rs index 4417992..b8bc295 100644 --- a/tests/input_playback.rs +++ b/tests/input_playback.rs @@ -13,6 +13,7 @@ use bevy::window::WindowPlugin; use leafwing_input_playback::frame_counting::FrameCount; use leafwing_input_playback::input_capture::InputCapturePlugin; use leafwing_input_playback::input_capture::InputModesCaptured; +use leafwing_input_playback::input_playback::BeginInputPlayback; use leafwing_input_playback::input_playback::InputPlaybackPlugin; use leafwing_input_playback::input_playback::PlaybackStrategy; use leafwing_input_playback::timestamped_input::TimestampedInputs; @@ -44,7 +45,10 @@ fn playback_app(strategy: PlaybackStrategy) -> App { let mut registry = app.world_mut().resource_mut::(); registry.should_update = ShouldUpdateEvents::Always; - *app.world_mut().resource_mut::() = strategy; + app.world_mut().send_event(BeginInputPlayback { + playback_strategy: strategy, + ..Default::default() + }); app } @@ -74,7 +78,7 @@ fn minimal_playback() { let input_events = app.world().resource::>(); assert_eq!(input_events.len(), 0); - *app.world_mut().resource_mut::() = simple_timestamped_input(); + app.insert_resource(simple_timestamped_input()); app.update(); @@ -97,6 +101,7 @@ fn capture_and_playback() { let mut app = playback_app(PlaybackStrategy::default()); app.add_plugins(InputCapturePlugin); app.insert_resource(PlaybackStrategy::Paused); + app.insert_resource(TimestampedInputs::default()); let mut input_events = app.world_mut().resource_mut::>(); input_events.send(TEST_PRESS); @@ -133,7 +138,8 @@ fn repeated_playback() { let input_events = app.world().resource::>(); assert_eq!(input_events.len(), 0); - *app.world_mut().resource_mut::() = simple_timestamped_input(); + app.insert_resource(simple_timestamped_input()); + for _ in 1..10 { app.update(); } @@ -156,7 +162,7 @@ fn repeated_playback() { #[test] fn playback_strategy_paused() { let mut app = playback_app(PlaybackStrategy::Paused); - *app.world_mut().resource_mut::() = complex_timestamped_input(); + app.insert_resource(complex_timestamped_input()); let timestamped_input = app.world().resource::(); assert_eq!(timestamped_input.cursor, 0); @@ -172,7 +178,7 @@ fn playback_strategy_paused() { #[test] fn playback_strategy_frame() { let mut app = playback_app(PlaybackStrategy::FrameCount); - *app.world_mut().resource_mut::() = complex_timestamped_input(); + app.insert_resource(complex_timestamped_input()); let timestamped_input = app.world().resource::(); assert_eq!(timestamped_input.cursor, 0); @@ -195,7 +201,7 @@ fn playback_strategy_frame() { fn playback_strategy_frame_range_once() { let strategy = PlaybackStrategy::FrameRangeOnce(FrameCount(2), FrameCount(5)); let mut app = playback_app(strategy); - *app.world_mut().resource_mut::() = complex_timestamped_input(); + app.insert_resource(complex_timestamped_input()); let timestamped_input = app.world().resource::(); assert_eq!(timestamped_input.cursor, 0); @@ -234,7 +240,7 @@ fn playback_strategy_frame_range_once() { fn playback_strategy_frame_range_loop() { let strategy = PlaybackStrategy::FrameRangeLoop(FrameCount(2), FrameCount(5)); let mut app = playback_app(strategy); - *app.world_mut().resource_mut::() = complex_timestamped_input(); + app.insert_resource(complex_timestamped_input()); let timestamped_input = app.world().resource::(); assert_eq!(timestamped_input.cursor, 0);