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.hpp"
27 #include "lisp/parser.hpp"
28 #include "lisp/lisp.hpp"
29 #include "lisp/writer.hpp"
30 #include "control/joystickkeyboardcontroller.hpp"
31 #include "resources.hpp"
38 use_fullscreen = true;
42 cheats_enabled = false;
56 std::auto_ptr<lisp::Lisp> root (parser.parse("config"));
58 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
60 throw std::runtime_error("File is not a supertux-config file");
62 config_lisp->get("show_fps", show_fps);
63 config_lisp->get("cheats", cheats_enabled);
65 const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
66 if(config_video_lisp) {
67 config_video_lisp->get("fullscreen", use_fullscreen);
68 config_video_lisp->get("width", screenwidth);
69 config_video_lisp->get("height", screenheight);
72 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
73 if(config_audio_lisp) {
74 config_audio_lisp->get("sound_enabled", sound_enabled);
75 config_audio_lisp->get("music_enabled", music_enabled);
78 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
79 if(config_control_lisp && main_controller) {
80 main_controller->read(*config_control_lisp);
87 lisp::Writer writer("config");
89 writer.start_list("supertux-config");
91 writer.write_bool("show_fps", show_fps);
92 writer.write_bool("cheats", cheats_enabled);
94 writer.start_list("video");
95 writer.write_bool("fullscreen", use_fullscreen);
96 writer.write_int("width", screenwidth);
97 writer.write_int("height", screenheight);
98 writer.end_list("video");
100 writer.start_list("audio");
101 writer.write_bool("sound_enabled", sound_enabled);
102 writer.write_bool("music_enabled", music_enabled);
103 writer.end_list("audio");
105 if(main_controller) {
106 writer.start_list("control");
107 main_controller->write(writer);
108 writer.end_list("control");
111 writer.end_list("supertux-config");