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 56 57 58 59 60 61 62
|
#pragma once
#include <map>
#include <sigc++/signal.h>
#include "TargetKey.h"
namespace entity
{
class TargetableNode;
class TargetKeyCollection :
public Entity::Observer
{
private:
TargetableNode& _owner;
// greebo: A container mapping "targetN" keys to TargetKey objects
typedef std::map<std::string, TargetKey> TargetKeyMap;
TargetKeyMap _targetKeys;
sigc::signal<void> _sigTargetPositionChanged;
public:
TargetKeyCollection(TargetableNode& owner);
// Might return nullptr if not inserted in the scene
ITargetManager* getTargetManager();
// Called by the owning TargetableNode to notify this class of a new target manager
// Since not all nodes are inserted in a scene by the time the target spawnargs are
// set we might need to call this at a later point.
void onTargetManagerChanged();
// Entity::Observer implementation, gets called on key insert/erase
void onKeyInsert(const std::string& key, EntityKeyValue& value);
void onKeyErase(const std::string& key, EntityKeyValue& value);
/**
* greebo: Walker function, calls visit() for each target
* contained in this structure.
*/
void forEachTarget(const std::function<void(const TargetPtr&)>& func) const;
// Returns the number of target keys
std::size_t getNumTargets() const;
// Returns TRUE if there are no "target" keys observed
bool empty() const;
// The TargetLineNode listens to this to reconstructs its renderables
sigc::signal<void>& signal_TargetPositionChanged();
// Invoked by the TargetKey instance if a single Target changes its position
void onTargetPositionChanged();
private:
// Returns TRUE if the given key matches the pattern for target keys
bool isTargetKey(const std::string& key);
};
} // namespace entity
|