Skip to content

Commit

Permalink
Migrate MapInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 20, 2017
1 parent 1ce7cbe commit e0c870e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 2 additions & 0 deletions install/scripts/test.py
Expand Up @@ -90,6 +90,8 @@ def visit(self, node):
visitor = Walker()
GlobalSelectionSystem.foreachSelected(visitor)

print('Map name is ' + GlobalMap.getMapName())

# Try to find the map's worldspawn
worldspawn = GlobalMap.getWorldSpawn()

Expand Down
18 changes: 11 additions & 7 deletions plugins/script/interfaces/MapInterface.cpp
@@ -1,8 +1,11 @@
#include "MapInterface.h"

#include <pybind11/pybind11.h>

#include "imap.h"

namespace script {
namespace script
{

ScriptSceneNode MapInterface::getWorldSpawn()
{
Expand All @@ -15,15 +18,16 @@ std::string MapInterface::getMapName()
}

// IScriptInterface implementation
void MapInterface::registerInterface(boost::python::object& nspace) {
void MapInterface::registerInterface(py::module& scope, py::dict& globals)
{
// Add the module declaration to the given python namespace
nspace["GlobalMap"] = boost::python::class_<MapInterface>("GlobalMap")
.def("getWorldSpawn", &MapInterface::getWorldSpawn)
.def("getMapName", &MapInterface::getMapName)
;
py::class_<MapInterface> map(scope, "Map");

map.def("getWorldSpawn", &MapInterface::getWorldSpawn);
map.def("getMapName", &MapInterface::getMapName);

// Now point the Python variable "GlobalMap" to this instance
nspace["GlobalMap"] = boost::python::ptr(this);
globals["GlobalMap"] = this;
}

} // namespace script
15 changes: 5 additions & 10 deletions plugins/script/interfaces/MapInterface.h
@@ -1,16 +1,14 @@
#ifndef _MAP_INTERFACE_H_
#define _MAP_INTERFACE_H_

#include <boost/python.hpp>
#pragma once

#include "iscript.h"

#include "SceneGraphInterface.h"

namespace script {
namespace script
{

/**
* greebo: This class provides the script interface for the GlobalEntityClassManager module.
* greebo: This class provides the script interface for the GlobalMap module.
*/
class MapInterface :
public IScriptInterface
Expand All @@ -20,10 +18,7 @@ class MapInterface :
std::string getMapName();

// IScriptInterface implementation
void registerInterface(boost::python::object& nspace);
void registerInterface(py::module& scope, py::dict& globals) override;
};
typedef std::shared_ptr<MapInterface> MapInterfacePtr;

} // namespace script

#endif /* _MAP_INTERFACE_H_ */

0 comments on commit e0c870e

Please sign in to comment.