Skip to content

Commit

Permalink
#6023: Start exposing the DeclarationManager interface to Python scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 28, 2022
1 parent eae2a8e commit c58edd6
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/script/CMakeLists.txt
Expand Up @@ -2,6 +2,7 @@ add_library(script MODULE
interfaces/BrushInterface.cpp
interfaces/CameraInterface.cpp
interfaces/CommandSystemInterface.cpp
interfaces/DeclarationManagerInterface.cpp
interfaces/DialogInterface.cpp
interfaces/EClassInterface.cpp
interfaces/EntityInterface.cpp
Expand Down
2 changes: 2 additions & 0 deletions plugins/script/ScriptingSystem.cpp
Expand Up @@ -34,6 +34,7 @@
#include "interfaces/SelectionGroupInterface.h"
#include "interfaces/CameraInterface.h"
#include "interfaces/LayerInterface.h"
#include "interfaces/DeclarationManagerInterface.h"

#include "PythonModule.h"

Expand Down Expand Up @@ -328,6 +329,7 @@ void ScriptingSystem::initialiseModule(const IApplicationContext& ctx)
addInterface("SelectionGroupInterface", std::make_shared<SelectionGroupInterface>());
addInterface("CameraInterface", std::make_shared<CameraInterface>());
addInterface("LayerInterface", std::make_shared<LayerInterface>());
addInterface("DeclarationManager", std::make_shared<DeclarationManagerInterface>());

GlobalCommandSystem().addCommand(
"RunScript",
Expand Down
29 changes: 29 additions & 0 deletions plugins/script/interfaces/DeclarationManagerInterface.cpp
@@ -0,0 +1,29 @@
#include "DeclarationManagerInterface.h"

namespace script
{

ScriptDeclaration DeclarationManagerInterface::findDeclaration(decl::Type type, const std::string& name)
{
return ScriptDeclaration({});
}

void DeclarationManagerInterface::registerInterface(py::module& scope, py::dict& globals)
{
py::class_<ScriptDeclaration> declaration(scope, "Declaration");

py::enum_<decl::Type>(declaration, "Type")
.value("None", decl::Type::None)
.value("Material", decl::Type::Material)
.value("Table", decl::Type::Table)
.value("EntityDef", decl::Type::EntityDef)
.value("SoundShader", decl::Type::SoundShader)
.value("ModelDef", decl::Type::ModelDef)
.value("Particle", decl::Type::Particle)
.value("Skin", decl::Type::Skin)
.export_values();


}

}
37 changes: 37 additions & 0 deletions plugins/script/interfaces/DeclarationManagerInterface.h
@@ -0,0 +1,37 @@
#pragma once

#include "iscriptinterface.h"
#include "ideclmanager.h"

namespace script
{

// Wrapper class to represent an IDeclaration object in Python
class ScriptDeclaration
{
private:
decl::IDeclaration::Ptr _decl;

public:
ScriptDeclaration(const decl::IDeclaration::Ptr& decl) :
_decl(decl)
{}

// TODO
};

/**
* Exposes the GlobalDeclarationManager interface to scripts
*/
class DeclarationManagerInterface :
public IScriptInterface
{
public:
// Mapped methods
ScriptDeclaration findDeclaration(decl::Type type, const std::string& name);

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

}
2 changes: 2 additions & 0 deletions tools/msvc/script.vcxproj
Expand Up @@ -217,6 +217,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\plugins\script\interfaces\CameraInterface.h" />
<ClInclude Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.h" />
<ClInclude Include="..\..\plugins\script\interfaces\LayerInterface.h" />
<ClInclude Include="..\..\plugins\script\interfaces\SelectionGroupInterface.h" />
<ClInclude Include="..\..\plugins\script\precompiled.h" />
Expand Down Expand Up @@ -248,6 +249,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\plugins\script\interfaces\CameraInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\LayerInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\SceneGraphInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\SelectionGroupInterface.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/script.vcxproj.filters
Expand Up @@ -97,6 +97,9 @@
<ClInclude Include="..\..\plugins\script\interfaces\LayerInterface.h">
<Filter>src\interfaces</Filter>
</ClInclude>
<ClInclude Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.h">
<Filter>src\interfaces</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\plugins\script\SceneNodeBuffer.cpp">
Expand Down Expand Up @@ -183,5 +186,8 @@
<ClCompile Include="..\..\plugins\script\interfaces\LayerInterface.cpp">
<Filter>src\interfaces</Filter>
</ClCompile>
<ClCompile Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.cpp">
<Filter>src\interfaces</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit c58edd6

Please sign in to comment.