Skip to main content

subtr_actor/stats/analysis_graph/nodes/
half_flip.rs

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