use bevy_ecs::{prelude::*, schedule::ScheduleConfigs, system::ScheduleSystem};
use bevy_state::state::FreelyMutableState;
use crate::prelude::*;
type SystemConfigs = ScheduleConfigs<ScheduleSystem>;
pub trait ProgressReturningSystem<T, Params> {
fn track_progress<S: FreelyMutableState>(self) -> SystemConfigs;
fn track_progress_and_stop<S: FreelyMutableState>(self) -> SystemConfigs;
}
impl<S, T, Params> ProgressReturningSystem<T, Params> for S
where
S: IntoSystem<(), T, Params>,
T: ApplyProgress + 'static,
{
fn track_progress<State: FreelyMutableState>(self) -> SystemConfigs {
let id = ProgressEntryId::new();
self.pipe(
move |In(progress): In<T>, tracker: Res<ProgressTracker<State>>| {
progress.apply_progress(&tracker, id);
},
)
.into_configs()
}
fn track_progress_and_stop<State: FreelyMutableState>(
self,
) -> SystemConfigs {
let id = ProgressEntryId::new();
self.pipe(
move |In(progress): In<T>, tracker: Res<ProgressTracker<State>>| {
progress.apply_progress(&tracker, id);
},
)
.run_if(move |tracker: Res<ProgressTracker<State>>| {
!tracker.is_id_ready(id)
})
.into_configs()
}
}
pub fn hide_progress(In(progress): In<Progress>) -> HiddenProgress {
HiddenProgress(progress)
}
pub fn unhide_progress(In(progress): In<HiddenProgress>) -> Progress {
progress.0
}