use super::*;
use beet_core::prelude::*;
use beet_flow::prelude::*;
#[action(depth_sensor_scorer)]
#[derive(Debug, Clone, PartialEq, Component, Reflect)]
#[reflect(Default, Component)]
pub struct DepthSensorScorer {
pub threshold_dist: f32,
pub far_score: Score,
pub close_score: Score,
}
impl Default for DepthSensorScorer {
fn default() -> Self {
Self {
threshold_dist: 0.5,
far_score: Score::FAIL,
close_score: Score::PASS,
}
}
}
impl DepthSensorScorer {
pub fn new(threshold_dist: f32) -> Self {
Self {
threshold_dist,
..Default::default()
}
}
}
fn depth_sensor_scorer(
ev: On<GetScore>,
mut commands: Commands,
query: Query<&DepthSensorScorer>,
sensors: AgentQuery<&DepthValue, Changed<DepthValue>>,
) -> Result {
let target = ev.target();
let scorer = query.get(target)?;
let depth = sensors.get(target)?;
let next_score = if let Some(depth) = **depth {
if depth < scorer.threshold_dist {
scorer.close_score
} else {
scorer.far_score
}
} else {
scorer.far_score
};
commands.entity(target).trigger_target(next_score);
Ok(())
}