Tightened up how we map ASA theaters to our own.

master
Pacman Ghost 2 years ago
parent 55c15e5157
commit ff0f40b22b
  1. 5
      vasl_templates/webapp/data/asl-scenario-archive.json
  2. 42
      vasl_templates/webapp/static/scenarios.js
  3. 25
      vasl_templates/webapp/tests/fixtures/asl-scenario-archive.json
  4. 42
      vasl_templates/webapp/tests/test_scenario_search.py

@ -1,11 +1,12 @@
{ {
"_comment_": "This section maps theaters from those at the ASL Scenario Archive to ours.", "_comment_": "This section maps theaters from those at the ASL Scenario Archive to ours.",
"_comment2_": "CBI is handled in getEffectiveTheater().",
"theater-mappings": { "theater-mappings": {
"WTO": "ETO",
"MTO": "ETO", "MTO": "ETO",
"Normandy": "ETO", "Normandy": "ETO",
"KW": "Korea", "KW": "Korea"
"CBI": "PTO"
}, },
"_comment_": "This section maps player nationalities from those at the ASL Scenario Archive (must be lower-case) to our nationality ID's.", "_comment_": "This section maps player nationalities from those at the ASL Scenario Archive (must be lower-case) to our nationality ID's.",

@ -525,7 +525,7 @@ function insertPlayerFlags( $target, scenario )
function loadObaInfo( $target, scenario, scenarioDateOverride ) function loadObaInfo( $target, scenario, scenarioDateOverride )
{ {
// initialize // initialize
var theater = getEffectiveTheater( scenario.theater ) ; var theater = getEffectiveTheater( scenario.theater, scenario ) ;
var scenarioDate = scenario.scenario_date_iso ; var scenarioDate = scenario.scenario_date_iso ;
if ( ! theater || ( !scenarioDate && !scenarioDateOverride ) ) if ( ! theater || ( !scenarioDate && !scenarioDateOverride ) )
return ; return ;
@ -613,7 +613,7 @@ function onImportScenario()
// check for warnings for the next field // check for warnings for the next field
var newVal = trimString( scenario[ importField.key ] ) ; var newVal = trimString( scenario[ importField.key ] ) ;
if ( newVal ) { if ( newVal ) {
var msg = eval( "checkImportField_" + importField.type )( importField, newVal ) ; // jshint ignore: line var msg = eval( "checkImportField_" + importField.type )( importField, newVal, scenario ) ; // jshint ignore: line
if ( msg ) { if ( msg ) {
if ( msg.substring(0,2) == "!=" ) if ( msg.substring(0,2) == "!=" )
newVal = msg.substring( 2 ) ; newVal = msg.substring( 2 ) ;
@ -723,7 +723,7 @@ function doImportScenario( scenario )
if ( $elem.length > 0 && ! $elem.prop("checked") ) if ( $elem.length > 0 && ! $elem.prop("checked") )
return ; return ;
var newVal = scenario[ importField.key ] ; var newVal = scenario[ importField.key ] ;
eval( "doImportField_" + importField.type )( importField, newVal ) ; // jshint ignore: line eval( "doImportField_" + importField.type )( importField, newVal, scenario ) ; // jshint ignore: line
} ) ; } ) ;
// update for the newly-connected scenario // update for the newly-connected scenario
@ -766,7 +766,7 @@ function onCancelImportScenario()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkImportField_text( importField, newVal, warnings2 ) { function checkImportField_text( importField, newVal, scenario ) {
return null ; return null ;
} }
@ -775,17 +775,17 @@ function getImportFieldCurrVal_text( importField ) {
return $( "input[name='" + importField.paramName + "']" ).val().trim() ; return $( "input[name='" + importField.paramName + "']" ).val().trim() ;
} }
function doImportField_text( importField, newVal ) { function doImportField_text( importField, newVal, scenario ) {
// update the field in the scenario // update the field in the scenario
$( "input[name='" + importField.paramName + "']" ).val( newVal ) ; $( "input[name='" + importField.paramName + "']" ).val( newVal ) ;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkImportField_select2( importField, newVal, warnings2 ) { function checkImportField_select2( importField, newVal, scenario ) {
if ( importField.paramName == "SCENARIO_THEATER" ) { if ( importField.paramName == "SCENARIO_THEATER" ) {
// check if we will be able to import this theater // check if we will be able to import this theater
if ( newVal && ! getEffectiveTheater( newVal ) ) { if ( newVal && ! getEffectiveTheater( newVal, scenario ) ) {
// nope - issue a warning // nope - issue a warning
return "Unknown theater: " + newVal ; return "Unknown theater: " + newVal ;
} }
@ -802,11 +802,11 @@ function getImportFieldCurrVal_select2( importField ) {
return $( "select[name='" + importField.paramName + "']" ).val().trim() ; return $( "select[name='" + importField.paramName + "']" ).val().trim() ;
} }
function doImportField_select2( importField, newVal ) { function doImportField_select2( importField, newVal, scenario ) {
// update the field in the scenario // update the field in the scenario
if ( importField.paramName == "SCENARIO_THEATER" ) { if ( importField.paramName == "SCENARIO_THEATER" ) {
if ( newVal ) { if ( newVal ) {
newVal = getEffectiveTheater( newVal ) ; newVal = getEffectiveTheater( newVal, scenario ) ;
if ( ! newVal ) if ( ! newVal )
newVal = "other" ; newVal = "other" ;
} }
@ -820,9 +820,23 @@ function doImportField_select2( importField, newVal ) {
$elem.val( newVal ).trigger( "change" ) ; $elem.val( newVal ).trigger( "change" ) ;
} }
function getEffectiveTheater( theater ) { function getEffectiveTheater( theater, scenario ) {
if ( gAppConfig.THEATERS.indexOf( theater ) !== -1 ) if ( gAppConfig.THEATERS.indexOf( theater ) !== -1 )
return theater ; return theater ;
// NOTE: The ASL Scenario Archive has a bunch of different theaters, which we try to map to ours.
// The most common ones are:
// - WTO: places like France, Holland, Belgium, so I think "Western Theatre Of Operations"
// - MTO: places like Sicily, Italy, Greece, so I think "Mediterranean Theatre Of Operations"
if ( theater === "CBI" ) {
// I think this is "China, Burma, India", but this one is tricky since we can't just
// map it to PTO, since we have "Burma" as a separate theatre. We peek at the scenario
// location to figure out what to do.
var loc = scenario.scenario_location || "" ;
if ( loc.indexOf( "Burma" ) !== -1 )
return "Burma" ;
// NOTE: It's debatable whether scenarios in India should be considered PTO, but why not...
return "PTO" ;
}
theater = gAppConfig.SCENARIOS_CONFIG["theater-mappings"][ theater ] ; theater = gAppConfig.SCENARIOS_CONFIG["theater-mappings"][ theater ] ;
if ( theater ) if ( theater )
return theater ; return theater ;
@ -831,7 +845,7 @@ function getEffectiveTheater( theater ) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkImportField_date( importField, newVal, warnings2 ) { function checkImportField_date( importField, newVal, scenario ) {
return null ; return null ;
} }
@ -845,7 +859,7 @@ function getImportFieldCurrVal_date( importField ) {
return [ scenarioDate[3], scenarioDate[4] ] ; return [ scenarioDate[3], scenarioDate[4] ] ;
} }
function doImportField_date( importField, newVal ) { function doImportField_date( importField, newVal, scenario ) {
// update the field in the scenario // update the field in the scenario
var $elem = $( "input[name='" + importField.paramName + "']" ) ; var $elem = $( "input[name='" + importField.paramName + "']" ) ;
$elem.datepicker( "setDate", $elem.datepicker( "setDate",
@ -855,7 +869,7 @@ function doImportField_date( importField, newVal ) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkImportField_player( importField, newVal, warnings2 ) { function checkImportField_player( importField, newVal, scenario ) {
// check if we will be able to import this player // check if we will be able to import this player
if ( newVal ) { if ( newVal ) {
var effectiveNat = getEffectivePlayerNat( newVal ) ; var effectiveNat = getEffectivePlayerNat( newVal ) ;
@ -881,7 +895,7 @@ function getImportFieldCurrVal_player( importField ) {
return [ currVal, get_nationality_display_name(currVal), "This player's OB will be removed." ] ; return [ currVal, get_nationality_display_name(currVal), "This player's OB will be removed." ] ;
} }
function doImportField_player( importField, newVal ) { function doImportField_player( importField, newVal, scenario ) {
// update the player's nationality in the scenario // update the player's nationality in the scenario
var effectiveNat = getEffectivePlayerNat( newVal ) ; var effectiveNat = getEffectivePlayerNat( newVal ) ;
if ( ! effectiveNat ) if ( ! effectiveNat )

@ -76,10 +76,33 @@
}, },
{ "scenario_id": "3a", { "scenario_id": "3a",
"title": "WTO Scenario",
"theatre": "WTO"
},
{ "scenario_id": "3b",
"title": "MTO Scenario", "title": "MTO Scenario",
"theatre": "MTO" "theatre": "MTO"
}, },
{ "scenario_id": "3b", { "scenario_id": "3c",
"title": "KFW Scenario",
"theatre": "KW"
},
{ "scenario_id": "3d1",
"title": "CBI(China) Scenario",
"scen_location": "Somewhere in China",
"theatre": "CBI"
},
{ "scenario_id": "3d2",
"title": "CBI(Burma) Scenario",
"scen_location": "Somewhere in Burma",
"theatre": "CBI"
},
{ "scenario_id": "3d3",
"title": "CBI(India) Scenario",
"scen_location": "Somewhere in India",
"theatre": "CBI"
},
{ "scenario_id": "3e",
"title": "African Scenario", "title": "African Scenario",
"theatre": "Africa" "theatre": "Africa"
}, },

@ -271,27 +271,35 @@ def test_oba_info( webapp, webdriver ):
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
def test_unknown_theaters( webapp, webdriver ): def test_asa_theater_mappings( webapp, webdriver ):
"""Test importing scenarios with unknown theaters.""" """Test mapping ASA theaters."""
# initialize # initialize
init_webapp( webapp, webdriver ) init_webapp( webapp, webdriver )
# search for the "MTO" scenario (this has a theater mapping) def do_test( query, scenario_id, expected, warning=None ):
set_theater( "Korea" ) new_scenario()
dlg = _do_scenario_search( "MTO", ["3a"], webdriver ) set_theater( "DTO" )
_click_import_button( dlg ) dlg = _do_scenario_search( query, [scenario_id], webdriver )
wait_for( 2, lambda: not dlg.is_displayed() ) _click_import_button( dlg )
assert get_theater() == "ETO" if warning:
_check_warnings( [], [warning] )
# search for the "Africa" scenario (this has no theater mapping) find_child( "button.confirm-import", dlg ).click()
new_scenario() wait_for( 2, lambda: not dlg.is_displayed() )
set_theater( "Korea" ) assert get_theater() == expected
dlg = _do_scenario_search( "Africa", ["3b"], webdriver )
_click_import_button( dlg ) # test some basic theater mappings
_check_warnings( [], ["Unknown theater: Africa"] ) do_test( "WTO", "3a", "ETO" )
find_child( "button.confirm-import", dlg ).click() do_test( "MTO", "3b", "ETO" )
assert get_theater() == "other" do_test( "KFW", "3c", "Korea" )
# test mapping CBI scenarios
do_test( "China", "3d1", "PTO" )
do_test( "Burma", "3d2", "Burma" )
do_test( "India", "3d3", "PTO" )
# test a theater that has no mapping
do_test( "Africa", "3e", "other", warning="Unknown theater: Africa" )
# --------------------------------------------------------------------- # ---------------------------------------------------------------------

Loading…
Cancel
Save