From 2315f9608abe0e9133ca5ca4b4fc8b7d2309da5d Mon Sep 17 00:00:00 2001 From: Nicholas Bottone Date: Fri, 5 Jan 2024 21:50:21 -0500 Subject: [PATCH] Add submit_crescendo function and related checks --- .gitignore | 1 + highscores/lib.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.gitignore b/.gitignore index 0eee590..4a784b4 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ dmypy.json migrations/ .vscode/ +.DS_Store diff --git a/highscores/lib.py b/highscores/lib.py index 26efc2e..b4040b7 100644 --- a/highscores/lib.py +++ b/highscores/lib.py @@ -82,6 +82,10 @@ def submit_over_under(score_obj: Score) -> Union[str, None]: return submit_score(score_obj, over_under_clean_code_check) +def submit_crescendo(score_obj: Score) -> Union[str, None]: + return submit_score(score_obj, crescendo_clean_code_check) + + def decode_time_data(in_string: str) -> str: out_bytes = "" @@ -268,6 +272,10 @@ def over_under_clean_code_check(score_obj: Score) -> Union[str, None]: return clean_code_check(score_obj, check_over_under_game_settings, check_score) +def crescendo_clean_code_check(score_obj: Score) -> Union[str, None]: + return clean_code_check(score_obj, check_crescendo_game_settings, check_score) + + def extract_clean_code_info(score_obj: Score) -> tuple[str, list[str], str, str, str, str, str]: """ Extracts the relevant information from the clean code. :param score_obj: Score object to extract from @@ -444,6 +452,20 @@ def check_over_under_game_settings(game_options: list, restart_option: str, game return None # No error +def check_crescendo_game_settings(game_options: list, restart_option: str, game_index: str) -> Union[str, None]: + """ Checks if the Crescendo game settings are valid. + :return: None if the settings are valid, or a response with an error message if they are not. + """ + if (game_index != '15'): + return 'Wrong game! This form is for Crescendo.' + if (game_options[2] != '1'): + return 'You must set setting 3 to "1" for high score submissions.' + if (game_options[3] != '4'): + return 'You must set setting 4 to "4" for high score submissions.' + + return None # No error + + def check_robot_type(score_obj: Score, robot_model: str) -> Union[str, None]: """ Checks if the robot model is valid. :return: None if the robot model is valid, or a response with an error message if it is not. @@ -608,6 +630,7 @@ def check_time_data(score_obj: Score) -> Union[str, None]: "su": submit_spin_up, "cs": submit_centerstage, "ou": submit_over_under, + "cr": submit_crescendo, } game_to_submit_func = { @@ -620,4 +643,5 @@ def check_time_data(score_obj: Score) -> Union[str, None]: "Spin Up": submit_spin_up, "CENTERSTAGE": submit_centerstage, "Over Under": submit_over_under, + "Crescendo": submit_crescendo, }