1 // $Id: configfile.cpp 2212 2004-11-28 14:57:45Z matzebraun $
3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Michael George <mike@georgetech.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "gameconfig.h"
29 #include "audio/sound_manager.h"
30 #include "lisp/parser.h"
31 #include "lisp/lisp.h"
32 #include "lisp/writer.h"
33 #include "control/joystickkeyboardcontroller.h"
34 #include "resources.h"
41 use_fullscreen = true;
45 cheats_enabled = false;
51 audio_frequency = MIX_DEFAULT_FREQUENCY;
52 audio_channels = MIX_DEFAULT_CHANNELS;
53 audio_chunksize = 2048;
54 audio_voices = MIX_CHANNELS;
64 std::auto_ptr<lisp::Lisp> root (parser.parse(user_dir + "/config"));
66 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
68 throw std::runtime_error("File is not a supertux-config file");
70 config_lisp->get("show_fps", show_fps);
71 config_lisp->get("cheats", cheats_enabled);
73 const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
74 if(config_video_lisp) {
75 config_video_lisp->get("fullscreen", use_fullscreen);
76 config_video_lisp->get("width", screenwidth);
77 config_video_lisp->get("height", screenheight);
80 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
81 if(config_audio_lisp) {
82 config_audio_lisp->get("sound_enabled", sound_enabled);
83 config_audio_lisp->get("music_enabled", music_enabled);
84 config_audio_lisp->get("frequency", audio_frequency);
85 config_audio_lisp->get("channels", audio_channels);
86 config_audio_lisp->get("voices", audio_voices);
87 config_audio_lisp->get("chunksize", audio_chunksize);
90 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
91 if(config_control_lisp && main_controller) {
92 main_controller->read(*config_control_lisp);
99 std::string configfile = user_dir + "/config";
100 std::ofstream file( (user_dir + "/config").c_str() );
102 std::stringstream msg;
103 msg << "Couldn't write config file '" << configfile << "'";
104 throw std::runtime_error(msg.str());
106 lisp::Writer writer(file);
108 writer.start_list("supertux-config");
110 writer.write_bool("show_fps", show_fps);
111 writer.write_bool("cheats", cheats_enabled);
113 writer.start_list("video");
114 writer.write_bool("fullscreen", use_fullscreen);
115 writer.write_int("width", screenwidth);
116 writer.write_int("height", screenheight);
117 writer.end_list("video");
119 writer.start_list("audio");
120 writer.write_bool("sound_enabled", sound_enabled);
121 writer.write_bool("music_enabled", music_enabled);
122 writer.write_int("frequency", audio_frequency);
123 writer.write_int("channels", audio_channels);
124 writer.write_int("voices", audio_voices);
125 writer.write_int("chunksize", audio_chunksize);
126 writer.end_list("audio");
128 if(main_controller) {
129 writer.start_list("control");
130 main_controller->write(writer);
131 writer.end_list("control");
134 writer.end_list("supertux-config");