diff --git a/src/tools/prefs.hpp b/src/tools/prefs.hpp index cc2c0356..6e0c3251 100644 --- a/src/tools/prefs.hpp +++ b/src/tools/prefs.hpp @@ -30,6 +30,9 @@ inline bool get_iarray_pref_contains(std::string keypath, int value) { return std::find(val.begin(), val.end(), value) != val.end(); } +void set_pref(std::string keypath, std::string value); +std::string get_string_pref(std::string keypath, std::string fallback = ""); + void clear_pref(std::string keypath); bool sync_prefs(); diff --git a/src/tools/prefs.mac.mm b/src/tools/prefs.mac.mm index f72b9dec..c1ab4a51 100644 --- a/src/tools/prefs.mac.mm +++ b/src/tools/prefs.mac.mm @@ -19,7 +19,8 @@ typedef NS_ENUM(NSInteger) { kInt = 0, kBool = 1, kFloat = 2, - kIArray = 3 + kIArray = 3, + kString = 4 } PrefType; NSUserDefaults* replayUserDefaults = nil; @@ -46,6 +47,10 @@ static NSString* convertKey(std::string keypath) { return key; } +static std::string convertValue(NSString* value) { + return std::string([value cStringUsingEncoding : NSASCIIStringEncoding]); +} + static NSUserDefaults* getCurrentDefaults() { if(replaying){ return replayUserDefaults; @@ -102,6 +107,19 @@ std::vector get_iarray_pref(std::string keypath) { return result; } +void set_pref(std::string keypath, std::string val) { + NSString* key = convertKey(keypath); + // Not a key, but convertKey() still works, don't it? + NSString* value = convertKey(val); + [getCurrentDefaults() setObject: value forKey: key]; +} + +std::string get_string_pref(std::string keypath, std::string fallback) { + NSString* val = [getCurrentDefaults() stringForKey: convertKey(keypath)]; + if(val == nil) return fallback; + return convertValue(val); +} + void clear_pref(std::string keypath) { [getCurrentDefaults() setValue: nil forKey: convertKey(keypath)]; } @@ -153,6 +171,9 @@ static bool load_prefs(std::istream& istream) { case kInt: set_pref(key, boost::lexical_cast(val)); break; + // NOTE: The core game currently has no string preferences, so the recording system doesn't need to know + // about them for now. + case kString: break; } } @@ -199,6 +220,9 @@ bool sync_prefs() { double fvalue = (double)[standard doubleForKey: pref]; prefs_recording << fvalue; } break; + // NOTE: The core game currently has no string preferences, so the recording system doesn't need to know + // about them for now. + case kString: break; } prefs_recording << std::endl; }