Skip to content

Commit

Permalink
Merge pull request Laupetin#69 from Laupetin/fix/column-expressions
Browse files Browse the repository at this point in the history
Accept expressions as part of the column sequence
  • Loading branch information
Laupetin authored Dec 25, 2023
2 parents f6b5dca + 7fff36d commit 3e18f74
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions src/ObjLoading/Parsing/Menu/Sequence/ItemScopeSequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
#include "Parsing/Menu/MenuFileCommonOperations.h"

#include <cassert>
#include <string>
#include <vector>

Expand Down Expand Up @@ -449,32 +450,30 @@ namespace menu::item_scope_sequences

class SequenceColumns final : public MenuFileParser::sequence_t
{
static constexpr auto TAG_COLUMN = 1;

static constexpr auto CAPTURE_FIRST_TOKEN = 1;
static constexpr auto CAPTURE_COLUMN_COUNT = 2;
static constexpr auto CAPTURE_X_POS = 3;
static constexpr auto CAPTURE_Y_POS = 4;
static constexpr auto CAPTURE_WIDTH = 5;
static constexpr auto CAPTURE_HEIGHT = 6;
static constexpr auto CAPTURE_MAX_CHARS = 7;
static constexpr auto CAPTURE_ALIGNMENT = 8;

public:
explicit SequenceColumns(const FeatureLevel featureLevel)
{
const MenuMatcherFactory create(this);
AddLabeledMatchers(MenuExpressionMatchers().Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);

if (featureLevel == FeatureLevel::IW5)
{
AddMatchers({
create.KeywordIgnoreCase("columns").Capture(CAPTURE_FIRST_TOKEN),
create.Integer().Capture(CAPTURE_COLUMN_COUNT),
create.Loop(create.And({
create.Integer().Capture(CAPTURE_X_POS),
create.Integer().Capture(CAPTURE_Y_POS),
create.Integer().Capture(CAPTURE_WIDTH),
create.Integer().Capture(CAPTURE_HEIGHT),
create.Integer().Capture(CAPTURE_MAX_CHARS),
create.Integer().Capture(CAPTURE_ALIGNMENT),
create.True().Tag(TAG_COLUMN),
create.IntExpression(), // xpos
create.IntExpression(), // ypos
create.IntExpression(), // width
create.IntExpression(), // height
create.IntExpression(), // maxChars
create.IntExpression(), // alignment
})),
});
}
Expand All @@ -484,10 +483,11 @@ namespace menu::item_scope_sequences
create.KeywordIgnoreCase("columns").Capture(CAPTURE_FIRST_TOKEN),
create.Integer().Capture(CAPTURE_COLUMN_COUNT),
create.Loop(create.And({
create.Integer().Capture(CAPTURE_X_POS),
create.Integer().Capture(CAPTURE_WIDTH),
create.Integer().Capture(CAPTURE_MAX_CHARS),
create.Integer().Capture(CAPTURE_ALIGNMENT),
create.True().Tag(TAG_COLUMN),
create.IntExpression(), // xpos
create.IntExpression(), // width
create.IntExpression(), // maxChars
create.IntExpression(), // alignment
})),
});
}
Expand All @@ -500,16 +500,42 @@ namespace menu::item_scope_sequences

ItemScopeOperations::EnsureHasListboxFeatures(*state->m_current_item, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos());

assert(state->m_feature_level == FeatureLevel::IW4 || state->m_feature_level == FeatureLevel::IW5);

const auto& listBoxFeatures = state->m_current_item->m_list_box_features;
while (result.HasNextCapture(CAPTURE_X_POS))
while (result.PeekAndRemoveIfTag(TAG_COLUMN) == TAG_COLUMN)
{
int xPos = 0;
int yPos = 0;
int width = 0;
int height = 0;
int maxChars = 0;
int alignment = 0;

if (state->m_feature_level == FeatureLevel::IW4)
{
xPos = MenuMatcherFactory::TokenIntExpressionValue(state, result);
width = MenuMatcherFactory::TokenIntExpressionValue(state, result);
maxChars = MenuMatcherFactory::TokenIntExpressionValue(state, result);
alignment = MenuMatcherFactory::TokenIntExpressionValue(state, result);
}
else if (state->m_feature_level == FeatureLevel::IW5)
{
xPos = MenuMatcherFactory::TokenIntExpressionValue(state, result);
yPos = MenuMatcherFactory::TokenIntExpressionValue(state, result);
width = MenuMatcherFactory::TokenIntExpressionValue(state, result);
height = MenuMatcherFactory::TokenIntExpressionValue(state, result);
maxChars = MenuMatcherFactory::TokenIntExpressionValue(state, result);
alignment = MenuMatcherFactory::TokenIntExpressionValue(state, result);
}

CommonItemFeaturesListBox::Column column{
result.NextCapture(CAPTURE_X_POS).IntegerValue(),
state->m_feature_level == FeatureLevel::IW5 ? result.NextCapture(CAPTURE_Y_POS).IntegerValue() : 0,
result.NextCapture(CAPTURE_WIDTH).IntegerValue(),
state->m_feature_level == FeatureLevel::IW5 ? result.NextCapture(CAPTURE_HEIGHT).IntegerValue() : 0,
result.NextCapture(CAPTURE_MAX_CHARS).IntegerValue(),
result.NextCapture(CAPTURE_ALIGNMENT).IntegerValue(),
xPos,
yPos,
width,
height,
maxChars,
alignment,
};
listBoxFeatures->m_columns.emplace_back(column);
}
Expand Down

0 comments on commit 3e18f74

Please sign in to comment.