Added a mask to be applied to a sprite.
[supertux.git] / lib / utils / configfile.cpp
index 0ef0374..bbbb501 100644 (file)
 #include "../utils/configfile.h"
 #include "../app/setup.h"
 #include "../app/globals.h"
+#include "../audio/sound_manager.h"
 
 using namespace SuperTux;
 
 #ifdef WIN32
-const char * config_filename = "/st_config.dat";
+const char * config_filename = ("/"+ package_symbol_name + "_config.dat").c_str();
 #else
 const char * config_filename = "/config";
 #endif
@@ -38,14 +39,37 @@ static void defaults ()
 {
   /* Set defaults: */
   debug_mode = false;
-  audio_device = true;
+  SoundManager::get()->set_audio_device_available(true);
 
   use_fullscreen = false;
   show_fps = false;
   use_gl = false;
 
-  use_sound = true;
-  use_music = true;
+  SoundManager::get()->enable_sound(true);
+  SoundManager::get()->enable_music(true);
+}
+
+FILE * SuperTux::opendata(const std::string& rel_filename, const char *mode)
+{
+  std::string filename;
+  FILE * fi;
+
+  filename = st_dir + rel_filename;
+
+  /* Try opening the file: */
+  fi = fopen(filename.c_str(), mode);
+
+  if (fi == NULL)
+    {
+      fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename.c_str());
+
+      if (strcmp(mode, "r") == 0)
+        fprintf(stderr, "for read!!!\n");
+      else if (strcmp(mode, "w") == 0)
+        fprintf(stderr, "for write!!!\n");
+    }
+
+  return(fi);
 }
 
 void Config::load()
@@ -72,14 +96,17 @@ void Config::load()
   if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
     return;
 
-  if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-config") != 0)
+  if (strcmp(lisp_symbol(lisp_car(root_obj)), (package_symbol_name+"-config").c_str()) != 0)
     return;
 
   LispReader reader(lisp_cdr(root_obj));
 
   reader.read_bool("fullscreen", use_fullscreen);
-  reader.read_bool("sound",      use_sound);
-  reader.read_bool("music",      use_music);
+  bool temp;
+  reader.read_bool("sound",     temp);
+  SoundManager::get()->enable_sound(temp);
+  reader.read_bool("music",      temp);
+  SoundManager::get()->enable_music(temp);
   reader.read_bool("show_fps",   show_fps);
 
   std::string video;
@@ -104,6 +131,7 @@ void Config::load()
   customload(reader);
 
   lisp_free(root_obj);
+  fclose(file);
 }
 
 void Config::save ()
@@ -113,11 +141,11 @@ void Config::save ()
 
   if(config)
     {
-      fprintf(config, "(supertux-config\n");
+      fprintf(config, ("("+package_symbol_name+"-config\n").c_str());
       fprintf(config, "\t;; the following options can be set to #t or #f:\n");
       fprintf(config, "\t(fullscreen %s)\n", use_fullscreen ? "#t" : "#f");
-      fprintf(config, "\t(sound      %s)\n", use_sound      ? "#t" : "#f");
-      fprintf(config, "\t(music      %s)\n", use_music      ? "#t" : "#f");
+      fprintf(config, "\t(sound      %s)\n", SoundManager::get()->sound_enabled()      ? "#t" : "#f");
+      fprintf(config, "\t(music      %s)\n", SoundManager::get()->music_enabled()      ? "#t" : "#f");
       fprintf(config, "\t(show_fps   %s)\n", show_fps       ? "#t" : "#f");
 
       fprintf(config, "\n\t;; either \"opengl\" or \"sdl\"\n");
@@ -139,6 +167,7 @@ void Config::save ()
        customsave(config);
 
       fprintf(config, ")\n");
+      fclose(config);
     }
 }