Skip to content

Commit

Permalink
Udate to latest Bevy main; prep for 0.8 (#16)
Browse files Browse the repository at this point in the history
* Update to latest Bevy commit

* Manually derive StageLabel

* Do not pin the Bevy commit

* Cargo.toml: point back at non-forked iyes_loopless

Co-authored-by: Ida Iyes <40234599+inodentry@users.noreply.github.com>
  • Loading branch information
NiklasEi and inodentry committed Jul 29, 2022
1 parent 31e54e7 commit b90ec9d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
5 changes: 3 additions & 2 deletions examples/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn main() {
.add_plugin(
ProgressPlugin::new(AppState::Splash)
.continue_to(AppState::MainMenu)
.track_assets())
.track_assets(),
)
// Add plugin for our game loading screen
.add_plugin(ProgressPlugin::new(AppState::GameLoading).continue_to(AppState::InGame))
// Load our UI assets during our splash screen
Expand All @@ -37,7 +38,7 @@ fn main() {
// we can also add regular untracked systems to our loading screen,
// like to draw our progress bar:
.with_system(ui_progress_bar)
.into()
.into(),
)
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_asset::prelude::*;
use bevy_asset::HandleId;
use bevy_asset::LoadState;
use bevy_asset::prelude::*;
use bevy_ecs::prelude::*;
use bevy_utils::HashSet;

Expand Down
54 changes: 28 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ use std::ops::{Add, AddAssign};
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering as MemOrdering;

use bevy_ecs::schedule::StateData;
use bevy_ecs::prelude::*;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_ecs::schedule::StateData;

#[cfg(feature = "assets")]
mod asset;

/// Most used imports
pub mod prelude {
pub use crate::ProgressPlugin;
pub use crate::Progress;
pub use crate::ProgressSystem;
pub use crate::ProgressCounter;
#[cfg(feature = "assets")]
pub use crate::asset::AssetsLoading;
pub use crate::Progress;
pub use crate::ProgressCounter;
pub use crate::ProgressPlugin;
pub use crate::ProgressSystem;
}

/// Progress reported by a system
Expand Down Expand Up @@ -146,10 +146,10 @@ impl AddAssign for Progress {
///
/// ```rust
/// # use bevy::prelude::*;
/// # use bevy_loading::ProgressPlugin;
/// # use iyes_progress::ProgressPlugin;
/// # let mut app = App::default();
/// app.add_plugin(LoadingPlugin::new(MyState::GameLoading).continue_to(MyState::InGame));
/// app.add_plugin(LoadingPlugin::new(MyState::Splash).continue_to(MyState::MainMenu));
/// app.add_plugin(ProgressPlugin::new(MyState::GameLoading).continue_to(MyState::InGame));
/// app.add_plugin(ProgressPlugin::new(MyState::Splash).continue_to(MyState::MainMenu));
/// # #[derive(Debug, Clone, PartialEq, Eq, Hash)]
/// # enum MyState {
/// # Splash,
Expand Down Expand Up @@ -195,10 +195,7 @@ impl<S: StateData> ProgressPlugin<S> {
#[cfg(not(feature = "iyes_loopless"))]
impl<S: StateData> Plugin for ProgressPlugin<S> {
fn build(&self, app: &mut App) {
app.add_system_set(
SystemSet::on_enter(self.state.clone())
.with_system(loadstate_enter),
);
app.add_system_set(SystemSet::on_enter(self.state.clone()).with_system(loadstate_enter));
app.add_system_set(
SystemSet::on_update(self.state.clone())
.with_system(
Expand All @@ -212,12 +209,9 @@ impl<S: StateData> Plugin for ProgressPlugin<S> {
.exclusive_system()
.at_end()
.label(ProgressSystemLabel::CheckProgress),
)
);
app.add_system_set(
SystemSet::on_exit(self.state.clone())
.with_system(loadstate_exit)
),
);
app.add_system_set(SystemSet::on_exit(self.state.clone()).with_system(loadstate_exit));

#[cfg(feature = "assets")]
if self.track_assets {
Expand All @@ -227,8 +221,7 @@ impl<S: StateData> Plugin for ProgressPlugin<S> {
.with_system(asset::assets_progress.track_progress()),
);
app.add_system_set(
SystemSet::on_exit(self.state.clone())
.with_system(asset::assets_loading_reset),
SystemSet::on_exit(self.state.clone()).with_system(asset::assets_loading_reset),
);
}

Expand All @@ -242,20 +235,27 @@ impl<S: StateData> Plugin for ProgressPlugin<S> {
#[cfg(feature = "iyes_loopless")]
impl<S: StateData> Plugin for ProgressPlugin<S> {
fn build(&self, app: &mut App) {
use iyes_loopless::prelude::*;
use iyes_loopless::condition::IntoConditionalExclusiveSystem;
use iyes_loopless::prelude::*;

app.add_enter_system(self.state.clone(), loadstate_enter);
app.add_exit_system(self.state.clone(), loadstate_exit);

#[derive(Debug, Clone, PartialEq, Eq, Hash, StageLabel)]
#[derive(Debug, Clone)]
struct StageLabel(String);

impl bevy_ecs::schedule::StageLabel for StageLabel {
fn as_str(&self) -> &'static str {
Box::leak(self.0.clone().into_boxed_str())
}
}

let stagelabel = StageLabel(format!("iyes_progress init: {:?}", &self.state));

app.add_stage_after(
iyes_loopless::state::app::StateTransitionStageLabel::from_type::<S>(),
stagelabel.clone(),
SystemStage::single_threaded()
SystemStage::single_threaded(),
);

app.add_system_to_stage(
Expand All @@ -281,7 +281,7 @@ impl<S: StateData> Plugin for ProgressPlugin<S> {
app.add_system(
asset::assets_progress
.track_progress()
.run_in_state(self.state.clone())
.run_in_state(self.state.clone()),
);
}

Expand All @@ -303,7 +303,8 @@ pub trait ProgressSystem<Params>: IntoSystem<(), Progress, Params> {

#[cfg(not(feature = "iyes_loopless"))]
impl<S, Params> ProgressSystem<Params> for S
where S: IntoSystem<(), Progress, Params>
where
S: IntoSystem<(), Progress, Params>,
{
fn track_progress(self) -> bevy_ecs::schedule::ParallelSystemDescriptor {
self.chain(
Expand All @@ -326,7 +327,8 @@ pub trait ProgressSystem<Params>: IntoSystem<(), Progress, Params> {

#[cfg(feature = "iyes_loopless")]
impl<S, Params> ProgressSystem<Params> for S
where S: IntoSystem<(), Progress, Params>
where
S: IntoSystem<(), Progress, Params>,
{
fn track_progress(self) -> iyes_loopless::condition::ConditionalSystemDescriptor {
use iyes_loopless::condition::IntoConditionalSystem;
Expand Down

0 comments on commit b90ec9d

Please sign in to comment.