Skip to content

Commit

Permalink
Update decomposer.
Browse files Browse the repository at this point in the history
  • Loading branch information
o3bvv committed Mar 8, 2014
1 parent 49e67a4 commit c7b7b3d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include README.md
include LICENSE
include requirements.pip
recursive-include il2ds_difficulty/locale *
43 changes: 24 additions & 19 deletions il2ds_difficulty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"""
Convert integer value of game difficulty into dictionary and vice versa.
"""
from collections import OrderedDict

from il2ds_difficulty.constants import (DEFAULT_GAME_VERSION, SETTINGS,
NUMBERS_MAPS, SETTINGS_NAMES_MAP, TABS_NAMES_MAP, )
from il2ds_difficulty.helpers import _
from il2ds_difficulty.helpers import _, evaluate_string
from il2ds_difficulty.validators import (validate_difficulty,
validate_game_version, )

Expand Down Expand Up @@ -38,34 +36,41 @@ def decompose_difficulty_to_tabs(difficulty,
Convert an integer value into ordered difficulty settings groups.
Output example:
{
'tab1_code': {
(
{
'code': 'tab1_code',
'name': 'tab1_name',
'settings': {
'setting1_code': {
'settings': (
{
'code': 'setting1_code',
'title': 'setting1_title',
'description': 'setting1_description',
'value': 'setting1_value',
},
},
),
},
}
)
"""
validate_difficulty(difficulty)
validate_game_version(game_version)

settings = SETTINGS[game_version]
return OrderedDict(tuple(
(tab_code, {
'name': TABS_NAMES_MAP[tab_code],
'settings': OrderedDict(tuple(
(setting_code, dict(
SETTINGS_NAMES_MAP[setting_code], **{
return tuple(
{
'code': tab_code,
'title': evaluate_string(TABS_NAMES_MAP[tab_code]),
'settings': tuple(
{
'code': setting_code,
'title': evaluate_string(
SETTINGS_NAMES_MAP[setting_code]['title']),
'description': evaluate_string(
SETTINGS_NAMES_MAP[setting_code]['description']),
'value': get_setting_value(difficulty, setting_number),
})) for setting_code, setting_number in tab_settings.items()
))
}) for tab_code, tab_settings in settings.items()
))
} for setting_code, setting_number in tab_settings.items()
)
} for tab_code, tab_settings in settings.items()
)


def compose_difficulty(settings, game_version=DEFAULT_GAME_VERSION):
Expand Down
8 changes: 6 additions & 2 deletions il2ds_difficulty/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
try:
from django.conf import settings
if settings.configured:
from django.utils.translation import ugettext
_ = ugettext
from django.utils.translation import ugettext_lazy
_ = ugettext_lazy
else:
raise ImportError()
except ImportError:
def _(value):
return value


def evaluate_string(value):
return None if value is None else unicode(value)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
author='Alexander Oblovatniy, Alexander Kamyhin',
author_email='[email protected], [email protected]',
packages=find_packages(),
include_package_data=True,
install_requires=[i.strip() for i in open("requirements.pip").readlines()],
classifiers = [
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit c7b7b3d

Please sign in to comment.