Skip to main content

subtr_actor/stats/analysis_graph/nodes/
center.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5/// Detects centering passes from ball state, touches, and frame events during live play.
6pub struct CenterNode {
7    calculator: CenterCalculator,
8}
9
10impl CenterNode {
11    pub fn new() -> Self {
12        Self {
13            calculator: CenterCalculator::new(),
14        }
15    }
16}
17
18impl Default for CenterNode {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl AnalysisNode for CenterNode {
25    type State = CenterCalculator;
26
27    fn name(&self) -> &'static str {
28        "center"
29    }
30
31    fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
32        crate::stats::calculators::CENTER_EMITTED_EVENTS
33    }
34
35    fn dependencies(&self) -> NodeDependencies {
36        vec![
37            frame_info_dependency(),
38            ball_frame_state_dependency(),
39            touch_state_dependency(),
40            frame_events_state_dependency(),
41            live_play_dependency(),
42        ]
43    }
44
45    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
46        self.calculator.update(
47            ctx.get::<FrameInfo>()?,
48            ctx.get::<BallFrameState>()?,
49            ctx.get::<TouchState>()?,
50            ctx.get::<FrameEventsState>()?,
51            ctx.get::<LivePlayState>()?,
52        )
53    }
54
55    fn state(&self) -> &Self::State {
56        &self.calculator
57    }
58}
59
60pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
61    Box::new(CenterNode::new())
62}