mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Parse Expression Properties for menuDefs
This commit is contained in:
parent
38551f29de
commit
321794a209
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "CommonItemDef.h"
|
#include "CommonItemDef.h"
|
||||||
#include "CommonMenuTypes.h"
|
#include "CommonMenuTypes.h"
|
||||||
|
#include "Expression/ICommonExpression.h"
|
||||||
|
|
||||||
namespace menu
|
namespace menu
|
||||||
{
|
{
|
||||||
@ -30,6 +31,13 @@ namespace menu
|
|||||||
double m_fade_in_amount;
|
double m_fade_in_amount;
|
||||||
double m_blur_radius;
|
double m_blur_radius;
|
||||||
std::string m_allowed_binding;
|
std::string m_allowed_binding;
|
||||||
|
std::unique_ptr<ICommonExpression> m_visible_expression;
|
||||||
|
std::unique_ptr<ICommonExpression> m_rect_x_exp;
|
||||||
|
std::unique_ptr<ICommonExpression> m_rect_y_exp;
|
||||||
|
std::unique_ptr<ICommonExpression> m_rect_w_exp;
|
||||||
|
std::unique_ptr<ICommonExpression> m_rect_h_exp;
|
||||||
|
std::unique_ptr<ICommonExpression> m_open_sound_exp;
|
||||||
|
std::unique_ptr<ICommonExpression> m_close_sound_exp;
|
||||||
|
|
||||||
bool m_full_screen;
|
bool m_full_screen;
|
||||||
bool m_screen_space;
|
bool m_screen_space;
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
#include "GenericExpressionPropertySequence.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||||
|
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||||
|
|
||||||
|
using namespace menu;
|
||||||
|
|
||||||
|
GenericExpressionPropertySequence::GenericExpressionPropertySequence(callback_t setCallback)
|
||||||
|
: m_set_callback(std::move(setCallback))
|
||||||
|
{
|
||||||
|
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeyword(std::string keyword, callback_t setCallback)
|
||||||
|
{
|
||||||
|
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||||
|
|
||||||
|
const MenuMatcherFactory create(result.get());
|
||||||
|
result->AddMatchers({
|
||||||
|
create.KeywordIgnoreCase(std::move(keyword)),
|
||||||
|
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||||
|
create.Optional(create.Char(';'))
|
||||||
|
});
|
||||||
|
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeywords(const std::initializer_list<std::string> keywords, callback_t setCallback)
|
||||||
|
{
|
||||||
|
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||||
|
|
||||||
|
const MenuMatcherFactory create(result.get());
|
||||||
|
std::vector<std::unique_ptr<matcher_t>> keywordMatchers;
|
||||||
|
for (auto keyword : keywords)
|
||||||
|
keywordMatchers.emplace_back(create.KeywordIgnoreCase(std::move(keyword)));
|
||||||
|
|
||||||
|
result->AddMatchers({
|
||||||
|
create.And(std::move(keywordMatchers)),
|
||||||
|
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||||
|
create.Optional(create.Char(';'))
|
||||||
|
});
|
||||||
|
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeywordAndBool(std::string keyword, callback_t setCallback)
|
||||||
|
{
|
||||||
|
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||||
|
|
||||||
|
const MenuMatcherFactory create(result.get());
|
||||||
|
result->AddMatchers({
|
||||||
|
create.KeywordIgnoreCase(std::move(keyword)),
|
||||||
|
create.Or({
|
||||||
|
create.And({
|
||||||
|
create.KeywordIgnoreCase("when"),
|
||||||
|
create.Char('('),
|
||||||
|
create.Label(MenuCommonMatchers::LABEL_EXPRESSION).Capture(CAPTURE_VALUE),
|
||||||
|
create.Char(')')
|
||||||
|
}),
|
||||||
|
create.Label(MenuCommonMatchers::LABEL_EXPRESSION)
|
||||||
|
}),
|
||||||
|
create.Optional(create.Char(';'))
|
||||||
|
});
|
||||||
|
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenericExpressionPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||||
|
{
|
||||||
|
if (m_set_callback)
|
||||||
|
{
|
||||||
|
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||||
|
m_set_callback(state, std::move(expression));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "Parsing/Menu/MenuFileParser.h"
|
||||||
|
#include "Parsing/Menu/Domain/Expression/ICommonExpression.h"
|
||||||
|
|
||||||
|
namespace menu
|
||||||
|
{
|
||||||
|
class GenericExpressionPropertySequence final : public MenuFileParser::sequence_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using callback_t = std::function<void(MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr auto CAPTURE_VALUE = 1;
|
||||||
|
|
||||||
|
const callback_t m_set_callback;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit GenericExpressionPropertySequence(callback_t setCallback);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::unique_ptr<GenericExpressionPropertySequence> WithKeyword(std::string keyword, callback_t setCallback);
|
||||||
|
static std::unique_ptr<GenericExpressionPropertySequence> WithKeywords(std::initializer_list<std::string> keywords, callback_t setCallback);
|
||||||
|
static std::unique_ptr<GenericExpressionPropertySequence> WithKeywordAndBool(std::string keyword, callback_t setCallback);
|
||||||
|
};
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "GenericBoolPropertySequence.h"
|
#include "GenericBoolPropertySequence.h"
|
||||||
#include "GenericColorPropertySequence.h"
|
#include "GenericColorPropertySequence.h"
|
||||||
|
#include "GenericExpressionPropertySequence.h"
|
||||||
#include "GenericFloatingPointPropertySequence.h"
|
#include "GenericFloatingPointPropertySequence.h"
|
||||||
#include "GenericIntPropertySequence.h"
|
#include "GenericIntPropertySequence.h"
|
||||||
#include "GenericKeywordPropertySequence.h"
|
#include "GenericKeywordPropertySequence.h"
|
||||||
@ -64,52 +65,6 @@ namespace menu::menu_properties
|
|||||||
state->m_current_menu->m_rect = rect;
|
state->m_current_menu->m_rect = rect;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SequenceBooleanExpression final : public MenuFileParser::sequence_t
|
|
||||||
{
|
|
||||||
static constexpr auto CAPTURE_EXPRESSION = 1;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit SequenceBooleanExpression(std::string keyword)
|
|
||||||
{
|
|
||||||
const MenuMatcherFactory create(this);
|
|
||||||
|
|
||||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
|
||||||
|
|
||||||
AddMatchers({
|
|
||||||
create.KeywordIgnoreCase(std::move(keyword)),
|
|
||||||
create.Or({
|
|
||||||
create.And({
|
|
||||||
create.KeywordIgnoreCase("when"),
|
|
||||||
create.Char('('),
|
|
||||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION).Capture(CAPTURE_EXPRESSION),
|
|
||||||
create.Char(')')
|
|
||||||
}),
|
|
||||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION)
|
|
||||||
}),
|
|
||||||
create.Char(';')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
|
||||||
{
|
|
||||||
assert(state->m_current_menu);
|
|
||||||
|
|
||||||
const auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
|
||||||
|
|
||||||
std::cout << "Evaluated expression!\n";
|
|
||||||
std::cout << " IsStatic: " << expression->IsStatic() << "\n";
|
|
||||||
|
|
||||||
const auto value = expression->Evaluate();
|
|
||||||
if(value.m_type == CommonExpressionValue::Type::DOUBLE)
|
|
||||||
std::cout << " Value: " << value.m_double_value << "\n";
|
|
||||||
else if(value.m_type == CommonExpressionValue::Type::INT)
|
|
||||||
std::cout << " Value: " << value.m_int_value << "\n";
|
|
||||||
else if (value.m_type == CommonExpressionValue::Type::STRING)
|
|
||||||
std::cout << " Value: \"" << *value.m_string_value << "\"\n";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace menu_properties;
|
using namespace menu_properties;
|
||||||
@ -234,6 +189,24 @@ void MenuPropertySequences::AddSequences(FeatureLevel featureLevel)
|
|||||||
{
|
{
|
||||||
state->m_current_menu->m_text_only_focus = true;
|
state->m_current_menu->m_text_only_focus = true;
|
||||||
}));
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeywordAndBool("visible", [](const MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)
|
||||||
AddSequence(std::make_unique<SequenceBooleanExpression>("visible"));
|
{
|
||||||
|
state->m_current_menu->m_visible_expression = std::move(value);
|
||||||
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeywords({"exp", "rect", "X"}, [](const MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)
|
||||||
|
{
|
||||||
|
state->m_current_menu->m_rect_x_exp = std::move(value);
|
||||||
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeywords({"exp", "rect", "Y"}, [](const MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)
|
||||||
|
{
|
||||||
|
state->m_current_menu->m_rect_y_exp = std::move(value);
|
||||||
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeywords({"exp", "rect", "W"}, [](const MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)
|
||||||
|
{
|
||||||
|
state->m_current_menu->m_rect_w_exp = std::move(value);
|
||||||
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeywords({"exp", "rect", "H"}, [](const MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)
|
||||||
|
{
|
||||||
|
state->m_current_menu->m_rect_h_exp = std::move(value);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user