# Balazar
# Copyright (C) 2005 Jean-Baptiste LAMY
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import os, os.path, gettext

import soya, tofu
APPDIR = os.path.dirname(__file__)

soya.path.insert(0, APPDIR)
tofu.path.insert(0, APPDIR)


translator = None
LOCALEDIR = os.path.join(APPDIR, "locale")
try: translator = gettext.translation("balazar", LOCALEDIR)
except IOError:
  
  LOCALEDIR = os.path.join(APPDIR, "..", "locale")
  try: translator = gettext.translation("balazar", LOCALEDIR)
  except IOError:
    
    LOCALEDIR = os.path.join("/", "usr", "share", "locale")
    try: translator = gettext.translation("balazar", LOCALEDIR)
    except IOError:
      
      # Non-supported language, defaults to english
      LOCALEDIR = os.path.join(APPDIR, "locale")
      try: translator = gettext.translation("balazar", LOCALEDIR, ("en",))
      except IOError:
        
        LOCALEDIR = os.path.join(APPDIR, "..", "locale")
        try: translator = gettext.translation("balazar", LOCALEDIR, ("en",))
        except IOError:
          
          LOCALEDIR = os.path.join("/", "usr", "share", "locale")
          translator = gettext.translation("balazar", LOCALEDIR, ("en",))
      
translator.install(1)
#open(os.path.join(LOCALEDIR, "fr", "LC_MESSAGES", "balazar.po")).read()


VERIFICATION_SERVER = ""

DIFFICULTY = 0

FULLSCREEN    = 0
SCREEN_WIDTH  = 800
SCREEN_HEIGHT = 600
MIN_FRAME_DURATION = 0.025

QUALITY    = 1

SERVER_HOST = "localhost" #"balazar.nekeme.net"
SERVER_PORT = 6900

MUSIC = 1
SOUND = 1
ASYNC_LOAD_MUSIC = 0
SOUND_SYSTEM = "OpenAL"
#SOUND_SYSTEM = "SDL_mixer"
WAIT_FOR_SOUND = 1

# Check for "dot balazar" config file
CONFIG_FILE = os.path.expanduser(os.path.join("~", ".balazar"))
if CONFIG_FILE[0] == "~": # Fucking winedaube OS !!!
  CONFIG_FILE = "C:\\.balazar" # Random name...
  
SAVED_GAME_DIR = os.path.expanduser(os.path.join("~", ".balazar_saved_games"))
if SAVED_GAME_DIR[0] == "~": # Fucking winedaube OS !!!
  SAVED_GAME_DIR = "C:\\.balazar_saved_games" # Random name...
  
try:
  import getpass
  NAME = getpass.getuser()
except:
  NAME = "jiba"

PASSWORD = "test"

if os.path.exists(CONFIG_FILE):
  try:
    execfile(CONFIG_FILE)
  except:
    import sys
    sys.excepthook(*sys.exc_info())
    print """* Balazar * Error in config file ~/.balazar !
Please reconfigure Balazar !
Config file ignored.
"""

    
def generate_dot_balazar():
  open(CONFIG_FILE, "w").write("""
FULLSCREEN        = %(FULLSCREEN)s
SCREEN_WIDTH      = %(SCREEN_WIDTH)s
SCREEN_HEIGHT     = %(SCREEN_HEIGHT)s
QUALITY           = %(QUALITY)s

DIFFICULTY        = %(DIFFICULTY)s

NAME              = '%(NAME)s'
PASSWORD          = '%(PASSWORD)s'

SERVER_HOST      = '%(SERVER_HOST)s'
SERVER_PORT      = %(SERVER_PORT)s

MUSIC            = %(MUSIC)s
SOUND            = %(SOUND)s
ASYNC_LOAD_MUSIC = %(ASYNC_LOAD_MUSIC)s
SOUND_SYSTEM     = '%(SOUND_SYSTEM)s'
WAIT_FOR_SOUND   = %(WAIT_FOR_SOUND)s

SAVED_GAME_DIR   = '%(SAVED_GAME_DIR)s'
""" % globals())

VERSION = "0.3.1"

GUI = 0

DIFFICULTY_NEWBIE = 0
DIFFICULTY_HACKER = 1
DIFFICULTY_GURU   = 2
DIFFICULTIES = {
  _("Newbie") : 0,
  _("Hacker") : 1,
  _("Guru"  ) : 2,
  }

SERVER_VIEW = 0

if SOUND_SYSTEM == "SDL_mixer":
  try:
    import soya.sdl_mixer4soya
    HAS_OGG = 1
    
  except ImportError:
    print "* Balazar * PySDL_mixer not installed, trying PyOpenAL..."
    
    try:
      import soya.openal4soya
      SOUND_SYSTEM = "OpenAL"

    except ImportError:
      print "* Balazar * Warning! Neither PyOpenAL nor PySDL_mixer are installed; music and sound are disabled!"
      MUSIC = 0
      SOUND = 0

    try:
      import ogg.vorbis
      HAS_OGG = 1
    except ImportError:
      print "* Balazar * Warning! PyOpenAL is installed, but not PyOgg / PyVorbis; music is disabled!"
      MUSIC   = 0
      HAS_OGG = 0
    
    
if SOUND_SYSTEM == "OpenAL":
  try:
    import soya.openal4soya
    
  except ImportError:
    print "* Balazar * PyOpenAL not installed, trying PySDL_mixer..."
    
    try:
      import soya.sdl_mixer4soya
      HAS_OGG = 1
      SOUND_SYSTEM = "SDL_mixer"
    
    except ImportError:
      print "* Balazar * Warning! Neither PyOpenAL nor PySDL_mixer are installed; music and sound are disabled!"
      MUSIC = 0
      SOUND = 0
      
  else:
    try:
      import ogg.vorbis
      HAS_OGG = 1
    except ImportError:
      print "* Balazar * Warning! PyOpenAL is installed, but not PyOgg / PyVorbis; music is disabled!"
      MUSIC   = 0
      HAS_OGG = 0
      


MODE = ""


