Skip to main content

subtr_actor/stats/analysis_graph/nodes/
positioning.rs

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