Debian Codegraph @

plugins/dm.difficulty/Setting.cpp

raw
1 #include "Setting.h"
2
3 #include "i18n.h"
4 #include "iregistry.h"
5 #include "gamelib.h"
6
7 namespace difficulty
8 {
9
10 namespace
11 {
12 const std::string GKEY_APPTYPE_IGNORE("/difficulty/appTypeIgnore");
13 }
14
15 Setting::Setting() :
16 id(++_highestId),
17 isDefault(false)
18 {}
19
20 std::string Setting::getArgumentKeyValue() const {
21 std::string returnValue(argument);
22
23 switch (appType) {
24 case EAssign: break;
25 case EAdd:
26 returnValue = "+" + returnValue;
27 break;
28 case EMultiply:
29 returnValue = "*" + returnValue;
30 break;
31 case EIgnore:
32 returnValue = game::current::getValue<std::string>(GKEY_APPTYPE_IGNORE);
33 break;
34 default:
35 break;
36 };
37
38 return returnValue;
39 }
40
41 std::string Setting::getDescString() const {
42 std::string returnValue(argument);
43
44 switch (appType) {
45 case EAssign:
46 returnValue = " = " + returnValue;
47 break;
48 case EAdd:
49 returnValue = " += " + returnValue;
50 break;
51 case EMultiply:
52 returnValue = " *= " + returnValue;
53 break;
54 case EIgnore:
55 returnValue = " = [IGNORE]";
56 break;
57 default:
58 break;
59 };
60
61 returnValue = spawnArg + returnValue;
62 return returnValue;
63 }
64
65 bool Setting::operator==(const Setting& rhs) const {
66 return className == rhs.className &&
67 spawnArg == rhs.spawnArg &&
68 argument == rhs.argument &&
69 appType == rhs.appType;
70 }
71
72 bool Setting::operator!=(const Setting& rhs) const {
73 return !operator==(rhs);
74 }
75
76 Setting& Setting::operator=(const Setting& rhs) {
77 className = rhs.className;
78 spawnArg = rhs.spawnArg;
79 argument = rhs.argument;
80 appType = rhs.appType;
81 isDefault = rhs.isDefault;
82
83 return *this;
84 }
85
86 void Setting::parseAppType() {
87 appType = EAssign;
88
89 if (!argument.empty())
90 {
91 // Check for ignore argument
92 if (argument == game::current::getValue<std::string>(GKEY_APPTYPE_IGNORE))
93 {
94 appType = EIgnore;
95 argument.clear(); // clear the argument
96 }
97 // Check for special modifiers
98 else if (argument[0] == '+')
99 {
100 appType = EAdd;
101 // Remove the first character
102 argument = argument.substr(1);
103 }
104 else if (argument[0] == '*')
105 {
106 appType = EMultiply;
107 // Remove the first character
108 argument = argument.substr(1);
109 }
110 else if (argument[0] == '-')
111 {
112 appType = EAdd;
113 // Leave the "-" sign, it will be the sign of the parsed int
114 }
115 }
116 }
117
118 // Initialise the static member
119 int Setting::_highestId = 0;
120
121 } // namespace difficulty