00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "supertux/gameconfig.hpp"
00018
00019 #include <stdexcept>
00020
00021 #include "addon/addon_manager.hpp"
00022 #include "control/joystickkeyboardcontroller.hpp"
00023 #include "lisp/writer.hpp"
00024 #include "lisp/parser.hpp"
00025 #include "util/reader.hpp"
00026 #include "supertux/globals.hpp"
00027
00028 Config::Config() :
00029 profile(1),
00030 fullscreen_size(800, 600),
00031 window_size(800, 600),
00032 aspect_size(0, 0),
00033 magnification(0.0f),
00034 use_fullscreen(false),
00035 video(VideoSystem::AUTO_VIDEO),
00036 try_vsync(true),
00037 show_fps(false),
00038 sound_enabled(true),
00039 music_enabled(true),
00040 console_enabled(false),
00041 random_seed(0),
00042 start_level(),
00043 enable_script_debugger(false),
00044 start_demo(),
00045 record_demo(),
00046 locale()
00047 {
00048 }
00049
00050 Config::~Config()
00051 {}
00052
00053 void
00054 Config::load()
00055 {
00056 lisp::Parser parser;
00057 const lisp::Lisp* root = parser.parse("config");
00058
00059 const lisp::Lisp* config_lisp = root->get_lisp("supertux-config");
00060 if(!config_lisp)
00061 throw std::runtime_error("File is not a supertux-config file");
00062
00063 config_lisp->get("show_fps", show_fps);
00064 config_lisp->get("console", console_enabled);
00065 config_lisp->get("locale", locale);
00066 config_lisp->get("random_seed", random_seed);
00067
00068 const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video");
00069 if(config_video_lisp) {
00070 config_video_lisp->get("fullscreen", use_fullscreen);
00071 std::string video_string;
00072 config_video_lisp->get("video", video_string);
00073 video = VideoSystem::get_video_system(video_string);
00074 config_video_lisp->get("vsync", try_vsync);
00075
00076 config_video_lisp->get("fullscreen_width", fullscreen_size.width);
00077 config_video_lisp->get("fullscreen_height", fullscreen_size.height);
00078
00079 config_video_lisp->get("window_width", window_size.width);
00080 config_video_lisp->get("window_height", window_size.height);
00081
00082 config_video_lisp->get("aspect_width", aspect_size.width);
00083 config_video_lisp->get("aspect_height", aspect_size.height);
00084
00085 config_video_lisp->get("magnification", magnification);
00086 }
00087
00088 const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
00089 if(config_audio_lisp) {
00090 config_audio_lisp->get("sound_enabled", sound_enabled);
00091 config_audio_lisp->get("music_enabled", music_enabled);
00092 }
00093
00094 const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control");
00095 if(config_control_lisp && g_jk_controller) {
00096 g_jk_controller->read(*config_control_lisp);
00097 }
00098
00099 const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons");
00100 if(config_addons_lisp) {
00101 AddonManager::get_instance().read(*config_addons_lisp);
00102 }
00103 }
00104
00105 void
00106 Config::save()
00107 {
00108 lisp::Writer writer("config");
00109
00110 writer.start_list("supertux-config");
00111
00112 writer.write("show_fps", show_fps);
00113 writer.write("console", console_enabled);
00114 writer.write("locale", locale);
00115
00116 writer.start_list("video");
00117 writer.write("fullscreen", use_fullscreen);
00118 writer.write("video", VideoSystem::get_video_string(video));
00119 writer.write("vsync", try_vsync);
00120
00121 writer.write("fullscreen_width", fullscreen_size.width);
00122 writer.write("fullscreen_height", fullscreen_size.height);
00123
00124 writer.write("window_width", window_size.width);
00125 writer.write("window_height", window_size.height);
00126
00127 writer.write("aspect_width", aspect_size.width);
00128 writer.write("aspect_height", aspect_size.height);
00129
00130 writer.write("magnification", magnification);
00131
00132 writer.end_list("video");
00133
00134 writer.start_list("audio");
00135 writer.write("sound_enabled", sound_enabled);
00136 writer.write("music_enabled", music_enabled);
00137 writer.end_list("audio");
00138
00139 if(g_jk_controller) {
00140 writer.start_list("control");
00141 g_jk_controller->write(writer);
00142 writer.end_list("control");
00143 }
00144
00145 writer.start_list("addons");
00146 AddonManager::get_instance().write(writer);
00147 writer.end_list("addons");
00148
00149 writer.end_list("supertux-config");
00150 }
00151
00152