use beet_core::prelude::*;
#[derive(Debug, Copy, Clone, PartialEq, Component, Reflect)]
#[reflect(Component, MapEntities)]
pub enum SteerTarget {
Position(Vec3),
Entity(Entity),
}
impl Default for SteerTarget {
fn default() -> Self { Self::Position(Vec3::default()) }
}
impl SteerTarget {
pub fn get_position(
&self,
query: &Query<&GlobalTransform>,
) -> Result<Vec3> {
match self {
Self::Position(position) => Ok(*position),
Self::Entity(entity) => {
if let Ok(transform) = query.get(*entity) {
Ok(transform.translation())
} else {
bevybail!("transform not found for entity {entity:?}")
}
}
}
}
}
impl MapEntities for SteerTarget {
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
match self {
Self::Entity(entity) => *entity = entity_mapper.get_mapped(*entity),
_ => {}
}
}
}
impl Into<SteerTarget> for Vec3 {
fn into(self) -> SteerTarget { SteerTarget::Position(self) }
}
impl Into<SteerTarget> for Entity {
fn into(self) -> SteerTarget { SteerTarget::Entity(self) }
}