use bevy::prelude::*;
use crate::prelude::*;
mod capture;
mod ext;
pub use self::{
capture::{
CaptureDeserialize,
CaptureInput,
CaptureOutput,
CaptureSerialize,
},
ext::{
AppPathwayExt,
WorldPathwayExt,
},
};
#[cfg(feature = "reflect")]
mod compat;
#[cfg(feature = "reflect")]
pub use self::compat::PipelineCapture;
pub trait Pathway {
type Capture: 'static;
type Backend: for<'a> Backend<Self::Key<'a>> + Send + Sync + 'static;
type Format: Format;
type Key<'a>;
fn key(&self) -> Self::Key<'_>;
fn capture(&self, world: &World) -> impl FlowLabel;
fn apply(&self, world: &World) -> impl FlowLabel;
}
#[cfg(test)]
mod test {
use serde::{
Deserialize,
Serialize,
};
use super::*;
use crate as bevy_save;
struct ExamplePathway {
pos: (i32, i32, i32),
}
#[derive(Serialize, Deserialize)]
struct ExamplePathwayCapture {
pos: (i32, i32, i32),
transforms: Vec<(Entity, Transform)>,
}
#[derive(Hash, Debug, PartialEq, Eq, Clone, Copy, FlowLabel)]
struct ExamplePathwayCaptureFlow;
#[derive(Hash, Debug, PartialEq, Eq, Clone, Copy, FlowLabel)]
struct ExamplePathwayApplyFlow;
impl Pathway for ExamplePathway {
type Capture = ExamplePathwayCapture;
type Backend = DefaultDebugBackend;
type Format = DefaultDebugFormat;
type Key<'a> = String;
fn key(&self) -> Self::Key<'_> {
let (x, y, z) = self.pos;
format!("sav-{x}-{y}-{z}")
}
fn capture(&self, _world: &World) -> impl FlowLabel {
ExamplePathwayCaptureFlow
}
fn apply(&self, _world: &World) -> impl FlowLabel {
ExamplePathwayApplyFlow
}
}
}