From fe3d30d2e2ea63242f99c74143cd68fe935cd914 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 14 Mar 2022 15:58:16 +1100 Subject: [PATCH] Added the Partisan nationality. --- .../national-capabilities.json | 13 +++ .../default-template-pack/nationalities.json | 6 +- vasl_templates/webapp/snippets.py | 8 +- vasl_templates/webapp/static/main.js | 103 +++++++++++------- vasl_templates/webapp/static/nat_caps.js | 15 ++- vasl_templates/webapp/static/snippets.js | 8 +- vasl_templates/webapp/static/utils.js | 6 +- .../tests/fixtures/nat-caps/partisan/1940.txt | 14 +++ .../tests/fixtures/nat-caps/partisan/1941.txt | 14 +++ .../tests/fixtures/nat-caps/partisan/1942.txt | 14 +++ .../tests/fixtures/nat-caps/partisan/1943.txt | 14 +++ .../tests/fixtures/nat-caps/partisan/1944.txt | 14 +++ .../tests/fixtures/nat-caps/partisan/1945.txt | 14 +++ .../tests/test_national_capabilities.py | 5 +- .../webapp/tests/test_vehicles_ordnance.py | 2 + vasl_templates/webapp/tests/test_vo_notes.py | 2 +- .../webapp/tests/test_vo_reports.py | 3 +- 17 files changed, 197 insertions(+), 58 deletions(-) create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1940.txt create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1941.txt create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1942.txt create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1943.txt create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1944.txt create mode 100644 vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1945.txt diff --git a/vasl_templates/webapp/data/default-template-pack/national-capabilities.json b/vasl_templates/webapp/data/default-template-pack/national-capabilities.json index 86fd580..90ad22f 100644 --- a/vasl_templates/webapp/data/default-template-pack/national-capabilities.json +++ b/vasl_templates/webapp/data/default-template-pack/national-capabilities.json @@ -188,6 +188,19 @@ ] }, +"partisan": { + "th_color": [ "Red", "[EXC: ATR/MG]" ], + "notes": [ + "Stealthy when Good Order", + "Never Elite/Inexperienced", + "ELR 5", + "Leadership NA for non-Partisan units", + "Massacre OK", + "RtPh Surrender NA", + "Disrupt NA" + ] +}, + "kfw-rok": { "th_color": "{! -08/1950 = Red | 09/1950-04/1951 = Red (ROK) ; Black (KMC) | 05/1951- = Black | ??? !}", "oba": [ "{! 06/1950- = 10B | ??? !}", "3R", diff --git a/vasl_templates/webapp/data/default-template-pack/nationalities.json b/vasl_templates/webapp/data/default-template-pack/nationalities.json index bf74dd6..7fabcdd 100644 --- a/vasl_templates/webapp/data/default-template-pack/nationalities.json +++ b/vasl_templates/webapp/data/default-template-pack/nationalities.json @@ -69,12 +69,16 @@ "ob_colors": [ "#d3edfc","#91cdf5", "#e0a22b" ] }, +"partisan": { + "display_name": "Partisan", + "ob_colors": [ "#eabe51","#d68d1a", "#d68d1a" ] +}, + "polish": { "display_name": "Polish", "ob_colors": [ "#ecd8b0","#e8cfa4", "#84e8c2" ], "type": "allied-minor" }, - "belgian": { "display_name": "Belgian", "ob_colors": [ "#a3ecd1","#82e3bd", "#61d8a6" ], diff --git a/vasl_templates/webapp/snippets.py b/vasl_templates/webapp/snippets.py index 36a70dd..6948cfb 100644 --- a/vasl_templates/webapp/snippets.py +++ b/vasl_templates/webapp/snippets.py @@ -212,8 +212,12 @@ def get_flag( nat ): # serve the standard flag fname = os.path.join( "static/images/flags/", nat+".png" ) - with app.open_resource( fname, "rb" ) as fp: - return _get_small_image( fp, key, height ) + try: + with app.open_resource( fname, "rb" ) as fp: + return _get_small_image( fp, key, height ) + except FileNotFoundError: + abort( 404 ) + return None # stop pylint from complaining :-/ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index c494a0c..5a624e8 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -1,6 +1,7 @@ gAppConfig = {} ; gDefaultTemplatePack = null ; gTemplatePack = {} ; +gHasPlayerFlag = {} ; gValidTemplateIds = [] ; gVehicleOrdnanceListings = {} ; gVehicleOrdnanceNotes = {} ; @@ -203,39 +204,6 @@ $(document).ready( function () { edit: function( $sortable2, $entry ) { edit_ob_ordnance( $entry, 2 ) ; }, } ) ; - // initialize the player droplists - function on_player_droplist_open( $sel ) { - // remember the current selection - $sel.data( "prev-val", $sel.val() ) ; - // limit the droplist's height to the available space - restrict_droplist_height( $sel ) ; - } - function format_player_droplist_item( opt ) { - if ( ! opt.id ) - return opt.text ; - var url = make_player_flag_url( opt.id, false ) ; - return $( "
" + - "
" + - "" + - "
" + - " " + opt.text + - "
" ) ; - } - init_select2( $( "select[name='PLAYER_1']" ), - "auto", false, format_player_droplist_item - ).on( "select2:open", function() { - on_player_droplist_open( $(this) ) ; - } ).on( "change", function() { - on_player_change_with_confirm( 1 ) ; - } ) ; - init_select2( $( "select[name='PLAYER_2']" ), - "auto", false, format_player_droplist_item - ).on( "select2:open", function() { - on_player_droplist_open( $(this) ) ; - } ).on( "change", function() { - on_player_change_with_confirm( 2 ) ; - } ) ; - // load the ELR's and SAN's buf = [ "" ] ; // nb: to help the user to remember to set this for ( var i=0 ; i <= 5 ; ++i ) // nb: A19.1: ELR is 0-5 @@ -343,6 +311,23 @@ $(document).ready( function () { // is the set of valid template ID's will depend on what's in it :-/ gValidTemplateIds = Object.keys( data.templates ) ; update_page_load_status( "template-pack" ) ; + // figure out which player flags are available (because some nationalities don't have one) + var nats = Object.keys( gTemplatePack.nationalities ) ; + var nFlagsChecked = 0 ; + function onFlagChecked() { + if ( ++nFlagsChecked === nats.length ) { + // we've checked all the flags - now we can build the player droplists + init_player_droplists() ; + update_page_load_status( "flag-urls" ) ; + } + } + nats.forEach( function( nat ) { + var url = make_player_flag_url( nat, false ) ; + $.ajax( url, { + success: function() { gHasPlayerFlag[nat] = true ; onFlagChecked() ; }, + error: function() { onFlagChecked() ; }, + } ) ; + } ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the template pack:
" + escapeHTML(errorMsg) + "
" ) ; update_page_load_status( "template-pack" ) ; @@ -475,6 +460,42 @@ $(document).ready( function () { $("input[name='SCENARIO_NAME']").focus().focus() ; } ) ; +function init_player_droplists() +{ + // initialize the player droplists + function on_player_droplist_open( $sel ) { + // remember the current selection + $sel.data( "prev-val", $sel.val() ) ; + // limit the droplist's height to the available space + restrict_droplist_height( $sel ) ; + } + function format_player_droplist_item( opt ) { + if ( ! opt.id ) + return opt.text ; + var url = gHasPlayerFlag[opt.id] ? make_player_flag_url( opt.id, false ) : "" ; + return $( "
" + + "
" + + "" + + "
" + + " " + opt.text + + "
" ) ; + } + init_select2( $( "select[name='PLAYER_1']" ), + "auto", false, format_player_droplist_item + ).on( "select2:open", function() { + on_player_droplist_open( $(this) ) ; + } ).on( "change", function() { + on_player_change_with_confirm( 1 ) ; + } ) ; + init_select2( $( "select[name='PLAYER_2']" ), + "auto", false, format_player_droplist_item + ).on( "select2:open", function() { + on_player_droplist_open( $(this) ) ; + } ).on( "change", function() { + on_player_change_with_confirm( 2 ) ; + } ) ; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function init_snippet_button( $btn ) @@ -553,7 +574,7 @@ gPageLoadStatus = [ "main", "app-config", "vehicle-listings", "ordnance-listings", "reset-scenario", "vehicle-notes", "ordnance-notes", "asl-rulebook2-vo-note-targets", - "vasl-piece-info", "online-counter-images", "template-pack", "default-scenario" + "vasl-piece-info", "online-counter-images", "template-pack", "flag-urls", "default-scenario" ] ; function update_page_load_status( id ) @@ -617,9 +638,6 @@ function update_page_load_status( id ) } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the startup messages:
" + escapeHTML(errorMsg) + "
" ) ; } ) ; - // preload the flag images (so that the player droplist renders immediately) - for ( var nat in gTemplatePack.nationalities ) - $.get( make_player_flag_url( nat, false ) ) ; } } @@ -697,7 +715,7 @@ function install_template_pack( data ) // update the OB tab headers // NOTE: We don't do this while the page is initially loading, it will be done when the default scenario loaded. - if ( gPageLoadStatus.indexOf( "template-pack" ) === -1 ) { + if ( gPageLoadStatus.indexOf( "flag-urls" ) === -1 ) { update_ob_tab_header( 1 ) ; update_ob_tab_header( 2 ) ; } @@ -805,10 +823,11 @@ function update_ob_tab_header( player_no ) var display_name = get_nationality_display_name( player_nat ) ; var image_url = make_player_flag_url( player_nat, false ) ; var $elem = $( "#tabs .ui-tabs-nav a[href='#tabs-ob" + player_no + "']" ) ; - $elem.html( - " " + - "" + escapeHTML(display_name) + " OB" - ) ; + var buf = [] ; + if ( gHasPlayerFlag[ player_nat ] ) + buf.push( " " ) ; + buf.push( "" + escapeHTML(display_name) + " OB" ) ; + $elem.html( buf.join("") ) ; return player_nat ; } diff --git a/vasl_templates/webapp/static/nat_caps.js b/vasl_templates/webapp/static/nat_caps.js index bb2a3f5..1cbd9d6 100644 --- a/vasl_templates/webapp/static/nat_caps.js +++ b/vasl_templates/webapp/static/nat_caps.js @@ -25,10 +25,17 @@ function set_nat_caps_params( player_nat, params ) // set the TH# color if ( nat_caps.th_color ) { if ( $.isArray( nat_caps.th_color ) ) { - add_nat_cap( "TH_COLOR", - make_time_based_comment( nat_caps.th_color[0], params.SCENARIO_MONTH, params.SCENARIO_YEAR ) + " TH#" + - " (" + nat_caps.th_color[1] + ")" - ) ; + var buf = [ + make_time_based_comment( nat_caps.th_color[0], params.SCENARIO_MONTH, params.SCENARIO_YEAR ) + " TH#", + " " + ] ; + var comment = nat_caps.th_color[ 1 ] ; + if ( comment.substring( 0, 5 ) === "[EXC:" && comment[comment.length-1] === "]" ) + buf.push( comment ) ; + else + buf.push( "(" + comment + ")" ) ; + buf.push( "" ) ; + add_nat_cap( "TH_COLOR", buf.join("") ) ; } else { var th_color = make_time_based_comment( nat_caps.th_color, params.SCENARIO_MONTH, params.SCENARIO_YEAR ) ; var match = th_color.match( /\(.+\)$/ ) ; diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 1dc247d..62d7e2a 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -157,7 +157,7 @@ function make_snippet( $btn, params, extra_params, show_date_warnings ) var colors = get_player_colors( player_no ) ; params.OB_COLOR = colors[0] ; params.OB_COLOR_2 = colors[2] ; - if ( gUserSettings["include-flags-in-snippets"] ) + if ( gUserSettings["include-flags-in-snippets"] && gHasPlayerFlag[player_nat] ) params.PLAYER_FLAG = make_player_flag_url( player_nat, true ) ; } @@ -320,8 +320,10 @@ function make_snippet( $btn, params, extra_params, show_date_warnings ) params.PLAYER_1_NAME = get_nationality_display_name( params.PLAYER_1 ) ; params.PLAYER_2_NAME = get_nationality_display_name( params.PLAYER_2 ) ; if ( gUserSettings["include-flags-in-snippets"] ) { - params.PLAYER_FLAG_1 = make_player_flag_url( get_player_nat(1), true ) ; - params.PLAYER_FLAG_2 = make_player_flag_url( get_player_nat(2), true ) ; + if ( gHasPlayerFlag[ get_player_nat( 1 ) ] ) + params.PLAYER_FLAG_1 = make_player_flag_url( get_player_nat(1), true ) ; + if ( gHasPlayerFlag[ get_player_nat( 2 ) ] ) + params.PLAYER_FLAG_2 = make_player_flag_url( get_player_nat(2), true ) ; } // pass through all the player colors and names diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 82c5be3..dd2405f 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -68,8 +68,10 @@ function make_player_flag_url( nat, for_snippet ) { return null ; if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET ) return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ; - else - return make_app_url( "/flags/" + nat, for_snippet ) ; + else { + var url = "/flags/" + nat ; + return make_app_url( url, for_snippet ) ; + } } function get_player_no_for_element( $elem ) diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1940.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1940.txt new file mode 100644 index 0000000..ea87fd4 --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1940.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1940) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1941.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1941.txt new file mode 100644 index 0000000..711aae6 --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1941.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1941) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1942.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1942.txt new file mode 100644 index 0000000..8cb859d --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1942.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1942) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1943.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1943.txt new file mode 100644 index 0000000..3e9f437 --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1943.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1943) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1944.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1944.txt new file mode 100644 index 0000000..41c956d --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1944.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1944) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1945.txt b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1945.txt new file mode 100644 index 0000000..fe555ad --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/nat-caps/partisan/1945.txt @@ -0,0 +1,14 @@ +=== partisan (ETO 1945) === + +- +HoB: - +Red TH# [EXC: ATR/MG] +OBA: - - - + +* Stealthy when Good Order +* Never Elite/Inexperienced +* ELR 5 +* Leadership NA for non-Partisan units +* Massacre OK +* RtPh Surrender NA +* Disrupt NA diff --git a/vasl_templates/webapp/tests/test_national_capabilities.py b/vasl_templates/webapp/tests/test_national_capabilities.py index e14b9a6..50f3a01 100644 --- a/vasl_templates/webapp/tests/test_national_capabilities.py +++ b/vasl_templates/webapp/tests/test_national_capabilities.py @@ -117,8 +117,9 @@ def _get_nat_caps( webapp, webdriver, nat, theater, year, month ): #pylint: disa else: assert len(elems) == 1 report[ field ] = to_text( elems[0] ).strip() - assert report["hob-drm"].startswith( "Heat of Battle: " ) - report["hob-drm"] = report["hob-drm"][16:] + if report["hob-drm"] != "-": + assert report["hob-drm"].startswith( "Heat of Battle: " ) + report["hob-drm"] = report["hob-drm"][16:] # parse the OBA comments report["oba-comments"] = [] diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index bf11948..b957b19 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -420,6 +420,8 @@ def test_common_vo( webapp, webdriver ): #pylint: disable=too-many-locals if nat == "kfw-cpva" and vo_type == "vehicles": assert not elem.is_enabled() continue + if nat == "partisan": + continue elem.click() # get the vehicles/ordnance diff --git a/vasl_templates/webapp/tests/test_vo_notes.py b/vasl_templates/webapp/tests/test_vo_notes.py index 1541e08..9a0d489 100644 --- a/vasl_templates/webapp/tests/test_vo_notes.py +++ b/vasl_templates/webapp/tests/test_vo_notes.py @@ -548,7 +548,7 @@ def test_vo_notes_reports( webapp, webdriver ): #pylint: disable=too-many-locals # get the next report vo_notes, ma_notes, keys = get_vo_notes_report( webapp, webdriver, nat, vo_type ) - if nat in ("burmese","filipino") \ + if nat in ("burmese","filipino","partisan") \ or (nat,vo_type) in [ ("landing-craft","ordnance"), ("anzac","ordnance"), ("kfw-cpva","vehicles") ]: assert not vo_notes and not ma_notes and not keys continue diff --git a/vasl_templates/webapp/tests/test_vo_reports.py b/vasl_templates/webapp/tests/test_vo_reports.py index 70aa317..310bc87 100644 --- a/vasl_templates/webapp/tests/test_vo_reports.py +++ b/vasl_templates/webapp/tests/test_vo_reports.py @@ -67,7 +67,8 @@ def test_vo_reports( webapp, webdriver ): #pylint: disable=too-many-locals if nat == "landing-craft" and vo_type == "ordnance": continue results = get_vo_report( webapp, webdriver, vo_type, nat, "ETO", year, 1 ) - if nat in ("burmese","filipino") or (nat,vo_type) in [("anzac","ordnance"),("kfw-cpva","vehicles")]: + if nat in ( "burmese", "filipino", "partisan" ) \ + or ( nat, vo_type ) in [ ("anzac","ordnance"), ("kfw-cpva","vehicles") ]: assert not results continue