use std::marker::PhantomData;
use std::ops::{Deref, DerefMut, Index, IndexMut};
use bevy_ecs::system::{ResMut, SystemParam};
use crate::entity_marker::EntityMarker;
use crate::{MarkerData, MarkerSlot};
#[derive(SystemParam)]
pub struct MarkerMut<'s, 'w, M: EntityMarker + 'static> {
marker_data: ResMut<'w, MarkerData<M>>,
#[system_param(ignore)]
phantom: PhantomData<&'s ()>,
}
impl<M: EntityMarker> Deref for MarkerMut<'_, '_, M>
where
M::Slots<MarkerSlot>: Deref<Target = MarkerSlot>,
{
type Target = MarkerSlot;
fn deref(&self) -> &Self::Target {
self.marker_data.slots.deref()
}
}
impl<M: EntityMarker> DerefMut for MarkerMut<'_, '_, M>
where
M::Slots<MarkerSlot>: DerefMut<Target = MarkerSlot>,
{
fn deref_mut(&mut self) -> &mut Self::Target {
self.marker_data.slots.deref_mut()
}
}
impl<M: EntityMarker> Index<M> for MarkerMut<'_, '_, M>
where
M::Slots<MarkerSlot>: Index<usize, Output = MarkerSlot>,
{
type Output = MarkerSlot;
fn index(&self, index: M) -> &Self::Output {
self.marker_data.slots.index(index.slot())
}
}
impl<M: EntityMarker> IndexMut<M> for MarkerMut<'_, '_, M>
where
M::Slots<MarkerSlot>: IndexMut<usize, Output = MarkerSlot>,
{
fn index_mut(&mut self, index: M) -> &mut Self::Output {
self.marker_data.slots.index_mut(index.slot())
}
}