# Balazar Brothers
# Copyright (C) 2006 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_brothers", LOCALEDIR)
except IOError:
  
  LOCALEDIR = os.path.join(APPDIR, "..", "locale")
  try: translator = gettext.translation("balazar_brothers", LOCALEDIR)
  except IOError:
    
    LOCALEDIR = os.path.join("/", "usr", "share", "locale")
    try: translator = gettext.translation("balazar_brothers", LOCALEDIR)
    except IOError:
      
      # Non-supported language, defaults to english
      LOCALEDIR = os.path.join(APPDIR, "locale")
      try: translator = gettext.translation("balazar_brothers", LOCALEDIR, ("en",))
      except IOError:
        
        LOCALEDIR = os.path.join(APPDIR, "..", "locale")
        try: translator = gettext.translation("balazar_brothers", LOCALEDIR, ("en",))
        except IOError:
          
          LOCALEDIR = os.path.join("/", "usr", "share", "locale")
          translator = gettext.translation("balazar_brothers", LOCALEDIR, ("en",))
      
translator.install(1)
#open(os.path.join(LOCALEDIR, "fr", "LC_MESSAGES", "balazar_brothers.po")).read()


VERIFICATION_SERVER = ""

DIFFICULTY = 0

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

QUALITY    = 1

SERVER_HOST = "localhost"
SERVER_PORT = 6901

START_LEVEL = "tutorial"

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

FPS_LABEL = 1

# Check for "dot balazar" config file
CONFIG_FILE = os.path.expanduser(os.path.join("~", ".balazar_brothers/config"))
if CONFIG_FILE[0] == "~": # Fucking winedaube OS !!!
  CONFIG_FILE = "C:\\.balazar_brothers/config" # Random name...
  
SAVED_GAME_DIR = os.path.expanduser(os.path.join("~", ".balazar_brothers"))
if SAVED_GAME_DIR[0] == "~": # Fucking winedaube OS !!!
  SAVED_GAME_DIR = "C:\\balazar_brothers" # Random name...


try:
  import getpass
  NAME = getpass.getuser()
except:
  NAME = "your_name"

PASSWORD = "test"

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


SAVE_REPLAY = 0



def check_path(d):
  if not os.path.exists(d): os.mkdir(d)
  
check_path(SAVED_GAME_DIR)



def generate_config_file():
  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"

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

    except ImportError:
      print "* BalazarBrothers * 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 "* BalazarBrothers * 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 "* BalazarBrothers * PyOpenAL not installed, trying PySDL_mixer..."
    
    try:
      import soya.sdl_mixer4soya
      HAS_OGG = 1
      SOUND_SYSTEM = "SDL_mixer"
    
    except ImportError:
      print "* BalazarBrothers * 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 "* BalazarBrothers * Warning! PyOpenAL is installed, but not PyOgg / PyVorbis; music is disabled!"
      MUSIC   = 0
      HAS_OGG = 0
      


mode = ""



