From 5936567a9877e4b11b02a11c3e54b83391694d78 Mon Sep 17 00:00:00 2001 From: Taka Date: Tue, 4 May 2021 08:03:54 +1000 Subject: [PATCH] Added a check for invalid nationalities in a save file. --- vasl_templates/webapp/static/snippets.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index d2398ea..46781b1 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -1614,13 +1614,26 @@ function do_load_scenario_data( params ) return $elem ; } ; // FUDGE! We must set the players first, since changing these will reset the OB tabs. + function is_valid_player_id( player_nat ) { + return gTemplatePack.nationalities[ player_nat ] !== undefined ; + } if ( "PLAYER_1" in params ) { - set_param( $("select[name='PLAYER_1']"), "PLAYER_1" ) ; - on_player_change( 1 ) ; + if ( is_valid_player_id( params.PLAYER_1 ) ) { + set_param( $("select[name='PLAYER_1']"), "PLAYER_1" ) ; + on_player_change( 1 ) ; + } else { + showErrorMsg( "Invalid player nationality: " + params.PLAYER_1 ) ; + params_loaded.PLAYER_1 = true ; + } } if ( "PLAYER_2" in params ) { - set_param( $("select[name='PLAYER_2']"), "PLAYER_2" ) ; - on_player_change( 2 ) ; + if ( is_valid_player_id( params.PLAYER_2 ) ) { + set_param( $("select[name='PLAYER_2']"), "PLAYER_2" ) ; + on_player_change( 2 ) ; + } else { + showErrorMsg( "Invalid player nationality: " + params.PLAYER_2 ) ; + params_loaded.PLAYER_2 = true ; + } } var i ; for ( var key in params ) {