Skip to main content

subtr_actor/stats/analysis_graph/nodes/
touch.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5pub struct TouchNode {
6    calculator: TouchCalculator,
7}
8
9impl TouchNode {
10    pub fn new() -> Self {
11        Self {
12            calculator: TouchCalculator::new(),
13        }
14    }
15}
16
17impl Default for TouchNode {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl AnalysisNode for TouchNode {
24    type State = TouchCalculator;
25
26    fn name(&self) -> &'static str {
27        "touch"
28    }
29
30    fn dependencies(&self) -> NodeDependencies {
31        vec![
32            frame_info_dependency(),
33            ball_frame_state_dependency(),
34            player_frame_state_dependency(),
35            player_vertical_state_dependency(),
36            touch_state_dependency(),
37            possession_state_dependency(),
38            fifty_fifty_state_dependency(),
39            live_play_dependency(),
40        ]
41    }
42
43    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
44        let touch_state = ctx.get::<TouchState>()?;
45        self.calculator.update(
46            ctx.get::<FrameInfo>()?,
47            ctx.get::<BallFrameState>()?,
48            ctx.get::<PlayerFrameState>()?,
49            ctx.get::<PlayerVerticalState>()?,
50            touch_state,
51            ctx.get::<PossessionState>()?,
52            ctx.get::<FiftyFiftyState>()?,
53            ctx.get::<LivePlayState>()?.is_live_play,
54        )
55    }
56
57    fn state(&self) -> &Self::State {
58        &self.calculator
59    }
60}
61
62pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
63    Box::new(TouchNode::new())
64}