diff --git a/include/ifx.h b/include/ifx.h index 3164f4edd9..f69a858741 100644 --- a/include/ifx.h +++ b/include/ifx.h @@ -5,11 +5,25 @@ namespace fx { +class IFxAction +{ +public: + using Ptr = std::shared_ptr; + + virtual ~IFxAction() {} + + +}; + class IFxDeclaration : public decl::IDeclaration { public: + // Returns the number of actions in this FX declaration + virtual std::size_t getNumActions() = 0; + // Returns the n-th action (based on the given 0-based index) + virtual IFxAction::Ptr getAction(std::size_t index) = 0; }; } diff --git a/radiantcore/fx/FxDeclaration.cpp b/radiantcore/fx/FxDeclaration.cpp index 0871565b54..640e0fd74a 100644 --- a/radiantcore/fx/FxDeclaration.cpp +++ b/radiantcore/fx/FxDeclaration.cpp @@ -7,6 +7,23 @@ FxDeclaration::FxDeclaration(const std::string& name) : DeclarationBase(decl::Type::Fx, name) {} +std::size_t FxDeclaration::getNumActions() +{ + ensureParsed(); + return _actions.size(); +} + +IFxAction::Ptr FxDeclaration::getAction(std::size_t index) +{ + ensureParsed(); + return _actions.at(index); +} + +void FxDeclaration::onBeginParsing() +{ + _actions.clear(); +} + void FxDeclaration::parseFromTokens(parser::DefTokeniser& tokeniser) { diff --git a/radiantcore/fx/FxDeclaration.h b/radiantcore/fx/FxDeclaration.h index 0504950b44..54f3eefa6e 100644 --- a/radiantcore/fx/FxDeclaration.h +++ b/radiantcore/fx/FxDeclaration.h @@ -1,5 +1,6 @@ #pragma once +#include #include "ifx.h" #include "decl/DeclarationBase.h" @@ -9,10 +10,17 @@ namespace fx class FxDeclaration : public decl::DeclarationBase { +private: + std::vector _actions; + public: FxDeclaration(const std::string& name); + std::size_t getNumActions() override; + IFxAction::Ptr getAction(std::size_t index) override; + protected: + void onBeginParsing() override; void parseFromTokens(parser::DefTokeniser& tokeniser) override; }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 980bb21a30..3cf246f118 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(drtest EntityClass.cpp Favourites.cpp FileTypes.cpp + Fx.cpp GeometryStore.cpp Grid.cpp HeadlessOpenGLContext.cpp diff --git a/test/Fx.cpp b/test/Fx.cpp new file mode 100644 index 0000000000..0d3ccc0546 --- /dev/null +++ b/test/Fx.cpp @@ -0,0 +1,16 @@ +#include "ifx.h" + +#include "RadiantTest.h" + +namespace test +{ + +using FxTest = RadiantTest; + +TEST_F(FxTest, GetFxByName) +{ + EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::Fx, "fx/tdm_flame")); + EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::Fx, "fx/sparks")); +} + +} diff --git a/test/resources/tdm/fx/parsertest.fx b/test/resources/tdm/fx/parsertest.fx new file mode 100644 index 0000000000..abfd956acf --- /dev/null +++ b/test/resources/tdm/fx/parsertest.fx @@ -0,0 +1,37 @@ +fx fx/tdm_flame +{ + bindto "Head" + { + delay 0 + duration 10 + restart 0 + light "lights/roundfire", 0.2, 0.6, 0.3, 300 + offset 0, 0, 5 + //fadeIn 2 + fadeOut 3 + } +} + +fx fx/sparks +{ + { + delay 0 + duration 0.5 + restart 0 + light "lights/sparks_sound", 0.7, 0.7, 0.7, 64 + offset 0, 0, 0 + } + + { + delay 0 + sound "security_camera_spark" + duration 2.5 + + } + { + delay 0 + duration 2.5 + restart 0 + model "sparks.prt" + } +} diff --git a/tools/msvc/Tests/Tests.vcxproj b/tools/msvc/Tests/Tests.vcxproj index 595fd5aca8..f5991e7545 100644 --- a/tools/msvc/Tests/Tests.vcxproj +++ b/tools/msvc/Tests/Tests.vcxproj @@ -99,6 +99,7 @@ + diff --git a/tools/msvc/Tests/Tests.vcxproj.filters b/tools/msvc/Tests/Tests.vcxproj.filters index dc401cc741..3b78f57493 100644 --- a/tools/msvc/Tests/Tests.vcxproj.filters +++ b/tools/msvc/Tests/Tests.vcxproj.filters @@ -66,6 +66,7 @@ +