Debian Codegraph @

plugins/dm.difficulty/DifficultyEntity.cpp

raw
1 #include "DifficultyEntity.h"
2
3 #include "ientity.h"
4 #include "string/convert.h"
5
6 namespace difficulty {
7
8 DifficultyEntity::DifficultyEntity(Entity* source) :
9 _entity(source),
10 _curId(0)
11 {}
12
13 void DifficultyEntity::clear() {
14 // Find all spawnargs starting with a "diff_"
15 Entity::KeyValuePairs pairs = _entity->getKeyValuePairs("diff_");
16
17 // Remove all (set the value to the empty string "")
18 for (Entity::KeyValuePairs::iterator i = pairs.begin(); i != pairs.end(); i++) {
19 _entity->setKeyValue(i->first, "");
20 }
21
22 _curId = 0;
23 }
24
25 void DifficultyEntity::writeSetting(const SettingPtr& setting, int _level) {
26 // Construct the prefix and index strings
27 std::string prefix = "diff_" + string::to_string(_level) + "_";
28 std::string idx = string::to_string(_curId);
29
30 // Save the spawnargs
31 _entity->setKeyValue(prefix + "class_" + idx, setting->className);
32 _entity->setKeyValue(prefix + "change_" + idx, setting->spawnArg);
33 _entity->setKeyValue(prefix + "arg_" + idx, setting->getArgumentKeyValue());
34
35 // Increase the ID
36 _curId++;
37 }
38
39 } // namespace difficulty