Added the ability to generate OB SETUP snippets.

master
Pacman Ghost 6 years ago
parent 040292279b
commit 06fa8dd30b
  1. 1
      vasl_templates/webapp/data/default-templates/ob_setup.j2
  2. 6
      vasl_templates/webapp/static/css/main.css
  3. 16
      vasl_templates/webapp/static/generate.js
  4. 6
      vasl_templates/webapp/templates/main.html
  5. 54
      vasl_templates/webapp/tests/test_ob_setup.py

@ -0,0 +1 @@
[{{OB_SETUP}}] (col=[{{OB_SETUP_COLOR}}/{{OB_SETUP_COLOR_2}}])

@ -108,6 +108,12 @@ input[type="text"] { margin-bottom: 0.25em ; }
#panel-vc textarea[name="victory_conditions"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; }
#panel-vc input[type="button"] { float: right ; }
#panel-obsetup1 textarea[name="ob_setup_1"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; }
#panel-obsetup1 input[type="button"] { float: right ; }
#panel-obsetup2 textarea[name="ob_setup_2"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; }
#panel-obsetup2 input[type="button"] { float: right ; }
/* -------------------------------------------------------------------- */
.growl-title { display: none ; }

@ -15,8 +15,22 @@ function generate_snippet( $btn )
$("textarea.param").each( function() { add_param($(this)) ; } ) ;
$("select.param").each( function() { add_param($(this)) ; } ) ;
// check for mandatory parameters
// figore out which template to use
var template_id = $btn.data( "id" ) ;
if ( template_id === "ob_setup_1" ) {
template_id = "ob_setup" ;
params.OB_SETUP = params.OB_SETUP_1 ;
params.OB_SETUP_COLOR = gNationalities[params.PLAYER_1].ob_colors[0] ;
params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_1].ob_colors[1] ;
}
else if ( template_id === "ob_setup_2" ) {
template_id = "ob_setup" ;
params.OB_SETUP = params.OB_SETUP_2 ;
params.OB_SETUP_COLOR = gNationalities[params.PLAYER_2].ob_colors[0] ;
params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_2].ob_colors[1] ;
}
// check for mandatory parameters
if ( template_id in _MANDATORY_PARAMS ) {
var missing_params = [] ;
for ( var param_id in _MANDATORY_PARAMS[template_id] ) {

@ -40,7 +40,7 @@
</fieldset>
<div id="panel-vc">
<fieldset> <legend>Victory Conditions</legend>
<textarea name="victory_conditions" type="text" class="param"> </textarea>
<textarea name="victory_conditions" type="text" class="param"></textarea>
<input type="button" class="generate" data-id="victory_conditions" value="Go">
</fieldset>
</div>
@ -53,6 +53,8 @@
<div id="tabs-ob1">
<div id="panel-obsetup1">
<fieldset> <legend>OB setup</legend>
<textarea name="ob_setup_1" type="text" class="param"></textarea>
<input type="button" class="generate" data-id="ob_setup_1" value="Go">
</fieldset>
</div>
<div id="panel-obvehicles1">
@ -68,6 +70,8 @@
<div id="tabs-ob2">
<div id="panel-obsetup2">
<fieldset> <legend>OB setup</legend>
<textarea name="ob_setup_2" type="text" class="param"></textarea>
<input type="button" class="generate" data-id="ob_setup_2" value="Go">
</fieldset>
</div>
<div id="panel-obvehicles2">

@ -0,0 +1,54 @@
""" Test generating OB SETUP snippets. """
from selenium.webdriver.support.ui import Select
from vasl_templates.webapp.tests.utils import get_clipboard, find_child
# ---------------------------------------------------------------------
def test_ob_setup( webapp, webdriver ):
"""Test generating OB SETUP snippets."""
# initialize
webdriver.get( webapp.url_for( "main" ) )
# initialize
def select_ob_tab( player_id ):
"""Select the OB tab for the specified player."""
elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob{}']".format( player_id ) )
elem.click()
# generate OB SETUP snippets for both players
select_ob_tab( 1 )
textarea1 = find_child( webdriver, "textarea[name='ob_setup_1']" )
textarea1.clear()
textarea1.send_keys( "setup here." )
btn1 = find_child( webdriver, "input[type='button'][data-id='ob_setup_1']" )
select_ob_tab( 2 )
textarea2 = find_child( webdriver, "textarea[name='ob_setup_2']" )
textarea2.clear()
textarea2.send_keys( "setup there." )
btn2 = find_child( webdriver, "input[type='button'][data-id='ob_setup_2']" )
btn2.click()
assert get_clipboard().strip() == "[setup there.] (col=[OBCOL:russian/OBCOL2:russian])"
select_ob_tab( 1 )
btn1.click()
assert get_clipboard().strip() == "[setup here.] (col=[OBCOL:german/OBCOL2:german])"
# change the player nationalities and generate the OB SETUP snippets again
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( "british" )
sel = Select(
find_child( webdriver, "select[name='player_2']" )
)
sel.select_by_value( "french" )
select_ob_tab( 1 )
btn1.click()
assert get_clipboard().strip() == "[setup here.] (col=[OBCOL:british/OBCOL2:british])"
select_ob_tab( 2 )
btn2.click()
assert get_clipboard().strip() == "[setup there.] (col=[OBCOL:french/OBCOL2:french])"
Loading…
Cancel
Save