use crate::snapshot::{
CloneStrategy, ComponentChecksumPlugin, ComponentMapEntitiesPlugin, ComponentSnapshotPlugin,
ResourceChecksumPlugin, ResourceSnapshotPlugin,
};
use bevy::{
ecs::{
component::{Immutable, Mutable},
entity::MapEntities,
},
prelude::*,
};
use std::hash::Hash;
use super::{
CopyStrategy, ImmutableComponentSnapshotPlugin, ReflectStrategy, ResourceMapEntitiesPlugin,
};
pub trait RollbackApp {
fn rollback_component_with_copy<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Copy;
fn rollback_immutable_component_with_copy<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Copy;
fn rollback_resource_with_copy<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Copy;
fn rollback_component_with_clone<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Clone;
fn rollback_immutable_component_with_clone<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Clone;
fn rollback_resource_with_clone<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Clone;
fn rollback_component_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Reflect + FromWorld;
fn rollback_immutable_component_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Reflect + FromWorld;
fn rollback_resource_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Reflect + FromWorld;
fn checksum_component_with_hash<Type>(&mut self) -> &mut Self
where
Type: Component + Hash;
fn update_component_with_map_entities<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + MapEntities;
fn checksum_resource_with_hash<Type>(&mut self) -> &mut Self
where
Type: Resource + Hash;
fn update_resource_with_map_entities<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + MapEntities;
fn checksum_component<Type>(&mut self, hasher: for<'a> fn(&'a Type) -> u64) -> &mut Self
where
Type: Component;
fn checksum_resource<Type>(&mut self, hasher: for<'a> fn(&'a Type) -> u64) -> &mut Self
where
Type: Resource;
fn require_rollback<Type>(&mut self) -> &mut Self
where
Type: Component;
}
impl RollbackApp for App {
fn rollback_component_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Reflect + FromWorld,
{
self.add_plugins(ComponentSnapshotPlugin::<ReflectStrategy<Type>>::default())
}
fn rollback_immutable_component_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Reflect + FromWorld,
{
self.add_plugins(ImmutableComponentSnapshotPlugin::<ReflectStrategy<Type>>::default())
}
fn rollback_resource_with_reflect<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Reflect + FromWorld,
{
self.add_plugins(ResourceSnapshotPlugin::<ReflectStrategy<Type>>::default())
}
fn rollback_component_with_copy<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Copy,
{
self.add_plugins(ComponentSnapshotPlugin::<CopyStrategy<Type>>::default())
}
fn rollback_immutable_component_with_copy<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Copy,
{
self.add_plugins(ImmutableComponentSnapshotPlugin::<CopyStrategy<Type>>::default())
}
fn rollback_resource_with_copy<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Copy,
{
self.add_plugins(ResourceSnapshotPlugin::<CopyStrategy<Type>>::default())
}
fn rollback_component_with_clone<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + Clone,
{
self.add_plugins(ComponentSnapshotPlugin::<CloneStrategy<Type>>::default())
}
fn rollback_immutable_component_with_clone<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Immutable> + Clone,
{
self.add_plugins(ImmutableComponentSnapshotPlugin::<CloneStrategy<Type>>::default())
}
fn rollback_resource_with_clone<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + Clone,
{
self.add_plugins(ResourceSnapshotPlugin::<CloneStrategy<Type>>::default())
}
fn checksum_component_with_hash<Type>(&mut self) -> &mut Self
where
Type: Component + Hash,
{
self.add_plugins(ComponentChecksumPlugin::<Type>::default())
}
fn update_component_with_map_entities<Type>(&mut self) -> &mut Self
where
Type: Component<Mutability = Mutable> + MapEntities,
{
self.add_plugins(ComponentMapEntitiesPlugin::<Type>::default())
}
fn checksum_resource_with_hash<Type>(&mut self) -> &mut Self
where
Type: Resource + Hash,
{
self.add_plugins(ResourceChecksumPlugin::<Type>::default())
}
fn update_resource_with_map_entities<Type>(&mut self) -> &mut Self
where
Type: Resource<Mutability = Mutable> + MapEntities,
{
self.add_plugins(ResourceMapEntitiesPlugin::<Type>::default())
}
fn checksum_component<Type>(&mut self, hasher: for<'a> fn(&'a Type) -> u64) -> &mut Self
where
Type: Component,
{
self.add_plugins(ComponentChecksumPlugin::<Type>(hasher))
}
fn checksum_resource<Type>(&mut self, hasher: for<'a> fn(&'a Type) -> u64) -> &mut Self
where
Type: Resource,
{
self.add_plugins(ResourceChecksumPlugin::<Type>(hasher))
}
fn require_rollback<Type>(&mut self) -> &mut Self
where
Type: Component,
{
self.register_required_components::<Type, super::Rollback>();
self
}
}