| 1 |
#[cfg(feature = "bevy_ci_testing")] |
| 2 |
use bevy::{ |
| 3 |
dev_tools::ci_testing::{CiTestingConfig, CiTestingEvent, CiTestingEventOnFrame}, |
| 4 |
diagnostic::FrameCount, |
| 5 |
platform::collections::HashSet, |
| 6 |
prelude::*, |
| 7 |
render::view::screenshot::Captured, |
| 8 |
state::state::FreelyMutableState, |
| 9 |
}; |
| 10 |
|
| 11 |
#[cfg(feature = "bevy_ci_testing")] |
| 12 |
pub fn switch_scene_in_ci<Scene: States + FreelyMutableState + Next>( |
| 13 |
mut ci_config: ResMut<CiTestingConfig>, |
| 14 |
scene: Res<State<Scene>>, |
| 15 |
mut next_scene: ResMut<NextState<Scene>>, |
| 16 |
mut scenes_visited: Local<HashSet<Scene>>, |
| 17 |
frame_count: Res<FrameCount>, |
| 18 |
captured: RemovedComponents<Captured>, |
| 19 |
) { |
| 20 |
if scene.is_changed() { |
| 21 |
|
| 22 |
ci_config.events.push(CiTestingEventOnFrame( |
| 23 |
frame_count.0 + 100, |
| 24 |
CiTestingEvent::NamedScreenshot(format!("{:?}", scene.get())), |
| 25 |
)); |
| 26 |
if scenes_visited.contains(scene.get()) { |
| 27 |
|
| 28 |
ci_config.events.push(CiTestingEventOnFrame( |
| 29 |
frame_count.0 + 1, |
| 30 |
CiTestingEvent::AppExit, |
| 31 |
)); |
| 32 |
} |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
if !captured.is_empty() { |
| 37 |
|
| 38 |
scenes_visited.insert(scene.get().clone()); |
| 39 |
next_scene.set(scene.get().next()); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
pub trait Next { |
| 44 |
fn next(&self) -> Self; |
| 45 |
} |