mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-08-20 22:14:29 +00:00
fix(menu): accept numeric dvarStrList values (#947)
* fix(menu): accept numeric `dvarStrList` values Convert numeric tokens to strings to match the game menu parser behaviour. https://github.com/Laupetin/OpenAssetTools/issues/160 * chore: rename TextOrNumericNoChain to TextNoChainOrNumeric --------- Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
@@ -67,6 +67,22 @@ MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::TextNoChain() const
|
||||
}));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::TextNoChainOrNumeric() const
|
||||
{
|
||||
return Or({
|
||||
TextNoChain(),
|
||||
Numeric().Transform(
|
||||
[](const token_list_t& tokens) -> SimpleParserValue
|
||||
{
|
||||
const auto& token = tokens[0].get();
|
||||
if (token.m_type == SimpleParserValueType::INTEGER)
|
||||
return SimpleParserValue::String(token.GetPos(), new std::string(std::to_string(token.IntegerValue())));
|
||||
|
||||
return SimpleParserValue::String(token.GetPos(), new std::string(std::format("{:g}", token.FloatingPointValue())));
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const
|
||||
{
|
||||
return MatcherFactoryWrapper(Or({
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace menu
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Text() const;
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> TextOrNumeric() const;
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> TextNoChain() const;
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> TextNoChainOrNumeric() const;
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Numeric() const;
|
||||
|
||||
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> TextExpression() const;
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace
|
||||
create.OptionalLoop(create.And({
|
||||
create.TextNoChain().Capture(CAPTURE_STEP_NAME),
|
||||
create.Optional(create.Char(';')),
|
||||
create.TextNoChain().Capture(CAPTURE_STEP_VALUE),
|
||||
create.TextNoChainOrNumeric().Capture(CAPTURE_STEP_VALUE),
|
||||
create.Optional(create.Char(';')),
|
||||
})),
|
||||
create.Char('}'),
|
||||
|
||||
Reference in New Issue
Block a user