Skip to content

Commit

Permalink
Merge pull request #15 from FAForever/feature/map-previews
Browse files Browse the repository at this point in the history
Feature/map previews
  • Loading branch information
micheljung committed Jun 25, 2016
2 parents 0029502 + 8f5e0e9 commit bfc8a90
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Thumbs.db
RELEASE-VERSION
.coverage
faftools.egg-info/
*.iml
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include static *
13 changes: 8 additions & 5 deletions faf/tools/fa/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path
from zipfile import ZipFile, ZipExtFile
import struct

import pkg_resources
from PIL import Image
import os
import math
Expand Down Expand Up @@ -98,7 +100,7 @@ def generate_preview(self, size, target_path, mass_icon=None, hydro_icon=None, a

self.add_markers(resized_image, mass_image, hydro_image, army_image)

resized_image.save(os.path.join(target_path.strpath, '{}.png'.format(self.mapname)))
resized_image.save(os.path.join(str(target_path), '{}.png'.format(self.mapname)))

def add_markers(self, target_image, mass_image=None, hydro_image=None, army_image=None):
markers = self.data['save']['Scenario']['MasterChain']['_MASTERCHAIN_']['Markers']
Expand Down Expand Up @@ -151,10 +153,11 @@ def generate_map_previews(map_path, sizes_to_paths, mass_icon=None, hydro_icon=N
:param army_icon: the path to the army marker image
:return:
"""
icons_dir = os.path.dirname(os.path.realpath(__file__))
mass_icon = mass_icon if mass_icon else os.path.join(icons_dir, 'map_icons', 'mass.png')
hydro_icon = hydro_icon if hydro_icon else os.path.join(icons_dir, 'map_icons', 'hydro.png')
army_icon = army_icon if army_icon else os.path.join(icons_dir, 'map_icons', 'army.png')

markers_dir = pkg_resources.resource_filename('static', 'map_markers')
mass_icon = mass_icon if mass_icon else os.path.join(markers_dir, 'mass.png')
hydro_icon = hydro_icon if hydro_icon else os.path.join(markers_dir, 'hydro.png')
army_icon = army_icon if army_icon else os.path.join(markers_dir, 'army.png')

file = MapFile(map_path)
for size, path in sizes_to_paths.items():
Expand Down
8 changes: 6 additions & 2 deletions faf/tools/lua/parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pkg_resources

try:
import lupa
import os


def from_lua(lua_code):
"""
Expand All @@ -9,7 +11,7 @@ def from_lua(lua_code):
:return:
"""

fa_functions_path = os.path.join(os.path.dirname(__file__), 'fa_functions.lua')
fa_functions_path = pkg_resources.resource_filename('static', 'lua/fa_functions.lua')

lua = lupa.LuaRuntime()
with open(fa_functions_path, 'r') as fp:
Expand All @@ -25,11 +27,13 @@ def unfold_table(t, seen=None):
elif lupa.lua_type(v) == 'table':
result[k] = dict(v)
return result

return unfold_table(lua.globals())

except ImportError as e:
print("Ignoring lupa import error: %s" % e)
lupa = None


def from_lua(input):
raise Exception("Can't parse lua code in this environment")
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
author_email='sheeo@faforever.com',
description='faftools project',
requires=['lupa'],
install_requires=['docopt', 'pathlib', 'marshmallow', 'marshmallow_jsonapi']
install_requires=['docopt', 'pathlib', 'marshmallow', 'marshmallow_jsonapi'],
include_package_data=True
)
3 changes: 3 additions & 0 deletions static/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Contains static data like PNG files.
"""
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
9 changes: 5 additions & 4 deletions tests/unit_tests/fa/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

from pathlib import Path

import pkg_resources
import pytest
from PIL import Image

from faf.tools.fa.maps import generate_map_previews
import os

HYDRO_ICON = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../faf/tools/fa/map_icons/hydro.png')
MASS_ICON = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../faf/tools/fa/map_icons/mass.png')
ARMY_ICON = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../faf/tools/fa/map_icons/army.png')
MAP_ZIP = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../data/maps/theta_passage_5.v0001.zip')
HYDRO_ICON = pkg_resources.resource_filename('static', 'map_markers/hydro.png')
MASS_ICON = pkg_resources.resource_filename('static', 'map_markers/mass.png')
ARMY_ICON = pkg_resources.resource_filename('static', 'map_markers/army.png')
MAP_ZIP = pkg_resources.resource_filename('tests', 'data/maps/theta_passage_5.v0001.zip')


@pytest.mark.parametrize("hydro_icon", [HYDRO_ICON, None])
Expand Down

0 comments on commit bfc8a90

Please sign in to comment.