File: EntityInterface.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (86 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once

#include "iscript.h"
#include "iscriptinterface.h"

#include "ientity.h"

#include "EClassInterface.h"
#include "SceneGraphInterface.h"

namespace script 
{

// Visitor object
class EntityVisitor
{
public:
    virtual ~EntityVisitor() {}

    virtual void visit(const std::string& key, const std::string& value) = 0;
};

class ScriptEntityNode :
	public ScriptSceneNode
{
public:
	// Constructor, checks if the passed node is actually an entity
	ScriptEntityNode(const scene::INodePtr& node);

	// Methods wrapping to Entity class
	std::string getKeyValue(const std::string& key);
	void setKeyValue(const std::string& key, const std::string& value);
	bool isInherited(const std::string& key);

	ScriptEntityClass getEntityClass();
	bool isModel();
	bool isOfType(const std::string& className);
	Entity::KeyValuePairs getKeyValuePairs(const std::string& prefix);

	// Visit each keyvalue, wraps to the contained entity
	void forEachKeyValue(EntityVisitor& visitor);

	// Checks if the given SceneNode structure is an EntityNode
	static bool isEntity(const ScriptSceneNode& node);

	// "Cast" service for Python, returns a ScriptEntityNode.
	// The returned node is non-NULL if the cast succeeded
	static ScriptEntityNode getEntity(const ScriptSceneNode& node);
};

// Wrap around the EntityClassVisitor interface
class EntityVisitorWrapper :
    public EntityVisitor
{
public:
	void visit(const std::string& key, const std::string& value) override
	{
		// Wrap this method to python
		PYBIND11_OVERLOAD_PURE(
			void,			/* Return type */
			EntityVisitor,  /* Parent class */
			visit,			/* Name of function in C++ (must match Python name) */
			key, value		/* Argument(s) */
		);
	}
};

/**
 * greebo: This class registers the entity interface with the
 * scripting system.
 */
class EntityInterface :
	public IScriptInterface
{
public:
	// Creates a new entity for the given entityclass
	ScriptSceneNode createEntity(const ScriptEntityClass& eclass);

	// Creates a new entity for the named entityclass
	ScriptSceneNode createEntity(const std::string& eclassName);

	// IScriptInterface implementation
	void registerInterface(py::module& scope, py::dict& globals) override;
};

} // namespace script