Debian Codegraph @

plugins/dm.stimresponse/SRPropertyRemover.cpp

raw
1 #include "SRPropertyRemover.h"
2
3 #include "iregistry.h"
4 #include "gamelib.h"
5 #include "entitylib.h"
6 #include <regex>
7
8 SRPropertyRemover::SRPropertyRemover(
9 Entity* target,
10 SREntity::KeyList& keys
11 ) :
12 _target(target),
13 _keys(keys)
14 {}
15
16 SRPropertyRemover::~SRPropertyRemover() {
17 for (unsigned int i = 0; i < _removeList.size(); i++) {
18 // Delete the key
19 _target->setKeyValue(_removeList[i], "");
20 }
21 }
22
23 void SRPropertyRemover::visitKeyValue(const std::string& key, const std::string& value)
24 {
25 std::string prefix = game::current::getValue<std::string>(GKEY_STIM_RESPONSE_PREFIX);
26
27 // Now cycle through the possible key names and see if we have a match
28 for (unsigned int i = 0; i < _keys.size(); i++) {
29 // Construct a regex with the number as match variable
30 std::string exprStr = "^" + prefix + _keys[i].key + "_([0-9])+$";
31 std::regex expr(exprStr);
32 std::smatch matches;
33
34 if (std::regex_match(key, matches, expr)) {
35 // We have a match, set the key on the black list
36 _removeList.push_back(key);
37 }
38 }
39
40 // This should search for something like "sr_effect_2_3*"
41 std::string exprStr = "^" + prefix + "effect" + "_([0-9])+_([0-9])+(.*)$";
42 std::regex expr(exprStr);
43 std::smatch matches;
44
45 if (std::regex_match(key, matches, expr)) {
46 _removeList.push_back(key);
47 }
48 }