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"
30 fullscreen_size(800, 600),
31 window_size(800, 600),
32 aspect_size(0, 0), // auto detect
34 use_fullscreen(false),
35 video(VideoSystem::AUTO_VIDEO),
40 console_enabled(false),
41 random_seed(0), // set by time(), by default (unless in config)
43 enable_script_debugger(false),
57 const lisp::Lisp* root = parser.parse("config");
59 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
61 throw std::runtime_error("File is not a supertux-config file");
63 config_lisp->get("show_fps", show_fps);
64 config_lisp->get("console", console_enabled);
65 config_lisp->get("locale", locale);
66 config_lisp->get("random_seed", random_seed);
68 const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
69 if(config_video_lisp) {
70 config_video_lisp->get("fullscreen", use_fullscreen);
71 std::string video_string;
72 config_video_lisp->get("video", video_string);
73 video = VideoSystem::get_video_system(video_string);
74 config_video_lisp->get("vsync", try_vsync);
76 config_video_lisp->get("fullscreen_width", fullscreen_size.width);
77 config_video_lisp->get("fullscreen_height", fullscreen_size.height);
79 config_video_lisp->get("window_width", window_size.width);
80 config_video_lisp->get("window_height", window_size.height);
82 config_video_lisp->get("aspect_width", aspect_size.width);
83 config_video_lisp->get("aspect_height", aspect_size.height);
85 config_video_lisp->get("magnification", magnification);
88 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
89 if(config_audio_lisp) {
90 config_audio_lisp->get("sound_enabled", sound_enabled);
91 config_audio_lisp->get("music_enabled", music_enabled);
94 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
95 if(config_control_lisp && g_jk_controller) {
96 g_jk_controller->read(*config_control_lisp);
99 const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
100 if(config_addons_lisp) {
101 AddonManager::get_instance().read(*config_addons_lisp);
108 lisp::Writer writer("config");
110 writer.start_list("supertux-config");
112 writer.write("show_fps", show_fps);
113 writer.write("console", console_enabled);
114 writer.write("locale", locale);
116 writer.start_list("video");
117 writer.write("fullscreen", use_fullscreen);
118 writer.write("video", VideoSystem::get_video_string(video));
119 writer.write("vsync", try_vsync);
121 writer.write("fullscreen_width", fullscreen_size.width);
122 writer.write("fullscreen_height", fullscreen_size.height);
124 writer.write("window_width", window_size.width);
125 writer.write("window_height", window_size.height);
127 writer.write("aspect_width", aspect_size.width);
128 writer.write("aspect_height", aspect_size.height);
130 writer.write("magnification", magnification);
132 writer.end_list("video");
134 writer.start_list("audio");
135 writer.write("sound_enabled", sound_enabled);
136 writer.write("music_enabled", music_enabled);
137 writer.end_list("audio");
139 if(g_jk_controller) {
140 writer.start_list("control");
141 g_jk_controller->write(writer);
142 writer.end_list("control");
145 writer.start_list("addons");
146 AddonManager::get_instance().write(writer);
147 writer.end_list("addons");
149 writer.end_list("supertux-config");