Skip to main content

subtr_actor/stats/analysis_graph/nodes/
controlled_play.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5pub struct ControlledPlayNode {
6    calculator: ControlledPlayCalculator,
7}
8
9impl ControlledPlayNode {
10    pub fn new() -> Self {
11        Self {
12            calculator: ControlledPlayCalculator::new(),
13        }
14    }
15}
16
17impl Default for ControlledPlayNode {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl AnalysisNode for ControlledPlayNode {
24    type State = ControlledPlayCalculator;
25
26    fn name(&self) -> &'static str {
27        "controlled_play"
28    }
29
30    fn dependencies(&self) -> Vec<AnalysisDependency> {
31        vec![
32            frame_info_dependency(),
33            ball_frame_state_dependency(),
34            player_frame_state_dependency(),
35            touch_state_dependency(),
36            live_play_dependency(),
37        ]
38    }
39
40    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
41        self.calculator.update(
42            ctx.get::<FrameInfo>()?,
43            ctx.get::<BallFrameState>()?,
44            ctx.get::<PlayerFrameState>()?,
45            ctx.get::<TouchState>()?,
46            ctx.get::<LivePlayState>()?,
47        )
48    }
49
50    fn finish(&mut self, _ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
51        self.calculator.finish();
52        Ok(())
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(ControlledPlayNode::new())
62}