Allow custom flags to be specified as a URL.

master
Pacman Ghost 5 years ago
parent 2397eb5c5f
commit 8532ab6413
  1. 8
      vasl_templates/webapp/snippets.py
  2. 3
      vasl_templates/webapp/static/utils.js

@ -7,6 +7,7 @@ import zipfile
import io
import base64
import threading
import urllib.request
from flask import request, jsonify, send_file, abort
from PIL import Image
@ -178,8 +179,11 @@ def get_flag( nat ):
if globvars.template_pack:
fname = globvars.template_pack.get( "nationalities", {} ).get( nat, {} ).get( "flag" )
if fname:
with open( fname, "rb" ) as fp:
return _get_small_image( fp, key, height )
if fname.startswith( ("http://","https://") ):
fp = urllib.request.urlopen( fname )
else:
fp = open( fname, "rb" )
return _get_small_image( fp, key, height )
# serve the standard flag
fname = os.path.join( "static/images/flags/", nat+".png" )

@ -34,6 +34,9 @@ function get_player_colors_for_element( $elem )
}
function make_player_flag_url( nat, for_snippet ) {
var flag = gTemplatePack.nationalities[nat].flag ;
if ( flag )
return flag ; // nb: custom flag, just use that
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ;
else

Loading…
Cancel
Save