~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
82
83
84
85
86
#!/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

BASEDIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(BASEDIR, "cocos"))

import config
config.BASEDIR = BASEDIR

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

import cocos
from cocos import scene
import pyglet

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

import games

# 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(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)


try:
    # pylint: disable-msg=W0612
    from pyglet.media import avbin
except ImportError:
    print _("Please get avbin from http://code.google.com/p/avbin/")
    exit()
print _("Using AVBin module:"), avbin


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

    gm = games.GameManager()
    sc = gm.start(dmenu, spec)
    director.run(sc)