-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "Preferences.h" | ||
#include "Utilities/ResourceManager.h" | ||
#include <map> | ||
|
||
namespace Preferences | ||
{ | ||
|
||
typedef std::map<std::string, std::string> PreferenceMap; | ||
PreferenceMap preferences; | ||
|
||
std::string Get ( const std::string& key, const std::string& defaultValue ) | ||
{ | ||
PreferenceMap::iterator iter = preferences.find(key); | ||
if (iter == preferences.end()) | ||
{ | ||
return defaultValue; | ||
} | ||
else | ||
{ | ||
return iter->second; | ||
} | ||
} | ||
|
||
void Set ( const std::string& key, const std::string& defaultValue ) | ||
{ | ||
preferences[key] = defaultValue; | ||
} | ||
|
||
void Clear ( const std::string& key ) | ||
{ | ||
PreferenceMap::iterator iter = preferences.find(key); | ||
if (iter != preferences.end()) | ||
{ | ||
preferences.erase(iter); | ||
} | ||
} | ||
|
||
static void ParseLine ( const std::string& line ) | ||
{ | ||
if (line != "") | ||
{ | ||
std::string::size_type n = line.find_first_of(':'); | ||
std::string k = line.substr(0, n); | ||
std::string v = line.substr(n + 1, std::string::npos); | ||
preferences[k] = v; | ||
} | ||
} | ||
|
||
void Load () | ||
{ | ||
preferences.clear(); | ||
SDL_RWops* ops = ResourceManager::OpenFile("Config/Preferences.cfg"); | ||
if (!ops) | ||
return; | ||
size_t len; | ||
char* buffer = (char*)ResourceManager::ReadFull(&len, ops, 1); | ||
std::string preferenceLine; | ||
char* tempPointer = buffer; | ||
while (*tempPointer) | ||
{ | ||
char ch = *tempPointer; | ||
if (ch == '\n') | ||
{ | ||
ParseLine(preferenceLine); | ||
preferenceLine.clear(); | ||
} | ||
else | ||
{ | ||
preferenceLine.push_back(ch); | ||
} | ||
tempPointer++; | ||
} | ||
free((void*)buffer); | ||
} | ||
|
||
void Save () | ||
{ | ||
std::string buffer; | ||
for ( PreferenceMap::iterator iter = preferences.begin(); iter != preferences.end(); iter++ ) | ||
{ | ||
buffer.append(iter->first + ":" + iter->second + "\n"); | ||
} | ||
ResourceManager::WriteFile("Config/Preferences.cfg", buffer.data(), buffer.length()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef __xsera_preferences_h | ||
#define __xsera_preferences_h | ||
|
||
#include <string> | ||
|
||
namespace Preferences | ||
{ | ||
|
||
std::string Get ( const std::string& key, const std::string& defaultValue = "" ); | ||
void Set ( const std::string& key, const std::string& newValue ); | ||
void Clear ( const std::string& key ); | ||
|
||
void Load (); | ||
void Save (); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Screen/Width:800 | ||
Screen/Height:600 | ||
Screen/Fullscreen:false | ||
Audio/SamplingRate:48000 | ||
Audio/Resolution:24 | ||
Audio/Channels:64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters