use core::ops::Deref;
use core::ops::DerefMut;
use crate::core::*;
use crate::sys;
#[derive(Clone, Copy)]
pub struct Alert<'a> {
pub(crate) entity: EntityView<'a>,
}
impl<'a> Deref for Alert<'a> {
type Target = EntityView<'a>;
#[inline]
fn deref(&self) -> &Self::Target {
&self.entity
}
}
impl DerefMut for Alert<'_> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.entity
}
}
impl<'a> WorldProvider<'a> for Alert<'a> {
#[inline(always)]
fn world(&self) -> WorldRef<'a> {
self.world
}
}
impl<'a> Alert<'a> {
pub fn new(world: impl WorldProvider<'a>, desc: sys::ecs_alert_desc_t) -> Self {
let id = unsafe { sys::ecs_alert_init(world.world_ptr_mut(), &desc) };
let entity = EntityView::new_from(world.world(), id);
Self { entity }
}
pub fn new_from_existing(alert_entity: EntityView<'a>) -> Self {
Self {
entity: alert_entity,
}
}
}