3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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"
33 #include "addon/addon_manager.hpp"
40 use_fullscreen = false;
46 console_enabled = false;
47 random_seed = 0; // set by time(), by default (unless in config)
52 fullscreen_width = 800;
53 fullscreen_height = 600;
56 stretch_to_window = false;
61 enable_script_debugger = false;
63 locale = ""; // autodetect
73 const lisp::Lisp* root = parser.parse("config");
75 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
77 throw std::runtime_error("File is not a supertux-config file");
79 config_lisp->get("show_fps", show_fps);
80 config_lisp->get("console", console_enabled);
81 config_lisp->get("locale", locale);
82 config_lisp->get("random_seed", random_seed);
84 const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
85 if(config_video_lisp) {
86 config_video_lisp->get("fullscreen", use_fullscreen);
87 std::string video_string;
88 config_video_lisp->get("video", video_string);
89 video = get_video_system(video_string);
90 config_video_lisp->get("vsync", try_vsync);
92 config_video_lisp->get("fullscreen_width", fullscreen_width);
93 config_video_lisp->get("fullscreen_height", fullscreen_height);
95 config_video_lisp->get("window_width", window_width);
96 config_video_lisp->get("window_height", window_height);
98 config_video_lisp->get("aspect_width", aspect_width);
99 config_video_lisp->get("aspect_height", aspect_height);
101 config_video_lisp->get("stretch_to_window", stretch_to_window);
104 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
105 if(config_audio_lisp) {
106 config_audio_lisp->get("sound_enabled", sound_enabled);
107 config_audio_lisp->get("music_enabled", music_enabled);
110 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
111 if(config_control_lisp && main_controller) {
112 main_controller->read(*config_control_lisp);
115 const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
116 if(config_addons_lisp) {
117 AddonManager::get_instance().read_config(*config_addons_lisp);
124 lisp::Writer writer("config");
126 writer.start_list("supertux-config");
128 writer.write_bool("show_fps", show_fps);
129 writer.write_bool("console", console_enabled);
130 writer.write_string("locale", locale);
132 writer.start_list("video");
133 writer.write_bool("fullscreen", use_fullscreen);
134 writer.write_string("video", get_video_string(video));
135 writer.write_bool("vsync", try_vsync);
137 writer.write_int("fullscreen_width", fullscreen_width);
138 writer.write_int("fullscreen_height", fullscreen_height);
140 writer.write_int("window_width", window_width);
141 writer.write_int("window_height", window_height);
143 writer.write_int("aspect_width", aspect_width);
144 writer.write_int("aspect_height", aspect_height);
146 writer.write_bool("stretch_to_window", stretch_to_window);
148 writer.end_list("video");
150 writer.start_list("audio");
151 writer.write_bool("sound_enabled", sound_enabled);
152 writer.write_bool("music_enabled", music_enabled);
153 writer.end_list("audio");
155 if(main_controller) {
156 writer.start_list("control");
157 main_controller->write(writer);
158 writer.end_list("control");
161 writer.start_list("addons");
162 AddonManager::get_instance().write_config(writer);
163 writer.end_list("addons");
165 writer.end_list("supertux-config");