Created
September 25, 2022 03:12
-
-
Save will-hart/d9f19d585d051320a9bae70a1f4dd731 to your computer and use it in GitHub Desktop.
My helper for bevy system tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::time::Duration; | |
use bevy::prelude::*; | |
use crate::core::time::SpectreTimePlugin; | |
pub struct TestWorld { | |
pub app: App, | |
} | |
impl Default for TestWorld { | |
fn default() -> Self { | |
let mut app = App::new(); | |
let mut time = Time::default(); | |
time.update(); | |
app.world.insert_resource(time); | |
app.add_plugin(SpectreTimePlugin); | |
Self { app } | |
} | |
} | |
impl TestWorld { | |
pub fn tick_time(&mut self, ms: u64) { | |
let mut time = self.app.world.resource_mut::<Time>(); | |
let last_update = time.last_update().unwrap(); | |
time.update_with_instant(last_update + Duration::from_millis(ms)); | |
} | |
pub fn tick_time_and_run(&mut self, ms: u64) { | |
self.tick_time(ms); | |
self.run_frame(); | |
} | |
pub fn run_frame(&mut self) { | |
self.app.update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment