From ff0f40b22b90d2ec5582fa329eaf05e0bfe0d3d0 Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 16 Jul 2022 22:14:02 +1000 Subject: [PATCH] Tightened up how we map ASA theaters to our own. --- .../webapp/data/asl-scenario-archive.json | 5 ++- vasl_templates/webapp/static/scenarios.js | 42 ++++++++++++------- .../tests/fixtures/asl-scenario-archive.json | 25 ++++++++++- .../webapp/tests/test_scenario_search.py | 42 +++++++++++-------- 4 files changed, 80 insertions(+), 34 deletions(-) diff --git a/vasl_templates/webapp/data/asl-scenario-archive.json b/vasl_templates/webapp/data/asl-scenario-archive.json index 5dc7fdb..dd945df 100644 --- a/vasl_templates/webapp/data/asl-scenario-archive.json +++ b/vasl_templates/webapp/data/asl-scenario-archive.json @@ -1,11 +1,12 @@ { "_comment_": "This section maps theaters from those at the ASL Scenario Archive to ours.", +"_comment2_": "CBI is handled in getEffectiveTheater().", "theater-mappings": { + "WTO": "ETO", "MTO": "ETO", "Normandy": "ETO", - "KW": "Korea", - "CBI": "PTO" + "KW": "Korea" }, "_comment_": "This section maps player nationalities from those at the ASL Scenario Archive (must be lower-case) to our nationality ID's.", diff --git a/vasl_templates/webapp/static/scenarios.js b/vasl_templates/webapp/static/scenarios.js index bad59ba..74c01de 100644 --- a/vasl_templates/webapp/static/scenarios.js +++ b/vasl_templates/webapp/static/scenarios.js @@ -525,7 +525,7 @@ function insertPlayerFlags( $target, scenario ) function loadObaInfo( $target, scenario, scenarioDateOverride ) { // initialize - var theater = getEffectiveTheater( scenario.theater ) ; + var theater = getEffectiveTheater( scenario.theater, scenario ) ; var scenarioDate = scenario.scenario_date_iso ; if ( ! theater || ( !scenarioDate && !scenarioDateOverride ) ) return ; @@ -613,7 +613,7 @@ function onImportScenario() // check for warnings for the next field var newVal = trimString( scenario[ importField.key ] ) ; 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.substring(0,2) == "!=" ) newVal = msg.substring( 2 ) ; @@ -723,7 +723,7 @@ function doImportScenario( scenario ) if ( $elem.length > 0 && ! $elem.prop("checked") ) return ; 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 @@ -766,7 +766,7 @@ function onCancelImportScenario() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function checkImportField_text( importField, newVal, warnings2 ) { +function checkImportField_text( importField, newVal, scenario ) { return null ; } @@ -775,17 +775,17 @@ function getImportFieldCurrVal_text( importField ) { return $( "input[name='" + importField.paramName + "']" ).val().trim() ; } -function doImportField_text( importField, newVal ) { +function doImportField_text( importField, newVal, scenario ) { // update the field in the scenario $( "input[name='" + importField.paramName + "']" ).val( newVal ) ; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function checkImportField_select2( importField, newVal, warnings2 ) { +function checkImportField_select2( importField, newVal, scenario ) { if ( importField.paramName == "SCENARIO_THEATER" ) { // check if we will be able to import this theater - if ( newVal && ! getEffectiveTheater( newVal ) ) { + if ( newVal && ! getEffectiveTheater( newVal, scenario ) ) { // nope - issue a warning return "Unknown theater: " + newVal ; } @@ -802,11 +802,11 @@ function getImportFieldCurrVal_select2( importField ) { return $( "select[name='" + importField.paramName + "']" ).val().trim() ; } -function doImportField_select2( importField, newVal ) { +function doImportField_select2( importField, newVal, scenario ) { // update the field in the scenario if ( importField.paramName == "SCENARIO_THEATER" ) { if ( newVal ) { - newVal = getEffectiveTheater( newVal ) ; + newVal = getEffectiveTheater( newVal, scenario ) ; if ( ! newVal ) newVal = "other" ; } @@ -820,9 +820,23 @@ function doImportField_select2( importField, newVal ) { $elem.val( newVal ).trigger( "change" ) ; } -function getEffectiveTheater( theater ) { +function getEffectiveTheater( theater, scenario ) { if ( gAppConfig.THEATERS.indexOf( theater ) !== -1 ) 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 ] ; if ( theater ) return theater ; @@ -831,7 +845,7 @@ function getEffectiveTheater( theater ) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function checkImportField_date( importField, newVal, warnings2 ) { +function checkImportField_date( importField, newVal, scenario ) { return null ; } @@ -845,7 +859,7 @@ function getImportFieldCurrVal_date( importField ) { return [ scenarioDate[3], scenarioDate[4] ] ; } -function doImportField_date( importField, newVal ) { +function doImportField_date( importField, newVal, scenario ) { // update the field in the scenario var $elem = $( "input[name='" + importField.paramName + "']" ) ; $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 if ( 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." ] ; } -function doImportField_player( importField, newVal ) { +function doImportField_player( importField, newVal, scenario ) { // update the player's nationality in the scenario var effectiveNat = getEffectivePlayerNat( newVal ) ; if ( ! effectiveNat ) diff --git a/vasl_templates/webapp/tests/fixtures/asl-scenario-archive.json b/vasl_templates/webapp/tests/fixtures/asl-scenario-archive.json index d22c208..b4fc04e 100644 --- a/vasl_templates/webapp/tests/fixtures/asl-scenario-archive.json +++ b/vasl_templates/webapp/tests/fixtures/asl-scenario-archive.json @@ -76,10 +76,33 @@ }, { "scenario_id": "3a", + "title": "WTO Scenario", + "theatre": "WTO" +}, +{ "scenario_id": "3b", "title": "MTO Scenario", "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", "theatre": "Africa" }, diff --git a/vasl_templates/webapp/tests/test_scenario_search.py b/vasl_templates/webapp/tests/test_scenario_search.py index aaa6ced..57ff7d5 100644 --- a/vasl_templates/webapp/tests/test_scenario_search.py +++ b/vasl_templates/webapp/tests/test_scenario_search.py @@ -271,27 +271,35 @@ def test_oba_info( webapp, webdriver ): # --------------------------------------------------------------------- -def test_unknown_theaters( webapp, webdriver ): - """Test importing scenarios with unknown theaters.""" +def test_asa_theater_mappings( webapp, webdriver ): + """Test mapping ASA theaters.""" # initialize init_webapp( webapp, webdriver ) - # search for the "MTO" scenario (this has a theater mapping) - set_theater( "Korea" ) - dlg = _do_scenario_search( "MTO", ["3a"], webdriver ) - _click_import_button( dlg ) - wait_for( 2, lambda: not dlg.is_displayed() ) - assert get_theater() == "ETO" - - # search for the "Africa" scenario (this has no theater mapping) - new_scenario() - set_theater( "Korea" ) - dlg = _do_scenario_search( "Africa", ["3b"], webdriver ) - _click_import_button( dlg ) - _check_warnings( [], ["Unknown theater: Africa"] ) - find_child( "button.confirm-import", dlg ).click() - assert get_theater() == "other" + def do_test( query, scenario_id, expected, warning=None ): + new_scenario() + set_theater( "DTO" ) + dlg = _do_scenario_search( query, [scenario_id], webdriver ) + _click_import_button( dlg ) + if warning: + _check_warnings( [], [warning] ) + find_child( "button.confirm-import", dlg ).click() + wait_for( 2, lambda: not dlg.is_displayed() ) + assert get_theater() == expected + + # test some basic theater mappings + do_test( "WTO", "3a", "ETO" ) + do_test( "MTO", "3b", "ETO" ) + 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" ) # ---------------------------------------------------------------------