1 // SuperTux - A Jump'n Run
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/gameconfig.hpp"
21 #include "addon/addon_manager.hpp"
22 #include "control/joystickkeyboardcontroller.hpp"
23 #include "lisp/writer.hpp"
24 #include "lisp/parser.hpp"
25 #include "util/reader.hpp"
26 #include "supertux/globals.hpp"
32 fullscreen_width (800),
33 fullscreen_height(600),
36 aspect_width (0), // auto detect
39 use_fullscreen(false),
45 console_enabled(false),
46 random_seed(0), // set by time(), by default (unless in config)
48 enable_script_debugger(false),
62 const lisp::Lisp* root = parser.parse("config");
64 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
66 throw std::runtime_error("File is not a supertux-config file");
68 config_lisp->get("show_fps", show_fps);
69 config_lisp->get("console", console_enabled);
70 config_lisp->get("locale", locale);
71 config_lisp->get("random_seed", random_seed);
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 std::string video_string;
77 config_video_lisp->get("video", video_string);
78 video = get_video_system(video_string);
79 config_video_lisp->get("vsync", try_vsync);
81 config_video_lisp->get("fullscreen_width", fullscreen_width);
82 config_video_lisp->get("fullscreen_height", fullscreen_height);
84 config_video_lisp->get("window_width", window_width);
85 config_video_lisp->get("window_height", window_height);
87 config_video_lisp->get("aspect_width", aspect_width);
88 config_video_lisp->get("aspect_height", aspect_height);
91 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
92 if(config_audio_lisp) {
93 config_audio_lisp->get("sound_enabled", sound_enabled);
94 config_audio_lisp->get("music_enabled", music_enabled);
97 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
98 if(config_control_lisp && g_main_controller) {
99 g_main_controller->read(*config_control_lisp);
102 const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
103 if(config_addons_lisp) {
104 AddonManager::get_instance().read(*config_addons_lisp);
111 lisp::Writer writer("config");
113 writer.start_list("supertux-config");
115 writer.write("show_fps", show_fps);
116 writer.write("console", console_enabled);
117 writer.write("locale", locale);
119 writer.start_list("video");
120 writer.write("fullscreen", use_fullscreen);
121 writer.write("video", get_video_string(video));
122 writer.write("vsync", try_vsync);
124 writer.write("fullscreen_width", fullscreen_width);
125 writer.write("fullscreen_height", fullscreen_height);
127 writer.write("window_width", window_width);
128 writer.write("window_height", window_height);
130 writer.write("aspect_width", aspect_width);
131 writer.write("aspect_height", aspect_height);
133 writer.end_list("video");
135 writer.start_list("audio");
136 writer.write("sound_enabled", sound_enabled);
137 writer.write("music_enabled", music_enabled);
138 writer.end_list("audio");
140 if(g_main_controller) {
141 writer.start_list("control");
142 g_main_controller->write(writer);
143 writer.end_list("control");
146 writer.start_list("addons");
147 AddonManager::get_instance().write(writer);
148 writer.end_list("addons");
150 writer.end_list("supertux-config");