mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
Make abstract color property accept less than 4 color values and make others zero
This commit is contained in:
parent
4b7a78100d
commit
6f15fe6010
@ -2,6 +2,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
@ -11,24 +12,33 @@ GenericColorPropertySequence::GenericColorPropertySequence(std::string keywordNa
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(MenuExpressionMatchers().Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN),
|
||||
create.Numeric().Capture(CAPTURE_R),
|
||||
create.Numeric().Capture(CAPTURE_G),
|
||||
create.Numeric().Capture(CAPTURE_B),
|
||||
create.Numeric().Capture(CAPTURE_A)
|
||||
create.NumericExpression().Tag(TAG_COLOR), // r
|
||||
create.Optional(create.NumericExpression().Tag(TAG_COLOR)), // g
|
||||
create.Optional(create.NumericExpression().Tag(TAG_COLOR)), // b
|
||||
create.Optional(create.NumericExpression().Tag(TAG_COLOR)) // a
|
||||
});
|
||||
}
|
||||
|
||||
double GenericColorPropertySequence::ReadColorValue(SequenceResult<SimpleParserValue>& result)
|
||||
{
|
||||
if (result.PeekAndRemoveIfTag(TAG_COLOR) == TAG_COLOR)
|
||||
return MenuMatcherFactory::TokenNumericExpressionValue(result);
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void GenericColorPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
CommonColor color{};
|
||||
color.r = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_R));
|
||||
color.g = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_G));
|
||||
color.b = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_B));
|
||||
color.a = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_A));
|
||||
color.r = ReadColorValue(result);
|
||||
color.g = ReadColorValue(result);
|
||||
color.b = ReadColorValue(result);
|
||||
color.a = ReadColorValue(result);
|
||||
|
||||
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), color);
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ namespace menu
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_FIRST_TOKEN = 1;
|
||||
static constexpr auto CAPTURE_R = 2;
|
||||
static constexpr auto CAPTURE_G = 3;
|
||||
static constexpr auto CAPTURE_B = 4;
|
||||
static constexpr auto CAPTURE_A = 5;
|
||||
|
||||
static constexpr auto TAG_COLOR = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
static double ReadColorValue(SequenceResult<SimpleParserValue>& result);
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user