~facundo/enjuewemela/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python

# This code is part of the 'enjuewemela' game
# License: GPLv3
# Main author: Facundo Batista
# Code, bug tracker, etc:
#   https://launchpad.net/enjuewemela/
#
"""Main program for the game."""

import os
import sys

import config

from cocos.director import director
director.init(width=800, height=600, resizable=True, audio_backend='sdl')

import pyglet
pyglet.resource.path.append(os.path.join(config.BASEDIR, "jewels"))
pyglet.resource.path.append(os.path.join(config.BASEDIR, "images"))
pyglet.resource.path.append(os.path.join(config.BASEDIR,
                                         "images", "backgrounds"))
pyglet.resource.reindex()

import games
import replayer
import sound

# i18n and l15n support!
import locale
import gettext
import os


def get_language():
    """Return the language to be used by the system.

    If it finds the system language in the translated files, it
    returns it, otherwise it just returns None.
    """
    loc = locale.setlocale(locale.LC_ALL, "")
    loc = loc[:2]
    traducidos = os.listdir(locale_dir)
    if loc in traducidos:
        return loc
    return

locale_dir = os.path.join(config.BASEDIR, "locale")
gettext.install('core', locale_dir, unicode=True)
idioma = get_language()
if idioma is not None:
    mo = os.path.join(locale_dir, '%s/LC_MESSAGES/core.mo' % idioma)
    if not os.access(mo, os.F_OK):
        raise IOError("The l10n directory (for language %r) exists but "
                      "not the core.mo file" % idioma)
    trans = gettext.translation('core', locale_dir, languages=[idioma])
    trans.install(unicode=True)


def start():
    if len(sys.argv) == 3:
        dmenu = sys.argv[1]
        spec = sys.argv[2]
    elif len(sys.argv) == 2:
        dmenu = sys.argv[1]
        spec = None
    else:
        dmenu = ""
        spec = None

    if dmenu == 'replay':
        if spec is None:
            print "Need to indicate which log file to replay."
            exit()
        sound.music_player.volume = 0
        sc = replayer.go(spec)
    else:
        gm = games.GameManager()
        sc = gm.start(dmenu, spec)
    director.run(sc)