Update the UI to indicate whether PF/BAZ/ATMM are available or not.

master
Pacman Ghost 6 years ago
parent 57d3bd4afe
commit fa84702394
  1. BIN
      vasl_templates/webapp/static/images/snippet-disabled.png
  2. 4
      vasl_templates/webapp/static/main.js
  3. 57
      vasl_templates/webapp/static/snippets.js
  4. 32
      vasl_templates/webapp/tests/test_ob.py

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@ -78,6 +78,7 @@ $(document).ready( function () {
showAnim: "slideDown",
changeMonth: true, changeYear: true,
defaultDate: "01/01/1940",
onClose: on_scenario_date_change,
} ) ;
// initialize the SSR's
@ -283,6 +284,9 @@ $(document).ready( function () {
// initialize hotkeys
init_hotkeys() ;
// update the UI
on_scenario_date_change() ;
// add some dummy links for the test suite to edit templates
if ( getUrlParam( "edit_template_links" ) ) {
$("button.generate").each( function() {

@ -129,18 +129,12 @@ function generate_snippet( $btn, extra_params )
}
// check for date-specific parameters
if ( template_id === "pf" ) {
if ( params.SCENARIO_DATE === "" || params.SCENARIO_YEAR <= 1942 || (params.SCENARIO_YEAR == 1943 && params.SCENARIO_MONTH <= 9) )
showWarningMsg( "PF are only available after September 1943." ) ;
}
if ( template_id === "baz" ) {
if ( params.SCENARIO_DATE === "" || params.SCENARIO_YEAR <= 1941 || (params.SCENARIO_YEAR == 1942 && params.SCENARIO_MONTH < 11) )
showWarningMsg( "BAZ are only available from November 1942." ) ;
}
if ( template_id === "atmm" ) {
if ( params.SCENARIO_DATE === "" || params.SCENARIO_YEAR < 1944 )
showWarningMsg( "ATMM are only available from 1944." ) ;
}
if ( template_id === "pf" && ! is_pf_available() )
showWarningMsg( "PF are only available after September 1943." ) ;
if ( template_id === "baz" && ! is_baz_available() )
showWarningMsg( "BAZ are only available from November 1942." ) ;
if ( template_id === "atmm" && ! is_atmm_available() )
showWarningMsg( "ATMM are only available from 1944." ) ;
// add in any extra parameters
if ( extra_params )
@ -809,3 +803,42 @@ function do_load_template_pack( fname, data )
}
}
// --------------------------------------------------------------------
function _is_scenario_after( month, year ) {
// check if the scenario is after the specified month/year
var scenario_date = $("input[name='SCENARIO_DATE']").datepicker( "getDate" ) ;
if ( ! scenario_date )
return false ;
if ( scenario_date.getFullYear() > year )
return true ;
if ( scenario_date.getFullYear() < year )
return false ;
return (scenario_date.getMonth() >= month) ;
}
function is_pf_available() { return _is_scenario_after( 9, 1943 ) ; }
function is_baz_available() { return _is_scenario_after( 10, 1942 ) ; }
function is_atmm_available() { return _is_scenario_after( 0, 1944 ) ; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function on_scenario_date_change()
{
// update the UI
// NOTE: We update the visual appearance of the buttons to indicate whether
// the support weapons are available, but leave the buttons active since
// the date restrictions are not strict, and the SW are sometimes available
// (by SSR) even outside the normal time.
function update_ui( id, is_available ) {
var $btn = $( "button.generate[data-id='" + id + "']" ) ;
$btn.css( "color", is_available?"#000":"#aaa" ) ;
$btn.children( "img" ).each( function() {
$(this).attr( "src", gImagesBaseUrl + (is_available?"/snippet.png":"/snippet-disabled.png") ) ;
} ) ;
}
update_ui( "pf", is_pf_available() ) ;
update_ui( "baz", is_baz_available() ) ;
update_ui( "atmm", is_atmm_available() ) ;
}

@ -115,10 +115,13 @@ def test_nationality_specific( webapp, webdriver ):
assert get_clipboard() == expected
# check if a warning was issued
last_warning = get_stored_msg( "_last-warning_" ) or ""
image_url = find_child( "img", pf_btn ).get_attribute( "src" )
if warning:
assert last_warning.startswith( "PF are only available" )
assert "snippet-disabled.png" in image_url
else:
assert last_warning == ""
assert "snippet.png" in image_url
do_test( (1942,1), "PF: range=[1] ; check=[2] (drm=[+1]) ; col=[OBCOL:german]/[OBCOL2:german]", True )
do_test( (1943,9), "PF: range=[1] ; check=[2] (drm=[+1]) ; col=[OBCOL:german]/[OBCOL2:german]", True )
do_test( (1943,10), "PF: range=[1] ; check=[3] ; col=[OBCOL:german]/[OBCOL2:german]", False )
@ -140,10 +143,13 @@ def test_nationality_specific( webapp, webdriver ):
assert get_clipboard() == expected
# check if a warning was issued
last_warning = get_stored_msg( "_last-warning_" ) or ""
image_url = find_child( "img", baz_btn ).get_attribute( "src" )
if expected == "BAZ: none":
assert last_warning.startswith( "BAZ are only available" )
assert "snippet-disabled.png" in image_url
else:
assert last_warning == ""
assert "snippet.png" in image_url
do_test( (1941,1), "BAZ: none" )
do_test( (1942,10), "BAZ: none" )
do_test( (1942,11), "BAZ: '43 ; range=[4] ; X#=[10] ; TK#=[13] ; col=[OBCOL:american]/[OBCOL2:american]" )
@ -156,13 +162,37 @@ def test_nationality_specific( webapp, webdriver ):
"BAZ: '45 ; range=[5] ; X#=[11] ; TK#=[16] ; WP#=[6] ; col=[OBCOL:american]/[OBCOL2:american]"
)
# initialize
def check_atmm_snippets():
"""Check that the ATMM snippets are generated correctly."""
atmm_btn = find_child( "button[data-id='atmm']" )
def do_test( date, available ): #pylint: disable=missing-docstring
# test snippet generation
set_scenario_date( date )
select_tab( "ob1" )
atmm_btn.click()
assert get_clipboard() == "Kaboom!!! ; col=[OBCOL:german]/[OBCOL2:german]"
# check if a warning was issued
last_warning = get_stored_msg( "_last-warning_" ) or ""
image_url = find_child( "img", atmm_btn ).get_attribute( "src" )
if not available:
assert last_warning.startswith( "ATMM are only available" )
assert "snippet-disabled.png" in image_url
else:
assert last_warning == ""
assert "snippet.png" in image_url
do_test( (1943,12), False )
do_test( (1944,1), True )
do_test( (1944,12), True )
do_test( (1945,1), True )
# initialize
nationality_specific_buttons = {
"mol": [ "russian", "Burn, baby, burn! ; col=[OBCOL:russian]/[OBCOL2:russian]" ],
"mol-p": [ "russian", "mol-p template ; col=[OBCOL:russian]/[OBCOL2:russian]" ],
"pf": [ "german", check_pf_snippets ],
"psk": [ "german", "====> whoosh! ; col=[OBCOL:german]/[OBCOL2:german]" ],
"atmm": [ "german", "Kaboom!!! ; col=[OBCOL:german]/[OBCOL2:german]" ],
"atmm": [ "german", check_atmm_snippets ],
"baz": [ "american", check_baz_snippets ],
"piat": [ "british", "piat template ; col=[OBCOL:british]/[OBCOL2:british]" ],
}

Loading…
Cancel
Save