From e0c870e62b7bff07e9ab5382ce52400bf3faf1ce Mon Sep 17 00:00:00 2001 From: codereader Date: Thu, 20 Jul 2017 17:54:02 +0200 Subject: [PATCH] Migrate MapInterface --- install/scripts/test.py | 2 ++ plugins/script/interfaces/MapInterface.cpp | 18 +++++++++++------- plugins/script/interfaces/MapInterface.h | 15 +++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/install/scripts/test.py b/install/scripts/test.py index 4cb8468e5e..255b897016 100644 --- a/install/scripts/test.py +++ b/install/scripts/test.py @@ -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() diff --git a/plugins/script/interfaces/MapInterface.cpp b/plugins/script/interfaces/MapInterface.cpp index 65a570ffe8..dc7779439d 100644 --- a/plugins/script/interfaces/MapInterface.cpp +++ b/plugins/script/interfaces/MapInterface.cpp @@ -1,8 +1,11 @@ #include "MapInterface.h" +#include + #include "imap.h" -namespace script { +namespace script +{ ScriptSceneNode MapInterface::getWorldSpawn() { @@ -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_("GlobalMap") - .def("getWorldSpawn", &MapInterface::getWorldSpawn) - .def("getMapName", &MapInterface::getMapName) - ; + py::class_ 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 diff --git a/plugins/script/interfaces/MapInterface.h b/plugins/script/interfaces/MapInterface.h index c8dbadfd2e..cc4ed4e9cc 100644 --- a/plugins/script/interfaces/MapInterface.h +++ b/plugins/script/interfaces/MapInterface.h @@ -1,16 +1,14 @@ -#ifndef _MAP_INTERFACE_H_ -#define _MAP_INTERFACE_H_ - -#include +#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 @@ -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 MapInterfacePtr; } // namespace script - -#endif /* _MAP_INTERFACE_H_ */