Skip to content

Commit

Permalink
Clean up construct_*_filtered_game_state (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
knoellle authored Oct 6, 2024
1 parent fb75fc4 commit 21d81c5
Showing 1 changed file with 8 additions and 45 deletions.
53 changes: 8 additions & 45 deletions crates/control/src/game_controller_state_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,19 @@ impl GameControllerStateFilter {
})
.unwrap_or(false);

let filtered_game_state = self.state.construct_hulks_filtered_game_state(
let filtered_game_state = self.state.construct_filtered_game_state_for_team(
game_controller_state,
Team::Hulks,
cycle_time.start_time,
ball_detected_far_from_kick_off_point,
config,
visual_referee_proceed_to_ready,
);

let filtered_opponent_game_state =
self.opponent_state.construct_opponent_filtered_game_state(
self.opponent_state.construct_filtered_game_state_for_team(
game_controller_state,
Team::Opponent,
cycle_time.start_time,
ball_detected_far_from_kick_off_point,
config,
Expand Down Expand Up @@ -399,57 +401,17 @@ impl State {
}
}

fn construct_hulks_filtered_game_state(
fn construct_filtered_game_state_for_team(
&self,
game_controller_state: &GameControllerState,
cycle_start_time: SystemTime,
ball_detected_far_from_kick_off_point: bool,
config: &GameStateFilterParameters,
visual_referee_proceed_to_ready: bool,
) -> FilteredGameState {
let opponent_is_kicking_team = matches!(
game_controller_state.kicking_team,
Team::Opponent | Team::Uncertain
);
self.construct_filtered_game_state(
game_controller_state,
opponent_is_kicking_team,
cycle_start_time,
ball_detected_far_from_kick_off_point,
config,
visual_referee_proceed_to_ready,
)
}

fn construct_opponent_filtered_game_state(
&self,
game_controller_state: &GameControllerState,
cycle_start_time: SystemTime,
ball_detected_far_from_kick_off_point: bool,
config: &GameStateFilterParameters,
visual_referee_proceed_to_ready: bool,
) -> FilteredGameState {
let hulks_is_kicking_team = matches!(game_controller_state.kicking_team, Team::Hulks);
self.construct_filtered_game_state(
game_controller_state,
hulks_is_kicking_team,
cycle_start_time,
ball_detected_far_from_kick_off_point,
config,
visual_referee_proceed_to_ready,
)
}

fn construct_filtered_game_state(
&self,
game_controller_state: &GameControllerState,
opponent_is_kicking_team: bool,
team: Team,
cycle_start_time: SystemTime,
ball_detected_far_from_kick_off_point: bool,
config: &GameStateFilterParameters,
visual_referee_proceed_to_ready: bool,
) -> FilteredGameState {
let is_in_sub_state = game_controller_state.sub_state.is_some();
let opponent_is_kicking_team = game_controller_state.kicking_team != team;

match self {
State::Initial => FilteredGameState::Initial,
Expand Down Expand Up @@ -478,6 +440,7 @@ impl State {
&& kick_off_grace_period
&& !ball_detected_far_from_kick_off_point;
let opponent_sub_state = opponent_is_kicking_team && is_in_sub_state;

FilteredGameState::Playing {
ball_is_free: !opponent_kick_off && !opponent_sub_state,
kick_off: !is_in_sub_state,
Expand Down

0 comments on commit 21d81c5

Please sign in to comment.