Skip to content

Commit

Permalink
#6092: First parsing algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 4, 2022
1 parent 2c5b31d commit 4b5a2ac
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
6 changes: 6 additions & 0 deletions radiantcore/fx/FxAction.cpp
Expand Up @@ -18,4 +18,10 @@ bool FxAction::getIgnoreMaster()
return _ignoreMaster;
}

void FxAction::parseFromTokens(parser::DefTokeniser& tokeniser)
{

}


}
4 changes: 4 additions & 0 deletions radiantcore/fx/FxAction.h
Expand Up @@ -19,6 +19,10 @@ class FxAction :

float getDelay() override;
bool getIgnoreMaster() override;

// Parses the action from the given tokens.
// The opening brace { will already have been been consumed by the calling code
void parseFromTokens(parser::DefTokeniser& tokeniser);
};

}
22 changes: 21 additions & 1 deletion radiantcore/fx/FxDeclaration.cpp
@@ -1,5 +1,8 @@
#include "FxDeclaration.h"

#include "string/case_conv.h"
#include "FxAction.h"

namespace fx
{

Expand Down Expand Up @@ -33,7 +36,24 @@ void FxDeclaration::onBeginParsing()

void FxDeclaration::parseFromTokens(parser::DefTokeniser& tokeniser)
{

while (tokeniser.hasMoreTokens())
{
auto token = tokeniser.nextToken();
string::to_lower(token);

if (token == "bindto")
{
_bindTo = tokeniser.nextToken();
}
else if (token == "{")
{
// An opening brace indicates an action, proceed
auto action = std::make_shared<FxAction>();
action->parseFromTokens(tokeniser);

_actions.emplace_back(std::move(action));
}
}
}

}
18 changes: 18 additions & 0 deletions test/Fx.cpp
Expand Up @@ -35,4 +35,22 @@ TEST_F(FxTest, GetAction)
EXPECT_THROW(getFxByName("fx/tdm_flame")->getAction(10), std::out_of_range);
}

TEST_F(FxTest, ParseBindTo)
{
EXPECT_EQ(getFxByName("fx/tdm_flame")->getBindTo(), "Head");
}

TEST_F(FxTest, ParseActionDelay)
{
EXPECT_EQ(getFxByName("fx/sparks")->getAction(0)->getDelay(), 0);
EXPECT_EQ(getFxByName("fx/sparks")->getAction(1)->getDelay(), 2);
EXPECT_EQ(getFxByName("fx/sparks")->getAction(2)->getDelay(), 1.5);
}

TEST_F(FxTest, ParseActionIgnoreMaster)
{
EXPECT_EQ(getFxByName("fx/sparks")->getAction(0)->getIgnoreMaster(), false);
EXPECT_EQ(getFxByName("fx/parserTest1")->getAction(0)->getIgnoreMaster(), true);
}

}
16 changes: 14 additions & 2 deletions test/resources/tdm/fx/parsertest.fx
Expand Up @@ -23,15 +23,27 @@ fx fx/sparks
}

{
delay 0
delay 2
sound "security_camera_spark"
duration 2.5

}
{
delay 0
delay 1.5
duration 2.5
restart 0
model "sparks.prt"
}
}

fx fx/parserTest1
{
{
delay 0
ignoreMaster
duration 0.5
restart 0
light "lights/sparks_sound", 0.7, 0.7, 0.7, 64
offset 0, 0, 0
}
}

0 comments on commit 4b5a2ac

Please sign in to comment.