/
WorldspawnArgFinder.h
55 lines (43 loc) · 1.11 KB
/
WorldspawnArgFinder.h
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
#ifndef _WORLDSPAWN_ARG_FINDER_H_
#define _WORLDSPAWN_ARG_FINDER_H_
#include "ientity.h"
#include "inode.h"
#include <string>
namespace map {
/**
* greebo: This class can be used to traverse a subgraph to search
* for a specific spawnarg on the worldspawn entity. The method
* getValue() can be used to retrieve the value of the key as specified
* in the constructor.
*/
class WorldspawnArgFinder :
public scene::NodeVisitor
{
std::string _key;
std::string _value;
public:
WorldspawnArgFinder(const std::string& keyName) :
_key(keyName)
{}
bool pre(const scene::INodePtr& node) {
// Try to cast this node onto an entity
Entity* ent = Node_getEntity(node);
if (ent != NULL) {
if (ent->isWorldspawn()) {
// Load the description spawnarg
_value = ent->getKeyValue(_key);
}
return false; // don't traverse entities
}
return true;
}
/**
* Returns the found value for the desired spawnarg. If not found,
* this function will return an empty string "".
*/
const std::string& getFoundValue() const {
return _value;
}
};
} // namespace map
#endif /* _WORLDSPAWN_ARG_FINDER_H_ */