Debian Codegraph @

plugins/script/interfaces/RadiantInterface.cpp

raw
1 #include "RadiantInterface.h"
2
3 #include <pybind11/pybind11.h>
4
5 #include "iscenegraph.h"
6 #include "entitylib.h"
7
8 namespace script
9 {
10
11 ScriptEntityNode RadiantInterface::findEntityByClassname(const std::string& name)
12 {
13 EntityNodeFindByClassnameWalker walker(name);
14 GlobalSceneGraph().root()->traverse(walker);
15
16 // Note: manage_new_object return value policy will take care of that raw pointer
17 return ScriptEntityNode(walker.getEntityNode());
18 }
19
20 ScriptEntityNode RadiantInterface::findEntityByName(const std::string& name)
21 {
22 scene::INodePtr found;
23
24 GlobalSceneGraph().root()->foreachNode([&] (const scene::INodePtr& node)
25 {
26 if (Node_isEntity(node) && Node_getEntity(node)->getKeyValue("name") == name)
27 {
28 found = node;
29 }
30
31 return true;
32 });
33
34 // Note: manage_new_object return value policy will take care of that raw pointer
35 return ScriptEntityNode(found);
36 }
37
38 void RadiantInterface::registerInterface(py::module& scope, py::dict& globals)
39 {
40 py::class_<RadiantInterface> radiant(scope, "RadiantInterface");
41 radiant.def("findEntityByClassname", &RadiantInterface::findEntityByClassname);
42 radiant.def("findEntityByName", &RadiantInterface::findEntityByName);
43
44 // Point the radiant variable to this
45 globals["Radiant"] = this;
46 }
47
48 } // namespace script