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
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 ) ;
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 } ;
// check for a theater flag
if ( timestamp.substring( timestamp.length-1 ) === "E" ) {
if ( scenario_theater != "ETO" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
}
if ( timestamp.substring( timestamp.length-1 ) === "P" ) {
if ( scenario_theater != "PTO" )
return "<ignore>" ;
THEATER_FLAGS = { E: "ETO", P: "PTO", B: "BURMA" } ;
var required_theater = THEATER_FLAGS[ timestamp.substring( timestamp.length-1 ) ] ;
if ( required_theater ) {
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
}
if ( timestamp.substring( timestamp.length-1 ) === "B" ) {
if ( scenario_theater != "BURMA" )
if ( scenario_theater !== required_theater )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
}
if ( timestamp.substring( timestamp.length-1 ) === "R" ) {
if ( nat != "romanian" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
}
if ( timestamp.substring( timestamp.length-2 ) === "CS" ) {
if ( nat != "croatian" && nat != "slovakian" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-2 ) ;
}
if ( timestamp.substring( timestamp.length-1 ) === "S" ) {
if ( nat != "slovakian" )
return "<ignore>" ;
timestamp = timestamp.substring( 0, timestamp.length-1 ) ;
// check for a nationality flag
NAT_FLAGS = { R: ["romanian"], S: ["slovakian"], CS: ["croatian","slovakian"] } ;
for ( var i=2 ; i >= 1 ; --i ) {
var required_nats = NAT_FLAGS[ timestamp.substring( timestamp.length-i ) ];
if ( required_nats ) {
timestamp = timestamp.substring( 0, timestamp.length-i ) ;
if ( required_nats.indexOf( nat ) === -1 )
return "<ignore>" ;
break ;
}
}
// 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" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True )
assert "s5[!]" not in val
ordnance = [ "romanian", "ordnance", "G obr. 38" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1941", merge_common=True )
assert "s5[!]" in val
ordnance = [ "slovakian", "ordnance", "G obr. 38" ]
@ -489,7 +488,6 @@ def test_nationality_capabilities( webapp, webdriver ):
ordnance = [ "slovakian", "ordnance", "Kanon PUV vz. 37(t)" ]
val = _get_capabilities( webdriver, webapp, *ordnance, "ETO", "01/1940", merge_common=True )
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 )
assert "A4" in val
ordnance = [ "croatian", "ordnance", "Kanon PUV vz. 37(t)" ]

Loading…
Cancel
Save