diff --git a/vasl_templates/webapp/__init__.py b/vasl_templates/webapp/__init__.py
index eb3b961..27bef31 100644
--- a/vasl_templates/webapp/__init__.py
+++ b/vasl_templates/webapp/__init__.py
@@ -84,6 +84,18 @@ def _init_webapp():
from vasl_templates.webapp.vo_notes import load_vo_notes #pylint: disable=cyclic-import
load_vo_notes( startup_msg_store )
+ # initialize the vehicle/ordnance notes image cache
+ from vasl_templates.webapp import vo_notes as webapp_vo_notes #pylint: disable=reimported
+ dname = app.config.get( "VO_NOTES_IMAGE_CACHE_DIR" )
+ if dname in ( "disable", "disabled" ):
+ webapp_vo_notes._vo_notes_image_cache_dname = None #pylint: disable=protected-access
+ elif dname:
+ webapp_vo_notes._vo_notes_image_cache_dname = dname #pylint: disable=protected-access
+ else:
+ webapp_vo_notes._vo_notes_image_cache_dname = os.path.join( #pylint: disable=protected-access
+ tempfile.gettempdir(), "vasl-templates", "vo-notes-image-cache"
+ )
+
# load integration data from asl-rulebook2
from vasl_templates.webapp.vo_notes import load_asl_rulebook2_vo_note_targets #pylint: disable=cyclic-import
load_asl_rulebook2_vo_note_targets( startup_msg_store )
diff --git a/vasl_templates/webapp/static/help/index.html b/vasl_templates/webapp/static/help/index.html
index b73dd62..6d9ee52 100644
--- a/vasl_templates/webapp/static/help/index.html
+++ b/vasl_templates/webapp/static/help/index.html
@@ -374,6 +374,7 @@ The report also calculates "hotness", which is a measure of how hot you
Show Chapter H vehicle/ordnance notes as images
If you have set up the Chapter H vehicle/ordnance notes as HTML, it may not be possible to get the layout you want, since VASSAL's HTML engine is very old and doesn't support many HTML/CSS features. To work around this, this option tells VASL Templates to render the HTML itself (using a modern browser) and send it as an image to VASSAL, which is slower but gives better results.
+
To optimize this process, the generated images are cached, and if you want to keep these cached images between sessions, configure VO_NOTES_IMAGE_CACHE_DIR in your site.cfg file. To pre-load this cache with all the available images, open http://localhost:5010/load-vo-notes-image-cache in a browser.
diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js
index 4b2b790..bfbb1ca 100644
--- a/vasl_templates/webapp/static/snippets.js
+++ b/vasl_templates/webapp/static/snippets.js
@@ -577,17 +577,12 @@ function get_vo_note( vo_type, nat, key )
if ( !( key in gVehicleOrdnanceNotes[ vo_type ][ nat ] ) )
return null ;
+ // check if we have an image or HTML note
var vo_note = gVehicleOrdnanceNotes[ vo_type ][ nat ][ key ] ;
- // FUDGE! We need to detect between a full HTML note and an image-based one.
- // This is not great, but it'll do... :-/
- var nat2 = nat ;
- var pos = nat2.indexOf( "~" ) ;
- if ( pos > 0 )
- nat2 = nat2.substring( 0, pos ) ;
- if ( vo_note.substr( 0, nat2.length+1 ) === nat2+"/" )
- return make_app_url( "/" + vo_type + "/" + nat + "/note/" + key, true ) ;
+ if ( vo_note.content !== undefined )
+ return vo_note.content ;
else
- return vo_note ;
+ return make_app_url( "/" + vo_type + "/" + nat + "/note/" + key, true ) ;
}
function get_ma_notes_keys( nat, vo_entries, vo_type )
diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js
index 97ae1aa..dffb334 100644
--- a/vasl_templates/webapp/static/vo.js
+++ b/vasl_templates/webapp/static/vo.js
@@ -234,23 +234,8 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, elite, custom_cap
"
",
""
] ;
- var vo_note = get_vo_note( vo_type, nat, vo_note_key ) ;
- var vo_note_image_url = null ;
- if ( vo_note ) {
- if ( is_landing_craft )
- vo_note_image_url = make_app_url( "/" + vo_type + "/landing-craft/note/" + vo_note_key.substring(3), true ) ;
- else
- vo_note_image_url = make_app_url( "/" + vo_type + "/" + nat + "/note/" + vo_note_key, true ) ;
- } else {
- // NOTE: Note numbers seem to be distinct across all Allied Minor or all Axis Minor vehicles/ordnance,
- // so if we don't find a note in a given nationality's normal vehicles/ordnance, we can get away with
- // just checking their corresponding common vehicles/ordnance.
- if ( ["allied-minor","axis-minor"].indexOf( nat_type ) !== -1 ) {
- vo_note = get_vo_note( vo_type, nat_type, vo_note_key ) ;
- if ( vo_note )
- vo_note_image_url = make_app_url( "/" + vo_type + "/" + nat_type + "/note/" + vo_note_key, true ) ;
- }
- }
+ var rc = make_vo_note_image_url( vo_type, nat, vo_note_key ) ;
+ var vo_note_image_url = rc[0], vo_note = rc[1] ;
if ( vo_note ) {
var template_id = (vo_type === "vehicles") ? "ob_vehicle_note" : "ob_ordnance_note" ;
if ( is_template_available( template_id ) ) {
@@ -285,6 +270,35 @@ function do_add_vo( vo_type, player_no, vo_entry, vo_image_id, elite, custom_cap
} ) ;
}
+function make_vo_note_image_url( vo_type, nat, key )
+{
+ // generate the URL to get a vehicle/ordnance note image
+ var url = null ;
+ var vo_note = get_vo_note( vo_type, nat, key ) ;
+ if ( vo_note ) {
+ var is_landing_craft = key ? key.substring( 0, 3 ) === "LC " : null ;
+ if ( is_landing_craft )
+ url = make_app_url( "/" + vo_type + "/landing-craft/note/" + key.substring(3), true ) ;
+ else
+ url = make_app_url( "/" + vo_type + "/" + nat + "/note/" + key, true ) ;
+ } else {
+ // NOTE: Note numbers seem to be distinct across all Allied Minor or all Axis Minor vehicles/ordnance,
+ // so if we don't find a note in a given nationality's normal vehicles/ordnance, we can get away with
+ // just checking their corresponding common vehicles/ordnance.
+ var nat_type ;
+ if ( [ "allied-minor", "axis-minor" ].indexOf( nat ) !== -1 )
+ nat_type = nat ;
+ else
+ nat_type = gTemplatePack.nationalities[ nat ].type ;
+ if ( [ "allied-minor", "axis-minor" ].indexOf( nat_type ) !== -1 ) {
+ vo_note = get_vo_note( vo_type, nat_type, key ) ;
+ if ( vo_note )
+ url = make_app_url( "/" + vo_type + "/" + nat_type + "/note/" + key, true ) ;
+ }
+ }
+ return [ url, vo_note ] ;
+}
+
function update_vo_sortable2_entry( $entry, vo_type, snippet_params )
{
// initialize
diff --git a/vasl_templates/webapp/templates/configure-vo-notes-image-cache.html b/vasl_templates/webapp/templates/configure-vo-notes-image-cache.html
new file mode 100644
index 0000000..81d73ce
--- /dev/null
+++ b/vasl_templates/webapp/templates/configure-vo-notes-image-cache.html
@@ -0,0 +1,7 @@
+If you have set up your vehicle/ordnance notes using HTML, and have configured "Show Chapter H vehicle/ordnance notes as images" in the Settings, you will find that scenarios can be slow to open in VASSAL, since converting each note to an image takes time.
+
+
This process can be optimized by configuring a directory to cache the generated images, and this page will pre-load the cache with all the available vehicle/ordnance notes.
+
+{%if NO_CACHE_DIR %}
+
Configure VO_NOTES_IMAGE_CACHE_DIR in your site.cfg, restart the server, then reload this page.
+{%endif%}
diff --git a/vasl_templates/webapp/templates/load-vo-notes-image-cache.html b/vasl_templates/webapp/templates/load-vo-notes-image-cache.html
new file mode 100644
index 0000000..b9b501d
--- /dev/null
+++ b/vasl_templates/webapp/templates/load-vo-notes-image-cache.html
@@ -0,0 +1,136 @@
+
+
+
+