| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "iscenegraph.h" |
| 4 |
#include "ientity.h" |
| 5 |
|
| 6 |
namespace scene |
| 7 |
{ |
| 8 |
|
| 9 |
// Tries to locate the named actor in the current map |
| 10 |
class ActorNodeFinder : |
| 11 |
public scene::NodeVisitor |
| 12 |
{ |
| 13 |
private: |
| 14 |
std::string _actorName; |
| 15 |
|
| 16 |
scene::INodePtr _foundNode; |
| 17 |
|
| 18 |
public: |
| 19 |
ActorNodeFinder(const std::string& actorName) : |
| 20 |
_actorName(actorName) |
| 21 |
{} |
| 22 |
|
| 23 |
bool pre(const scene::INodePtr& node) |
| 24 |
{ |
| 25 |
if (_foundNode) return false; // we've already found what we're looking for |
| 26 |
|
| 27 |
Entity* entity = Node_getEntity(node); |
| 28 |
|
| 29 |
if (entity == nullptr) return true; |
| 30 |
|
| 31 |
// Found an entity, compare names |
| 32 |
if (entity->getKeyValue("name") == _actorName) |
| 33 |
{ |
| 34 |
_foundNode = node; |
| 35 |
} |
| 36 |
|
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
const scene::INodePtr& getFoundNode() const |
| 41 |
{ |
| 42 |
return _foundNode; |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
} |