mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +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 <utility>
|
||||||
|
|
||||||
|
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
|
||||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
@ -11,24 +12,33 @@ GenericColorPropertySequence::GenericColorPropertySequence(std::string keywordNa
|
|||||||
{
|
{
|
||||||
const MenuMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
|
AddLabeledMatchers(MenuExpressionMatchers().Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN),
|
create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN),
|
||||||
create.Numeric().Capture(CAPTURE_R),
|
create.NumericExpression().Tag(TAG_COLOR), // r
|
||||||
create.Numeric().Capture(CAPTURE_G),
|
create.Optional(create.NumericExpression().Tag(TAG_COLOR)), // g
|
||||||
create.Numeric().Capture(CAPTURE_B),
|
create.Optional(create.NumericExpression().Tag(TAG_COLOR)), // b
|
||||||
create.Numeric().Capture(CAPTURE_A)
|
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
|
void GenericColorPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||||
{
|
{
|
||||||
if (m_set_callback)
|
if (m_set_callback)
|
||||||
{
|
{
|
||||||
CommonColor color{};
|
CommonColor color{};
|
||||||
color.r = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_R));
|
color.r = ReadColorValue(result);
|
||||||
color.g = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_G));
|
color.g = ReadColorValue(result);
|
||||||
color.b = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_B));
|
color.b = ReadColorValue(result);
|
||||||
color.a = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_A));
|
color.a = ReadColorValue(result);
|
||||||
|
|
||||||
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), color);
|
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), color);
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ namespace menu
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto CAPTURE_FIRST_TOKEN = 1;
|
static constexpr auto CAPTURE_FIRST_TOKEN = 1;
|
||||||
static constexpr auto CAPTURE_R = 2;
|
|
||||||
static constexpr auto CAPTURE_G = 3;
|
static constexpr auto TAG_COLOR = 1;
|
||||||
static constexpr auto CAPTURE_B = 4;
|
|
||||||
static constexpr auto CAPTURE_A = 5;
|
|
||||||
|
|
||||||
const callback_t m_set_callback;
|
const callback_t m_set_callback;
|
||||||
|
|
||||||
|
static double ReadColorValue(SequenceResult<SimpleParserValue>& result);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user