mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Merge pull request #60 from Laupetin/fix/custom-menu-function-case-sensitivity
Fix custom menu function case sensitivity
This commit is contained in:
commit
e8a22f3968
@ -12,6 +12,7 @@
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionConditionalOperator.h"
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@ -204,12 +205,15 @@ namespace IW4
|
||||
const CommonMenuDef* menu,
|
||||
const CommonItemDef* item) const
|
||||
{
|
||||
Statement_s* functionStatement = m_conversion_zone_state->FindFunction(functionCall->m_function_name);
|
||||
std::string lowerCaseFunctionName(functionCall->m_function_name);
|
||||
utils::MakeStringLowerCase(lowerCaseFunctionName);
|
||||
|
||||
Statement_s* functionStatement = m_conversion_zone_state->FindFunction(lowerCaseFunctionName);
|
||||
|
||||
if (functionStatement == nullptr)
|
||||
{
|
||||
// Function was not converted yet: Convert it now
|
||||
const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(functionCall->m_function_name);
|
||||
const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(lowerCaseFunctionName);
|
||||
|
||||
if (foundCommonFunction == m_parsing_zone_state->m_functions_by_name.end())
|
||||
throw MenuConversionException("Failed to find definition for custom function \"" + functionCall->m_function_name + "\"", menu, item);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionConditionalOperator.h"
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@ -204,18 +205,21 @@ namespace IW5
|
||||
const CommonMenuDef* menu,
|
||||
const CommonItemDef* item) const
|
||||
{
|
||||
Statement_s* functionStatement = m_conversion_zone_state->FindFunction(functionCall->m_function_name);
|
||||
std::string lowerCaseFunctionName(functionCall->m_function_name);
|
||||
utils::MakeStringLowerCase(lowerCaseFunctionName);
|
||||
|
||||
Statement_s* functionStatement = m_conversion_zone_state->FindFunction(lowerCaseFunctionName);
|
||||
|
||||
if (functionStatement == nullptr)
|
||||
{
|
||||
// Function was not converted yet: Convert it now
|
||||
const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(functionCall->m_function_name);
|
||||
const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(lowerCaseFunctionName);
|
||||
|
||||
if (foundCommonFunction == m_parsing_zone_state->m_functions_by_name.end())
|
||||
throw MenuConversionException("Failed to find definition for custom function \"" + functionCall->m_function_name + "\"", menu, item);
|
||||
|
||||
functionStatement = ConvertExpression(foundCommonFunction->second->m_value.get(), menu, item);
|
||||
functionStatement = m_conversion_zone_state->AddFunction(foundCommonFunction->second->m_name, functionStatement);
|
||||
functionStatement = m_conversion_zone_state->AddFunction(lowerCaseFunctionName, functionStatement);
|
||||
}
|
||||
|
||||
expressionEntry functionEntry{};
|
||||
|
@ -58,7 +58,11 @@ const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapF
|
||||
if (!iw4FunctionMapInitialized)
|
||||
{
|
||||
for (size_t i = IW4::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW4::g_expFunctionNames)>; i++)
|
||||
iw4FunctionMap.emplace(std::make_pair(IW4::g_expFunctionNames[i], i));
|
||||
{
|
||||
std::string functionName(IW4::g_expFunctionNames[i]);
|
||||
utils::MakeStringLowerCase(functionName);
|
||||
iw4FunctionMap.emplace(std::make_pair(functionName, i));
|
||||
}
|
||||
}
|
||||
|
||||
return iw4FunctionMap;
|
||||
@ -71,7 +75,11 @@ const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapF
|
||||
if (!iw5FunctionMapInitialized)
|
||||
{
|
||||
for (size_t i = IW5::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW5::g_expFunctionNames)>; i++)
|
||||
iw5FunctionMap.emplace(std::make_pair(IW5::g_expFunctionNames[i], i));
|
||||
{
|
||||
std::string functionName(IW5::g_expFunctionNames[i]);
|
||||
utils::MakeStringLowerCase(functionName);
|
||||
iw5FunctionMap.emplace(std::make_pair(std::move(functionName), i));
|
||||
}
|
||||
}
|
||||
|
||||
return iw5FunctionMap;
|
||||
|
@ -1,10 +1,15 @@
|
||||
#include "MenuAssetZoneState.h"
|
||||
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
void MenuAssetZoneState::AddFunction(std::unique_ptr<CommonFunctionDef> function)
|
||||
{
|
||||
m_functions_by_name.emplace(std::make_pair(function->m_name, function.get()));
|
||||
std::string lowerCaseFunctionName(function->m_name);
|
||||
utils::MakeStringLowerCase(lowerCaseFunctionName);
|
||||
|
||||
m_functions_by_name.emplace(std::make_pair(lowerCaseFunctionName, function.get()));
|
||||
m_functions.emplace_back(std::move(function));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "MenuFileParserState.h"
|
||||
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
MenuFileParserState::EventHandlerConditionState::EventHandlerConditionState(CommonEventHandlerCondition* condition)
|
||||
@ -32,7 +34,9 @@ MenuFileParserState::MenuFileParserState(const FeatureLevel featureLevel, const
|
||||
{
|
||||
for (const auto& function : zoneState->m_functions)
|
||||
{
|
||||
m_functions_by_name.emplace(std::make_pair(function->m_name, function.get()));
|
||||
std::string lowerCaseName(function->m_name);
|
||||
utils::MakeStringLowerCase(lowerCaseName);
|
||||
m_functions_by_name.emplace(std::make_pair(lowerCaseName, function.get()));
|
||||
}
|
||||
|
||||
for (const auto& menu : zoneState->m_menus)
|
||||
|
@ -36,7 +36,9 @@ namespace menu
|
||||
std::vector<std::unique_ptr<CommonFunctionDef>> m_functions;
|
||||
std::vector<std::unique_ptr<CommonMenuDef>> m_menus;
|
||||
|
||||
// Function names are case-insensitive, therefore keys are always lowercase
|
||||
std::map<std::string, CommonFunctionDef*> m_functions_by_name;
|
||||
|
||||
std::map<std::string, CommonMenuDef*> m_menus_by_name;
|
||||
|
||||
bool m_in_global_scope;
|
||||
|
@ -34,10 +34,13 @@ namespace menu::function_scope_sequences
|
||||
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
||||
}
|
||||
|
||||
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
|
||||
auto lowerCaseName = state->m_current_function->m_name;
|
||||
utils::MakeStringLowerCase(lowerCaseName);
|
||||
|
||||
const auto existingFunction = state->m_functions_by_name.find(lowerCaseName);
|
||||
if (existingFunction == state->m_functions_by_name.end())
|
||||
{
|
||||
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
|
||||
state->m_functions_by_name.emplace(std::make_pair(lowerCaseName, state->m_current_function));
|
||||
state->m_current_function = nullptr;
|
||||
}
|
||||
else if (!state->m_current_function->m_value->Equals(existingFunction->second->m_value.get()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user