Skip to content

Commit

Permalink
#6092: Add FX-related script interfaces (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 6, 2022
1 parent d959c2b commit de2ae8a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions install/scripts/test.py
Expand Up @@ -27,6 +27,15 @@ def visit(self, decl):

GlobalDeclarationManager.foreachDeclaration(Declaration.Type.ModelDef, visitor)

# FX interface
fx = GlobalFxManager.findFx("fx/sparks")

# An FX declaration inherits all the Declaration methods and properties
print("Name: " + fx.getDeclName())
print("Type: " + str(fx.getDeclType()))
print("Defined in: " + str(fx.getDeclFilePath()))
print("Definition: " + fx.getBlockSyntax().contents)

# Create a new material
myOwnMaterial = GlobalDeclarationManager.findOrCreateDeclaration(Declaration.Type.Material, "textures/myown_material")

Expand Down
1 change: 1 addition & 0 deletions plugins/script/CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ add_library(script MODULE
interfaces/EClassInterface.cpp
interfaces/EntityInterface.cpp
interfaces/FileSystemInterface.cpp
interfaces/FxManagerInterface.cpp
interfaces/GameInterface.cpp
interfaces/GridInterface.cpp
interfaces/LayerInterface.cpp
Expand Down
2 changes: 2 additions & 0 deletions plugins/script/ScriptingSystem.cpp
Expand Up @@ -35,6 +35,7 @@
#include "interfaces/CameraInterface.h"
#include "interfaces/LayerInterface.h"
#include "interfaces/DeclarationManagerInterface.h"
#include "interfaces/FxManagerInterface.h"

#include "PythonModule.h"

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

GlobalCommandSystem().addCommand(
"RunScript",
Expand Down
1 change: 1 addition & 0 deletions plugins/script/interfaces/DeclarationManagerInterface.cpp
Expand Up @@ -72,6 +72,7 @@ void DeclarationManagerInterface::registerInterface(py::module& scope, py::dict&
.value("ModelDef", decl::Type::ModelDef)
.value("Particle", decl::Type::Particle)
.value("Skin", decl::Type::Skin)
.value("Fx", decl::Type::Fx)
.export_values();

py::class_<decl::DeclarationBlockSyntax>(scope, "DeclarationBlockSyntax")
Expand Down
27 changes: 27 additions & 0 deletions plugins/script/interfaces/FxManagerInterface.cpp
@@ -0,0 +1,27 @@
#include "FxManagerInterface.h"

namespace script
{

ScriptFxDeclaration FxManagerInterface::findFx(const std::string& name)
{
return ScriptFxDeclaration(GlobalFxManager().findFx(name));
}

void FxManagerInterface::registerInterface(py::module& scope, py::dict& globals)
{
// Add the EntityNode interface
py::class_<ScriptFxDeclaration, ScriptDeclaration> fxDeclaration(scope, "Fx");
fxDeclaration.def(py::init<const fx::IFxDeclaration::Ptr&>());

// Add the FxManager module declaration to the given python namespace
py::class_<FxManagerInterface> fxManager(scope, "FxManager");

// Add both overloads to createEntity
fxManager.def("findFx", &FxManagerInterface::findFx);

// Now point the Python variable "GlobalFxManager" to this instance
globals["GlobalFxManager"] = this;
}

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

#include "ifx.h"
#include "DeclarationManagerInterface.h"

namespace script
{

class ScriptFxDeclaration :
public ScriptDeclaration
{
private:
fx::IFxDeclaration::Ptr _fx;

public:
ScriptFxDeclaration(const fx::IFxDeclaration::Ptr& fx) :
ScriptDeclaration(fx),
_fx(fx)
{}
};

/**
* Exposes the GlobalFxManager interface to scripts
*/
class FxManagerInterface :
public IScriptInterface
{
public:
// Mapped methods
ScriptFxDeclaration findFx(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 @@ -218,6 +218,7 @@
<ItemGroup>
<ClInclude Include="..\..\plugins\script\interfaces\CameraInterface.h" />
<ClInclude Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.h" />
<ClInclude Include="..\..\plugins\script\interfaces\FxManagerInterface.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 @@ -250,6 +251,7 @@
<ItemGroup>
<ClCompile Include="..\..\plugins\script\interfaces\CameraInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.cpp" />
<ClCompile Include="..\..\plugins\script\interfaces\FxManagerInterface.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 @@ -100,6 +100,9 @@
<ClInclude Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.h">
<Filter>src\interfaces</Filter>
</ClInclude>
<ClInclude Include="..\..\plugins\script\interfaces\FxManagerInterface.h">
<Filter>src\interfaces</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\plugins\script\SceneNodeBuffer.cpp">
Expand Down Expand Up @@ -189,5 +192,8 @@
<ClCompile Include="..\..\plugins\script\interfaces\DeclarationManagerInterface.cpp">
<Filter>src\interfaces</Filter>
</ClCompile>
<ClCompile Include="..\..\plugins\script\interfaces\FxManagerInterface.cpp">
<Filter>src\interfaces</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit de2ae8a

Please sign in to comment.