Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further refinement of the setting the preferences paths to the module…

… name. Also now sets the window title to the module name. Added name as an attribute in the module.cfg files.
  • Loading branch information...
commit 9fc7546e918e52a79122b1c8a9b8c3d45ac9547f 1 parent 2f337cd
@sweetkristas sweetkristas authored
View
1  modules/cube_trains/master-config.cfg
@@ -1,4 +1,5 @@
{
id: "cube_trains",
+name: "Cube Trains",
arguments: ["--width", "1050", "--height", "845", "--native"],
}
View
1  modules/cube_trains/module.cfg
@@ -1,4 +1,5 @@
{
id: "cube_trains",
+name: "Cube Trains",
arguments: ["--width", "1050", "--height", "845", "--native"],
}
View
1  modules/weregild/module.cfg
@@ -1,4 +1,5 @@
{
id: "weregild",
+name: "Weregild",
#arguments: ["--width", "1050", "--height", "845", "--native"]
}
View
42 src/main.cpp
@@ -213,9 +213,6 @@ extern "C" int main(int argcount, char** argvec)
std::string orig_level_cfg = level_cfg;
std::string override_level_cfg = "";
- preferences::load_preferences();
- LOG( "After load_preferences()" );
-
std::vector<std::string> argv;
for(int n = 1; n < argcount; ++n) {
argv.push_back(argvec[n]);
@@ -224,12 +221,12 @@ extern "C" int main(int argcount, char** argvec)
if(sys::file_exists("./master-config.cfg")) {
variant cfg = json::parse_from_file("./master-config.cfg");
if(cfg.is_map()) {
- if(cfg["id"].is_null() == false) {
-#ifdef _WINDOWS
- preferences::set_preferences_path(GetAppDataPath() + "/" + cfg["id"].as_string());
-#else
- preferences::set_preferences_path("~/." + cfg["id"].as_string());
-#endif
+ if(cfg["name"].is_null() == false) {
+ preferences::set_preferences_path_from_module(cfg["name"].as_string());
+ module::set_module_name(cfg["name"].as_string());
+ } else if( cfg["id"].is_null() == false) {
+ preferences::set_preferences_path_from_module(cfg["id"].as_string());
+ module::set_module_name(cfg["id"].as_string());
}
if(cfg["arguments"].is_null() == false) {
std::vector<std::string> additional_args = cfg["arguments"].as_list_string();
@@ -247,7 +244,6 @@ extern "C" int main(int argcount, char** argvec)
arg_name = std::string(arg.begin(), equal);
arg_value = std::string(equal+1, arg.end());
}
-
if(arg_name == "--module") {
variant mod_info = module::get(arg_value);
if(mod_info.is_null()) {
@@ -260,11 +256,25 @@ extern "C" int main(int argcount, char** argvec)
const std::vector<std::string>& arguments = mod_info["arguments"].as_list_string();
argv.insert(argv.end(), arguments.begin(), arguments.end());
}
-#ifdef _WINDOWS
- preferences::set_preferences_path(GetAppDataPath() + "/" + module::get_module_name());
-#else
- preferences::set_preferences_path("~/." + module::get_module_name());
-#endif
+ preferences::set_preferences_path_from_module(module::get_module_name());
+ }
+ }
+
+ preferences::load_preferences();
+ LOG( "After load_preferences()" );
+
+ for(int n = 0; n < argv.size(); ++n) {
+ const int argc = argv.size();
+ const std::string arg(argv[n]);
+ std::string arg_name, arg_value;
+ std::string::const_iterator equal = std::find(arg.begin(), arg.end(), '=');
+ if(equal != arg.end()) {
+ arg_name = std::string(arg.begin(), equal);
+ arg_value = std::string(equal+1, arg.end());
+ }
+
+ if(arg_name == "--module") {
+ // ignore already processed.
} else if(arg_name == "--profile" || arg == "--profile") {
profile_output_buf = arg_value;
profile_output = profile_output_buf.c_str();
@@ -475,7 +485,7 @@ extern "C" int main(int argcount, char** argvec)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- SDL_WM_SetCaption("Frogatto", "Frogatto");
+ SDL_WM_SetCaption(module::get_module_name().c_str(), module::get_module_name().c_str());
std::cerr << "JOYSTICKS: " << SDL_NumJoysticks() << "\n";
View
19 src/module.cpp
@@ -1,6 +1,7 @@
#include "filesystem.hpp"
#include "foreach.hpp"
#include "json_parser.hpp"
+#include "module.hpp"
namespace module {
@@ -12,10 +13,14 @@ std::vector<std::string>& loaded_paths() {
}
}
-std::string module_loaded;
+std::string module_loaded_;
const std::string get_module_name(){
- return module_loaded.empty() ? "frogatto" : module_loaded;
+ return module_loaded_.empty() ? "frogatto" : module_loaded_;
+}
+
+void set_module_name(const std::string& name) {
+ module_loaded_ = name;
}
std::string map_file(const std::string& fname)
@@ -84,10 +89,18 @@ variant get(const std::string& name)
void load(const std::string& name)
{
- module_loaded = name;
+ std::string modname = name;
std::string fname = "modules/" + name + "/module.cfg";
variant v = json::parse_from_file(fname);
+ if(v.is_map()) {
+ if(v["name"].is_null() == false) {
+ modname = v["name"].as_string();
+ } else if(v["id"].is_null() == false) {
+ modname = v["id"].as_string();
+ }
+ }
+ set_module_name(modname);
loaded_paths().insert(loaded_paths().begin(), "./modules/" + name + "/");
}
View
1  src/module.hpp
@@ -9,6 +9,7 @@
namespace module {
+void set_module_name(const std::string& name);
const std::string get_module_name();
std::string map_file(const std::string& fname);
void get_unique_filenames_under_dir(const std::string& dir,
View
29 src/preferences.cpp
@@ -44,7 +44,7 @@ class WindowsPrefs
public:
State::State()
{
- this->preferences_path = GetAppDataPath();
+ this->preferences_path = GetAppDataPath() + "/" + module::get_module_name() + "/";
this->save_file_path = this->preferences_path + SAVE_FILENAME;
this->auto_save_file_path = this->preferences_path + AUTOSAVE_FILENAME;
}
@@ -226,8 +226,13 @@ namespace preferences {
bool use_fbo_ = true;
bool use_bequ_ = true;
bool use_16bpp_textures_ = false;
+
#else
+#if defined(_WINDOWS)
+#define PREFERENCES_PATH ""
+#endif // _WINDOWS
+
#ifndef NO_UPLOAD_STATS
bool send_stats_ = true;
#else
@@ -317,6 +322,19 @@ namespace preferences {
return !sys::get_dir(user_data_path()).empty();
}
+ void set_preferences_path_from_module( const std::string& name)
+ {
+#ifdef _WINDOWS
+ preferences::set_preferences_path(GetAppDataPath() + "/" + name + "/");
+#elif defined(__ANDROID__)
+ preferences::set_preferences_path("." + name + "/");
+#else
+ preferences::set_preferences_path("~/." + name + "/");
+#endif
+ save_file_path_ = preferences_path_ + SAVE_FILENAME;
+ auto_save_file_path_ = preferences_path_ + AUTOSAVE_FILENAME;
+ }
+
void set_preferences_path(const std::string& path)
{
preferences_path_ = path;
@@ -555,14 +573,19 @@ namespace preferences {
void load_preferences()
{
+ std::string path;
+ if(preferences_path_.empty()) {
#if defined( _WINDOWS )
preferences_path_ = winPrefs.GetPreferencePath();
save_file_path_ = winPrefs.GetSaveFilePath();
auto_save_file_path_ = winPrefs.GetAutoSaveFilePath();
- std::string path = preferences_path_;
+ path = preferences_path_;
#else
- std::string path = PREFERENCES_PATH;
+ path = PREFERENCES_PATH;
#endif // defined( _WINDOWS )
+ } else {
+ path = preferences_path_;
+ }
expand_path(path);
if(!sys::file_exists(path + "preferences.cfg")) {
return;
View
1  src/preferences.hpp
@@ -27,6 +27,7 @@ namespace preferences {
bool no_music();
void set_preferences_path(const std::string& path);
+ void set_preferences_path_from_module( const std::string& name);
bool setup_preferences_dir();
Please sign in to comment.
Something went wrong with that request. Please try again.