<commit_before>## Copyright (c) 2010 by <NAME> <<EMAIL>>
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Affero General Public License as published by the
## Free Software Foundation, either version 3 of the License, or (at your option
## any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
## for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/agpl.txt>.
##
## This license is also included in the file COPYING
##
## AUTHOR: <NAME> <<EMAIL>>

""" This module defines functions to generate the map. """

import Image, ImageDraw
import os
import os.path

from django.conf import settings

TOKENS_DIR=os.path.join(settings.MEDIA_ROOT, 'scenarios', 'tokens')
TEMPLATES_DIR=os.path.join(settings.PROJECT_ROOT, 'apps/condottieri_scenarios/media/condottieri_scenarios/token_templates')
BADGES_DIR=os.path.join(settings.MEDIA_ROOT, 'scenarios', 'badges')

def ensure_dir(f):
	d = os.path.dirname(f)
	if not os.path.exists(d):
		os.makedirs(d)

def make_scenario_map(s):
	""" Makes the initial map for an scenario.
	"""
	base_map = Image.open(s.setting.board)
	## if there are disabled areas, mark them
	marker = Image.open("%s/disabled.png" % TOKENS_DIR)
	for d in  s.disabledarea_set.all():
		base_map.paste(marker, (d.area.aftoken.x, d.area.aftoken.y), marker)
	## mark special city incomes
	marker = Image.open("%s/chest.png" % TOKENS_DIR)
	for i in s.cityincome_set.all():
		base_map.paste(marker, (i.city.gtoken.x + 48, i.city.gtoken.y), marker)
	##
	for c in s.contender_set.filter(country__isnull=False):
		## paste control markers and flags
		marker = Image.open("%s/control-%s.png" % (TOKENS_DIR, c.country.static_name))
		flag = Image.open("%s/flag-%s.png" % (TOKENS_DIR, c.country.static_name))<commit_msg>fixed compatibility with Pillow<commit_after>## Copyright (c) 2010 by <NAME> <<EMAIL>>
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Affero General Public License as published by the
## Free Software Foundation, either version 3 of the License, or (at your option
## any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
## for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/agpl.txt>.
##
## This license is also included in the file COPYING
##
## AUTHOR: <NAME> <<EMAIL>>

""" This module defines functions to generate the map. """

from PIL import Image, ImageDraw
import os
import os.path

from django.conf import settings

TOKENS_DIR=os.path.join(settings.MEDIA_ROOT, 'scenarios', 'tokens')
TEMPLATES_DIR=os.path.join(settings.PROJECT_ROOT, 'apps/condottieri_scenarios/media/condottieri_scenarios/token_templates')
BADGES_DIR=os.path.join(settings.MEDIA_ROOT, 'scenarios', 'badges')

def ensure_dir(f):
	d = os.path.dirname(f)
	if not os.path.exists(d):
		os.makedirs(d)

def make_scenario_map(s):
	""" Makes the initial map for an scenario.
	"""
	base_map = Image.open(s.setting.board)
	## if there are disabled areas, mark them
	marker = Image.open("%s/disabled.png" % TOKENS_DIR)
	for d in  s.disabledarea_set.all():
		base_map.paste(marker, (d.area.aftoken.x, d.area.aftoken.y), marker)
	## mark special city incomes
	marker = Image.open("%s/chest.png" % TOKENS_DIR)
	for i in s.cityincome_set.all():
		base_map.paste(marker, (i.city.gtoken.x + 48, i.city.gtoken.y), marker)
	##
	for c in s.contender_set.filter(country__isnull=False):
		## paste control markers and flags
		marker = Image.open("%s/control-%s.png" % (TOKENS_DIR, c.country.static_name))
		flag = Image.open("%s/flag-%s.png" % (TOKENS_DIR, c.country.static_name))
{'fraction_non_alphanumeric': 0.12497018840925352, 'fraction_numerical': 0.00333889816360601, 'mean_word_length': 4.776859504132231, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2035909', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1367, 'n_words': 440}