|
| 1 | +use bevy::app::AppExit; |
| 2 | +use bevy::asset::AssetPlugin; |
| 3 | +use bevy::audio::AudioPlugin; |
| 4 | +use bevy::prelude::*; |
| 5 | +use bevy::state::app::StatesPlugin; |
| 6 | +use bevy_asset_loader::prelude::*; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn main() { |
| 10 | + let mut app = App::new(); |
| 11 | + |
| 12 | + app.add_plugins(( |
| 13 | + MinimalPlugins, |
| 14 | + AssetPlugin { |
| 15 | + file_path: "assets/audio".to_owned(), |
| 16 | + ..default() |
| 17 | + }, |
| 18 | + AudioPlugin::default(), |
| 19 | + StatesPlugin, |
| 20 | + )); |
| 21 | + app.init_state::<MyStates>(); |
| 22 | + app.add_loading_state( |
| 23 | + LoadingState::new(MyStates::Load) |
| 24 | + .continue_to_state(MyStates::Next) |
| 25 | + .load_collection::<PlopAudio>(), |
| 26 | + ) |
| 27 | + .add_systems(Update, timeout.run_if(in_state(MyStates::Load))) |
| 28 | + .add_systems(OnEnter(MyStates::Next), expect) |
| 29 | + .run(); |
| 30 | +} |
| 31 | + |
| 32 | +fn timeout(time: Res<Time>) { |
| 33 | + if time.elapsed_secs_f64() > 60. { |
| 34 | + panic!("The asset loader did not change the state in 60 seconds"); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +fn expect(collection: Option<Res<PlopAudio>>, mut exit: EventWriter<AppExit>) { |
| 39 | + if collection.is_none() { |
| 40 | + panic!("The asset collection was not inserted"); |
| 41 | + } else { |
| 42 | + exit.write(AppExit::Success); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +#[derive(AssetCollection, Resource)] |
| 47 | +struct PlopAudio { |
| 48 | + #[asset(path = "plop.ogg")] |
| 49 | + _plop: Handle<AudioSource>, |
| 50 | +} |
| 51 | + |
| 52 | +#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)] |
| 53 | +enum MyStates { |
| 54 | + #[default] |
| 55 | + Load, |
| 56 | + Next, |
| 57 | +} |
0 commit comments