forked from asantee/ETHFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserDataManager.angelscript
59 lines (51 loc) · 1.78 KB
/
UserDataManager.angelscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const string ETH_FRAMEWORK_USER_DATA_FILE_NAME = "ethf.user.data";
class UserDataManager
{
void saveValue(const string &in entity, const string &in valueName, const string &in value)
{
const string filePath = GetExternalStoragePath() + ETH_FRAMEWORK_USER_DATA_FILE_NAME;
const string content = GetStringFromFile(filePath);
enmlFile userData;
userData.parseString(content);
userData.addValue(entity, valueName, value);
userData.writeToFile(filePath);
}
string loadValue(const string &in entity, const string &in valueName, const string &in defaultValue)
{
const string filePath = GetExternalStoragePath() + ETH_FRAMEWORK_USER_DATA_FILE_NAME;
const string content = GetStringFromFile(filePath);
enmlFile userData;
userData.parseString(content);
const string value = userData.get(entity, valueName);
return (value != "") ? value : defaultValue;
}
void saveFloat(const string &in entity, const string &in valueName, const float value)
{
saveValue(entity, valueName, "" + value);
}
float loadFloat(const string &in entity, const string &in valueName, const float defaultValue)
{
const string value = loadValue(entity, valueName, "" + defaultValue);
return ParseFloat(value);
}
void saveBoolean(const string &in entity, const string &in valueName, const bool value)
{
saveValue(entity, valueName, boolToString(value));
}
bool loadBoolean(const string &in entity, const string &in valueName, const bool defaultValue)
{
const string value = loadValue(entity, valueName, boolToString(defaultValue));
return isTrue(value);
}
string boolToString(const bool value)
{
return value ? "true" : "false";
}
bool isTrue(const string &in value)
{
if (value == "true" || value == "TRUE" || value == "YES" || value == "yes")
return true;
else
return false;
}
}