Added nationality-specific templates.

master
Pacman Ghost 6 years ago
parent 6df95e46f3
commit 773fc3a46f
  1. 1
      vasl_templates/webapp/data/default-templates/atmm.j2
  2. 1
      vasl_templates/webapp/data/default-templates/baz.j2
  3. 1
      vasl_templates/webapp/data/default-templates/mol-p.j2
  4. 1
      vasl_templates/webapp/data/default-templates/mol.j2
  5. 1
      vasl_templates/webapp/data/default-templates/pf.j2
  6. 1
      vasl_templates/webapp/data/default-templates/piat.j2
  7. 1
      vasl_templates/webapp/data/default-templates/psk.j2
  8. 2
      vasl_templates/webapp/data/default-templates/scenario.j2
  9. 19
      vasl_templates/webapp/static/css/tabs-ob.css
  10. 66
      vasl_templates/webapp/static/generate.js
  11. 27
      vasl_templates/webapp/static/main.js
  12. 18
      vasl_templates/webapp/templates/main.html
  13. 4
      vasl_templates/webapp/tests/test_generate.py
  14. 115
      vasl_templates/webapp/tests/test_ob_setup.py

@ -0,0 +1 @@
BAZ: {%if BAZ_TYPE%}'{{BAZ_TYPE}} ; range=[{{BAZ_RANGE}}] ; X#=[{{BAZ_BREAKDOWN}}] ; TK#=[{{BAZ_TOKILL}}]{%if BAZ_WP%} ; WP#=[{{BAZ_WP}}]{%endif%}{%else%}none{%endif%}

@ -0,0 +1 @@
PF: range=[{{PF_RANGE}}] ; check=[{{PF_CHECK_DR}}]{%if PF_CHECK_DRM%} (drm=[{{PF_CHECK_DRM}}]){%endif%}

@ -1,3 +1,3 @@
name = [{{SCENARIO_NAME}}]
loc = [{{SCENARIO_LOCATION}}]
date = [{{SCENARIO_DATE}}]
date = [{{SCENARIO_DATE}}]{%if SCENARIO_DATE%} aka "{{SCENARIO_DAY_OF_MONTH}} {{SCENARIO_MONTH_NAME}}, {{SCENARIO_YEAR}}"{%endif%}

@ -1,14 +1,19 @@
#panel-obsetup1, #panel-obsetup2 {
.panel-obsetup {
height: 100% ;
display: grid ; display: -ms-grid ;
grid-template-rows: 1fr 2em ; -ms-grid-rows: 1fr 2em ;
grid-template-columns: 1fr ; -ms-grid-columns: 1fr ;
}
/* FUDGE! IE hackamathon follows (nb: <label> doesn't work, we use <div> for labels instead :-/) */
#panel-obsetup1 .footer, #panel-obsetup2 .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
.panel-obsetup .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
#panel-obsetup1 textarea { width: 100% ; height: 100% ; resize: none ; }
#panel-obsetup1 input[type="button"] { float: right ; }
#panel-obsetup2 textarea { width: 100% ; height: 100% ; resize: none ; }
#panel-obsetup2 input[type="button"] { float: right ; }
.panel-obsetup textarea { width: 100% ; height: 100% ; resize: none ; }
.panel-obsetup input[type="button"][data-id='mol'] { float: left ; }
.panel-obsetup input[type="button"][data-id='mol-p'] { float: left ; }
.panel-obsetup input[type="button"][data-id='pf'] { float: left ; }
.panel-obsetup input[type="button"][data-id='psk'] { float: left ; }
.panel-obsetup input[type="button"][data-id='atmm'] { float: left ; }
.panel-obsetup input[type="button"][data-id='baz'] { float: left ; }
.panel-obsetup input[type="button"][data-id='piat'] { float: left ; }
.panel-obsetup input[type="button"][data-id='ob_setup_1'] { float: right ; }
.panel-obsetup input[type="button"][data-id='ob_setup_2'] { float: right ; }

@ -4,10 +4,20 @@ var _MANDATORY_PARAMS = {
scenario: { "SCENARIO_NAME": "scenario name", "SCENARIO_DATE": "scenario date" },
} ;
var _MONTH_NAMES = [ // nb: we assume English :-/
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
] ;
// --------------------------------------------------------------------
function generate_snippet( $btn )
{
// initialize
storeMsgForTestSuite( "_last-info_", "" ) ;
storeMsgForTestSuite( "_last-warning_", "" ) ;
storeMsgForTestSuite( "_last-error_", "" ) ;
// collect all the template parameters
var params = {} ;
add_param = function($elem) { params[ $elem.attr("name").toUpperCase() ] = $elem.val() ; } ;
@ -15,7 +25,7 @@ function generate_snippet( $btn )
$("textarea.param").each( function() { add_param($(this)) ; } ) ;
$("select.param").each( function() { add_param($(this)) ; } ) ;
// figore out which template to use
// figure out which template to use
var template_id = $btn.data( "id" ) ;
if ( template_id === "ob_setup_1" ) {
template_id = "ob_setup" ;
@ -52,6 +62,60 @@ function generate_snippet( $btn )
}
}
// extract the scenario date components
var scenario_date = $("input[name='scenario_date']").datepicker( "getDate" ) ;
if ( scenario_date ) {
params.SCENARIO_DAY_OF_MONTH = scenario_date.getDate() ;
params.SCENARIO_MONTH = 1 + scenario_date.getMonth() ;
params.SCENARIO_MONTH_NAME = _MONTH_NAMES[scenario_date.getMonth()] ;
params.SCENARIO_YEAR = scenario_date.getFullYear() ;
}
// generate PF parameters
if ( params.SCENARIO_YEAR < 1944 || (params.SCENARIO_YEAR == 1944 && params.SCENARIO_MONTH < 6) )
params.PF_RANGE = 1 ;
else if ( params.SCENARIO_YEAR == 1944 )
params.PF_RANGE = 2 ;
else
params.PF_RANGE = 3 ;
if ( params.SCENARIO_YEAR < 1943 || (params.SCENARIO_YEAR == 1943 && params.SCENARIO_MONTH <= 9) ) {
params.PF_CHECK_DRM = "+1" ;
params.PF_CHECK_DR = 4 ;
} else if ( params.SCENARIO_YEAR >= 1945 ) {
params.PF_CHECK_DRM = "-1" ;
params.PF_CHECK_DR = 4 ;
} else {
params.PF_CHECK_DRM = "" ;
params.PF_CHECK_DR = 3 ;
}
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." ) ;
}
// generate BAZ parameters
if ( params.SCENARIO_YEAR >= 1945 ) {
params.BAZ_TYPE = 45 ;
params.BAZ_BREAKDOWN = 11 ;
params.BAZ_TOKILL = 16 ;
params.BAZ_WP = 6 ;
params.BAZ_RANGE = 5 ;
} else if ( params.SCENARIO_YEAR >= 1944 ) {
params.BAZ_TYPE = 44 ;
params.BAZ_BREAKDOWN = 11 ;
params.BAZ_TOKILL = 16 ;
params.BAZ_RANGE = 4 ;
} else if ( params.SCENARIO_YEAR == 1943 || (params.SCENARIO_YEAR == 1942 && params.SCENARIO_MONTH >= 11) ) {
params.BAZ_TYPE = 43 ;
params.BAZ_BREAKDOWN = 10 ;
params.BAZ_TOKILL = 13 ;
params.BAZ_RANGE = 4 ;
}
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." ) ;
}
// check that the players have different nationalities
if ( params.PLAYER_1 === params.PLAYER_2 )
showWarningMsg( "Both players have the same nationality!" ) ;

@ -1,6 +1,13 @@
var gNationalities = {} ;
var gDefaultTemplates = {} ;
var _NATIONALITY_SPECIFIC_BUTTONS = {
"russian": [ "mol", "mol-p" ],
"german": [ "pf", "psk", "atmm" ],
"american": [ "baz" ],
"british": [ "piat" ],
} ;
// --------------------------------------------------------------------
$(document).ready( function () {
@ -12,6 +19,13 @@ $(document).ready( function () {
var navHeight = $("#tabs .ui-tabs-nav").height() ;
$("input[name='scenario_name']").focus().focus() ;
// initialize
$("input[name='scenario_date']").datepicker( {
showAnim: "slideDown",
changeMonth: true, changeYear: true,
defaultDate: "01/01/1940",
} ) ;
// initialize
$("#ssr-sortable").sortable( { connectWith: "#ssr-trash", cursor: "move" } ) ;
init_ssr( $("#ssr-sortable li") ) ;
@ -106,7 +120,16 @@ function on_player_change( $select )
var player_id = name.substring( name.length-1 ) ;
// update the tab label
var nat = $select.find( "option:selected" ).val() ;
var player_nat = $select.find( "option:selected" ).val() ;
var $elem = $("#tabs .ui-tabs-nav a[href='#tabs-ob" + player_id + "']") ;
$elem.text( gNationalities[nat].display_name + " OB" ) ;
$elem.text( gNationalities[player_nat].display_name + " OB" ) ;
// show/hide the nationality-specific buttons
for ( var nat in _NATIONALITY_SPECIFIC_BUTTONS ) {
for ( var i=0 ; i < _NATIONALITY_SPECIFIC_BUTTONS[nat].length ; ++i ) {
var button_id = _NATIONALITY_SPECIFIC_BUTTONS[nat][i] ;
$elem = $( "#panel-obsetup" + player_id + " input[type='button'][data-id='" + button_id + "']" ) ;
$elem.css( "display", nat == player_nat ? "block" : "none" ) ;
}
}
}

@ -65,9 +65,16 @@
<div id="tabs-ob1">
<fieldset class="tl"> <legend>OB setup</legend>
<div id="panel-obsetup1">
<div id="panel-obsetup1" class="panel-obsetup">
<textarea name="ob_setup_1" type="text" class="param"></textarea>
<div class="footer">
<input type="button" class="generate" data-id="mol" value="MOL">
<input type="button" class="generate" data-id="mol-p" value="MOL-P">
<input type="button" class="generate" data-id="pf" value="PF">
<input type="button" class="generate" data-id="psk" value="PSK">
<input type="button" class="generate" data-id="atmm" value="ATMM">
<input type="button" class="generate" data-id="baz" value="BAZ">
<input type="button" class="generate" data-id="piat" value="PIAT">
<input type="button" class="generate" data-id="ob_setup_1" value="Go">
</div>
</div>
@ -84,10 +91,17 @@
<div id="tabs-ob2">
<fieldset class="tl"> <legend>OB setup</legend>
<div id="panel-obsetup2">
<div id="panel-obsetup2" class="panel-obsetup">
<textarea name="ob_setup_2" type="text" class="param"></textarea>
<div class="footer">
<input type="button" class="generate" data-id="mol" value="MOL">
<input type="button" class="generate" data-id="mol-p" value="MOL-P">
<input type="button" class="generate" data-id="pf" value="PF">
<input type="button" class="generate" data-id="psk" value="PSK">
<input type="button" class="generate" data-id="atmm" value="ATMM">
<input type="button" class="generate" data-id="baz" value="BAZ">
<input type="button" class="generate" data-id="ob_setup_2" value="Go">
<input type="button" class="generate" data-id="piat" value="PIAT">
</div>
</div>
</fieldset>

@ -61,9 +61,9 @@ def test_scenario_snippets( webapp, webdriver ):
_test_snippet( webdriver, "scenario", {
"scenario_name": "my scenario",
"scenario_location": "here",
"scenario_date": "now",
"scenario_date": "01/02/1942",
},
"name = [my scenario] | loc = [here] | date = [now]",
'name = [my scenario] | loc = [here] | date = [01/02/1942] aka "2 January, 1942"',
None
)

@ -1,8 +1,10 @@
""" Test generating OB SETUP snippets. """
import types
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import get_clipboard, find_child
from vasl_templates.webapp.tests.utils import get_nationalities, get_clipboard, get_stored_msg, find_child
# ---------------------------------------------------------------------
@ -52,3 +54,114 @@ def test_ob_setup( webapp, webdriver ):
select_ob_tab( 2 )
btn2.click()
assert get_clipboard().strip() == "[setup there.] (col=[OBCOL:french/OBCOL2:french])"
# ---------------------------------------------------------------------
def test_nationality_specific( webapp, webdriver ):
"""Check that nationality-specific buttons are shown/hidden correctly."""
# initialize
webdriver.get( webapp.url_for( "main", store_msgs=1 ) )
nationalities = get_nationalities( webapp )
# initialize
def set_scenario_date( date ):
"""Set the scenario date."""
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-scenario']" )
elem.click()
elem = find_child( webdriver, "#panel-scenario input[name='scenario_date']" )
elem.clear()
elem.send_keys( "{:02}/01/{:04}".format( date[1], date[0] ) )
# initialize
def check_pf_snippets():
"""Check that the PF snippets are generated correctly."""
def do_test( date, expected, warning ): #pylint: disable=missing-docstring
# test snippet generation
set_scenario_date( date )
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob1']" )
elem.click()
elem = find_child( webdriver, "input[type='button'][data-id='pf']" )
elem.click()
assert get_clipboard().strip() == expected
# check if a warning was issued
last_warning = get_stored_msg( "_last-warning_" ) or ""
if warning:
assert last_warning.startswith( "PF are only available" )
else:
assert last_warning == ""
do_test( (1942,1), "PF: range=[1] ; check=[4] (drm=[+1])", True )
do_test( (1943,9), "PF: range=[1] ; check=[4] (drm=[+1])", True )
do_test( (1943,10), "PF: range=[1] ; check=[3]", False )
do_test( (1944,5), "PF: range=[1] ; check=[3]", False )
do_test( (1944,6), "PF: range=[2] ; check=[3]", False )
do_test( (1944,12), "PF: range=[2] ; check=[3]", False )
do_test( (1945,1), "PF: range=[3] ; check=[4] (drm=[-1])", False )
do_test( (1946,1), "PF: range=[3] ; check=[4] (drm=[-1])", False )
# initialize
def check_baz_snippets():
"""Check that the BAZ snippets are generated correctly."""
def do_test( date, expected ): #pylint: disable=missing-docstring
# test snippet generation
set_scenario_date( date )
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob1']" )
elem.click()
elem = find_child( webdriver, "input[type='button'][data-id='baz']" )
elem.click()
assert get_clipboard().strip() == expected
# check if a warning was issued
last_warning = get_stored_msg( "_last-warning_" ) or ""
if expected == "BAZ: none":
assert last_warning.startswith( "BAZ are only available" )
else:
assert last_warning == ""
do_test( (1941,1), "BAZ: none" )
do_test( (1942,10), "BAZ: none" )
do_test( (1942,11), "BAZ: '43 ; range=[4] ; X#=[10] ; TK#=[13]" )
do_test( (1943,1), "BAZ: '43 ; range=[4] ; X#=[10] ; TK#=[13]" )
do_test( (1944,1), "BAZ: '44 ; range=[4] ; X#=[11] ; TK#=[16]" )
do_test( (1945,1), "BAZ: '45 ; range=[5] ; X#=[11] ; TK#=[16] ; WP#=[6]" )
do_test( (1946,1), "BAZ: '45 ; range=[5] ; X#=[11] ; TK#=[16] ; WP#=[6]" )
# initialize
nationality_specific_buttons = {
"mol": [ "russian", "Burn, baby, burn!" ],
"mol-p": [ "russian", "mol-p template" ],
"pf": [ "german", check_pf_snippets ],
"psk": [ "german", "====> whoosh!" ],
"atmm": [ "german", "Kaboom!!!" ],
"baz": [ "american", check_baz_snippets ],
"piat": [ "british", "piat template" ],
}
# iterate through each nationality
for nat in nationalities:
# change the nationality for player 1
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-scenario']" )
elem.click()
sel = Select(
find_child( webdriver, "select[name='player_1']" )
)
sel.select_by_value( nat )
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob1']" )
elem.click()
# check the nationality-specific buttons
for button_id,expected in nationality_specific_buttons.items():
elem = find_child( webdriver, "input[type='button'][data-id='{}']".format( button_id ) )
if nat == expected[0]:
# the button should be shown for this nationality
assert elem.is_displayed()
# make sure that the template works
elem.click()
if isinstance( expected[1], str ):
assert get_clipboard().strip() == expected[1]
elif isinstance( expected[1], types.FunctionType ):
expected[1]() #pylint: disable=not-callable
else:
assert False
else:
# it should be hidden for all other nationalities
assert not elem.is_displayed()

Loading…
Cancel
Save