Skip to content

Commit

Permalink
Extend Map Script Interface by point file and merge edit mode methods…
Browse files Browse the repository at this point in the history
…. Also include GlobalMap.getRoot since that's useful too.
  • Loading branch information
codereader committed Jun 6, 2021
1 parent 9ec9971 commit 16a0abc
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
16 changes: 16 additions & 0 deletions install/scripts/test.py
Expand Up @@ -93,6 +93,22 @@ def visit(self, node):

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

print(GlobalMap.getEditMode())

# Switching Map Modes
GlobalMap.setEditMode(MapEditMode.Merge)
GlobalMap.setEditMode(MapEditMode.Normal)

# Point File Management is visible
print(GlobalMap.showPointFile("test.lin"))
print(GlobalMap.isPointTraceVisible())

# Enumerate the point files available for the current map
print("Point files found: " + str(len(GlobalMap.getPointFileList())))

for path in GlobalMap.getPointFileList:
print("Pointfile: " + path)

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

Expand Down
62 changes: 61 additions & 1 deletion plugins/script/interfaces/MapInterface.cpp
Expand Up @@ -17,14 +17,74 @@ std::string MapInterface::getMapName()
return GlobalMapModule().getMapName();
}

IMap::EditMode MapInterface::getEditMode()
{
return GlobalMapModule().getEditMode();
}

void MapInterface::setEditMode(IMap::EditMode mode)
{
GlobalMapModule().setEditMode(mode);
}

ScriptSceneNode MapInterface::getRoot()
{
return ScriptSceneNode(GlobalMapModule().getRoot());
}

bool MapInterface::isModified()
{
return GlobalMapModule().isModified();
}

void MapInterface::showPointFile(const std::string& filePath)
{
if (!filePath.empty())
{
GlobalMapModule().showPointFile(filePath);
}
}

bool MapInterface::isPointTraceVisible()
{
return GlobalMapModule().isPointTraceVisible();
}

std::vector<std::string> MapInterface::getPointFileList()
{
std::vector<std::string> files;

GlobalMapModule().forEachPointfile([&](const fs::path& path)
{
files.push_back(path.string());
});

return files;
}

// IScriptInterface implementation
void MapInterface::registerInterface(py::module& scope, py::dict& globals)
{
// Add the module declaration to the given python namespace
// Add the module declaration to the given python namespace
py::class_<MapInterface> map(scope, "Map");

// Expose the edit mode enum
py::enum_<IMap::EditMode>(scope, "MapEditMode")
.value("Normal", IMap::EditMode::Normal)
.value("Merge", IMap::EditMode::Merge)
.export_values();

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

map.def("getEditMode", &MapInterface::getEditMode);
map.def("setEditMode", &MapInterface::setEditMode);

map.def("showPointFile", &MapInterface::showPointFile);
map.def("isPointTraceVisible", &MapInterface::isPointTraceVisible);
map.def("getPointFileList", &MapInterface::getPointFileList);

// Now point the Python variable "GlobalMap" to this instance
globals["GlobalMap"] = this;
Expand Down
12 changes: 10 additions & 2 deletions plugins/script/interfaces/MapInterface.h
Expand Up @@ -15,8 +15,16 @@ class MapInterface :
public IScriptInterface
{
public:
ScriptSceneNode getWorldSpawn();
std::string getMapName();
ScriptSceneNode getWorldSpawn();
std::string getMapName();
bool isModified();
ScriptSceneNode getRoot();
IMap::EditMode getEditMode();
void setEditMode(IMap::EditMode mode);

void showPointFile(const std::string& filePath);
bool isPointTraceVisible();
std::vector<std::string> getPointFileList();

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

0 comments on commit 16a0abc

Please sign in to comment.