Tightened up how capability theater/nationality superscripts are parsed.

master
Pacman Ghost 5 years ago
parent 635c6d5093
commit 5f234fc9a5
  1. 46
      vasl_templates/webapp/static/snippets.js
  2. 2
      vasl_templates/webapp/tests/test_capabilities.py

@ -878,6 +878,11 @@ function make_capabilities( raw, vo_entry, vo_type, nat, elite, scenario_theater
} }
// check if we should return the raw capability, or select the one for the scenario date // check if we should return the raw capability, or select the one for the scenario date
if ( ! scenario_year ) { if ( ! scenario_year ) {
// NOTE: We should really check for theater/nationality flags here (e.g. perhaps by calling
// _check_capability_timestamp()), but at this stage (just before the v1.0 release),
// it's not worth the risk. The superscripts will still appear in the UI/snippets,
// so we're not completely doing the wrong thing, and in practice, the scenario date
// will always be set.
indeterminate_caps.push( key ) ; indeterminate_caps.push( key ) ;
raw = true ; raw = true ;
} }
@ -1016,35 +1021,24 @@ function _check_capability_timestamp( capabilities, timestamp, nat, scenario_the
var MONTH_NAMES = { F:2, J:6, A:8, S:9, N:11 } ; var MONTH_NAMES = { F:2, J:6, A:8, S:9, N:11 } ;
// check for a theater flag // check for a theater flag
if ( timestamp.substring( timestamp.length-1 ) === "E" ) { THEATER_FLAGS = { E: "ETO", P: "PTO", B: "BURMA" } ;
if ( scenario_theater != "ETO" ) var required_theater = THEATER_FLAGS[ timestamp.substring( timestamp.length-1 ) ] ;
return "<ignore>" ; if ( required_theater ) {
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
}
if ( timestamp.substring( timestamp.length-1 ) === "P" ) {
if ( scenario_theater != "PTO" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ; timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
} if ( scenario_theater !== required_theater )
if ( timestamp.substring( timestamp.length-1 ) === "B" ) {
if ( scenario_theater != "BURMA" )
return "<ignore>" ; return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
} }
if ( timestamp.substring( timestamp.length-1 ) === "R" ) {
if ( nat != "romanian" ) // check for a nationality flag
return "<ignore>" ; NAT_FLAGS = { R: ["romanian"], S: ["slovakian"], CS: ["croatian","slovakian"] } ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ; for ( var i=2 ; i >= 1 ; --i ) {
} var required_nats = NAT_FLAGS[ timestamp.substring( timestamp.length-i ) ];
if ( timestamp.substring( timestamp.length-2 ) === "CS" ) { if ( required_nats ) {
if ( nat != "croatian" && nat != "slovakian" ) timestamp = timestamp.substring( 0, timestamp.length-i ) ;
return "<ignore>" ; if ( required_nats.indexOf( nat ) === -1 )
timestamp = timestamp.substring( 0, timestamp.length-2 ) ; return "<ignore>" ;
} break ;
if ( timestamp.substring( timestamp.length-1 ) === "S" ) { }
if ( nat != "slovakian" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
} }
// remove any trailing "+" (FIXME! What does it even mean? Doesn't make sense :-/) // remove any trailing "+" (FIXME! What does it even mean? Doesn't make sense :-/)

@ -467,7 +467,6 @@ def test_nationality_capabilities( webapp, webdriver ):
ordnance = [ "romanian", "ordnance", "G obr. 38" ] ordnance = [ "romanian", "ordnance", "G obr. 38" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True ) val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True )
assert "s5[!]" not in val assert "s5[!]" not in val
ordnance = [ "romanian", "ordnance", "G obr. 38" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True ) val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True )
assert "s5[!]" in val assert "s5[!]" in val
ordnance = [ "slovakian", "ordnance", "G obr. 38" ] ordnance = [ "slovakian", "ordnance", "G obr. 38" ]
@ -489,7 +488,6 @@ def test_nationality_capabilities( webapp, webdriver ):
ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ] ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True ) val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True )
assert "A4" not in val assert "A4" not in val
ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True ) val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True )
assert "A4" in val assert "A4" in val
ordnance = [ "croatian", "ordnance", "Kanon PUV vz. 37(t)" ] ordnance = [ "croatian", "ordnance", "Kanon PUV vz. 37(t)" ]

Loading…
Cancel
Save