Skip to content

Instantly share code, notes, and snippets.

@will-hart
Created September 25, 2022 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-hart/d9f19d585d051320a9bae70a1f4dd731 to your computer and use it in GitHub Desktop.
Save will-hart/d9f19d585d051320a9bae70a1f4dd731 to your computer and use it in GitHub Desktop.
My helper for bevy system tests
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