| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "iscript.h" |
| 4 |
#include "iscriptinterface.h" |
| 5 |
|
| 6 |
#include "ientity.h" |
| 7 |
|
| 8 |
#include "EClassInterface.h" |
| 9 |
#include "SceneGraphInterface.h" |
| 10 |
|
| 11 |
namespace script |
| 12 |
{ |
| 13 |
|
| 14 |
// Visitor object |
| 15 |
class EntityVisitor |
| 16 |
{ |
| 17 |
public: |
| 18 |
virtual ~EntityVisitor() {} |
| 19 |
|
| 20 |
virtual void visit(const std::string& key, const std::string& value) = 0; |
| 21 |
}; |
| 22 |
|
| 23 |
class ScriptEntityNode : |
| 24 |
public ScriptSceneNode |
| 25 |
{ |
| 26 |
public: |
| 27 |
// Constructor, checks if the passed node is actually an entity |
| 28 |
ScriptEntityNode(const scene::INodePtr& node); |
| 29 |
|
| 30 |
// Methods wrapping to Entity class |
| 31 |
std::string getKeyValue(const std::string& key); |
| 32 |
void setKeyValue(const std::string& key, const std::string& value); |
| 33 |
bool isInherited(const std::string& key); |
| 34 |
|
| 35 |
ScriptEntityClass getEntityClass(); |
| 36 |
bool isModel(); |
| 37 |
bool isOfType(const std::string& className); |
| 38 |
Entity::KeyValuePairs getKeyValuePairs(const std::string& prefix); |
| 39 |
|
| 40 |
// Visit each keyvalue, wraps to the contained entity |
| 41 |
void forEachKeyValue(EntityVisitor& visitor); |
| 42 |
|
| 43 |
// Checks if the given SceneNode structure is an EntityNode |
| 44 |
static bool isEntity(const ScriptSceneNode& node); |
| 45 |
|
| 46 |
// "Cast" service for Python, returns a ScriptEntityNode. |
| 47 |
// The returned node is non-NULL if the cast succeeded |
| 48 |
static ScriptEntityNode getEntity(const ScriptSceneNode& node); |
| 49 |
}; |
| 50 |
|
| 51 |
// Wrap around the EntityClassVisitor interface |
| 52 |
class EntityVisitorWrapper : |
| 53 |
public EntityVisitor |
| 54 |
{ |
| 55 |
public: |
| 56 |
void visit(const std::string& key, const std::string& value) override |
| 57 |
{ |
| 58 |
// Wrap this method to python |
| 59 |
PYBIND11_OVERLOAD_PURE( |
| 60 |
void, /* Return type */ |
| 61 |
EntityVisitor, /* Parent class */ |
| 62 |
visit, /* Name of function in C++ (must match Python name) */ |
| 63 |
key, value /* Argument(s) */ |
| 64 |
); |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
/** |
| 69 |
* greebo: This class registers the entity interface with the |
| 70 |
* scripting system. |
| 71 |
*/ |
| 72 |
class EntityInterface : |
| 73 |
public IScriptInterface |
| 74 |
{ |
| 75 |
public: |
| 76 |
// Creates a new entity for the given entityclass |
| 77 |
ScriptSceneNode createEntity(const ScriptEntityClass& eclass); |
| 78 |
|
| 79 |
// Creates a new entity for the named entityclass |
| 80 |
ScriptSceneNode createEntity(const std::string& eclassName); |
| 81 |
|
| 82 |
// IScriptInterface implementation |
| 83 |
void registerInterface(py::module& scope, py::dict& globals) override; |
| 84 |
}; |
| 85 |
|
| 86 |
} // namespace script |