Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/testbed/helpers.rs
6592 views
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
// Changed scene! trigger a screenshot in 100 frames
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
// Exit once all scenes have been screenshotted
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
// Screenshot taken! Switch to the next scene
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
}
46
47