2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-08 09:47:26 +00:00

Make use of custom functions when converting menus

This commit is contained in:
Jan
2021-12-28 23:52:42 +01:00
parent 338de302d9
commit 7188b0946d
27 changed files with 459 additions and 143 deletions

View File

@@ -0,0 +1,43 @@
#include "CommonExpressionBaseFunctionCall.h"
using namespace menu;
CommonExpressionBaseFunctionCall::CommonExpressionBaseFunctionCall(std::string functionName, size_t functionIndex)
: m_function_name(std::move(functionName)),
m_function_index(functionIndex)
{
}
bool CommonExpressionBaseFunctionCall::Equals(const ISimpleExpression* other) const
{
const auto otherFunctionCall = dynamic_cast<const CommonExpressionBaseFunctionCall*>(other);
if (!otherFunctionCall
|| m_function_name != otherFunctionCall->m_function_name
|| m_function_index != otherFunctionCall->m_function_index
|| m_args.size() != otherFunctionCall->m_args.size())
{
return false;
}
for (auto i = 0u; i < m_args.size(); i++)
{
const auto* arg = m_args[i].get();
const auto* otherArg = otherFunctionCall->m_args[i].get();
if (!arg->Equals(otherArg))
return false;
}
return true;
}
bool CommonExpressionBaseFunctionCall::IsStatic() const
{
return false;
}
SimpleExpressionValue CommonExpressionBaseFunctionCall::Evaluate() const
{
return SimpleExpressionValue(0);
}

View File

@@ -5,13 +5,14 @@
namespace menu
{
class CommonExpressionFunctionCall final : public ISimpleExpression
class CommonExpressionBaseFunctionCall final : public ISimpleExpression
{
public:
std::string m_function_name;
size_t m_function_index;
std::vector<std::unique_ptr<ISimpleExpression>> m_args;
explicit CommonExpressionFunctionCall(std::string functionName);
CommonExpressionBaseFunctionCall(std::string functionName, size_t functionIndex);
_NODISCARD bool Equals(const ISimpleExpression* other) const override;
_NODISCARD bool IsStatic() const override;

View File

@@ -0,0 +1,24 @@
#include "CommonExpressionCustomFunctionCall.h"
using namespace menu;
CommonExpressionCustomFunctionCall::CommonExpressionCustomFunctionCall(std::string functionName)
: m_function_name(std::move(functionName))
{
}
bool CommonExpressionCustomFunctionCall::Equals(const ISimpleExpression* other) const
{
const auto otherFunctionCall = dynamic_cast<const CommonExpressionCustomFunctionCall*>(other);
return otherFunctionCall && m_function_name == otherFunctionCall->m_function_name;
}
bool CommonExpressionCustomFunctionCall::IsStatic() const
{
return false;
}
SimpleExpressionValue CommonExpressionCustomFunctionCall::Evaluate() const
{
return SimpleExpressionValue(0);
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Parsing/Simple/Expression/ISimpleExpression.h"
namespace menu
{
class CommonExpressionCustomFunctionCall final : public ISimpleExpression
{
public:
std::string m_function_name;
explicit CommonExpressionCustomFunctionCall(std::string functionName);
_NODISCARD bool Equals(const ISimpleExpression* other) const override;
_NODISCARD bool IsStatic() const override;
_NODISCARD SimpleExpressionValue Evaluate() const override;
};
}

View File

@@ -1,41 +0,0 @@
#include "CommonExpressionFunctionCall.h"
using namespace menu;
CommonExpressionFunctionCall::CommonExpressionFunctionCall(std::string functionName)
: m_function_name(std::move(functionName))
{
}
bool CommonExpressionFunctionCall::Equals(const ISimpleExpression* other) const
{
const auto otherFunctionCall = dynamic_cast<const CommonExpressionFunctionCall*>(other);
if (!otherFunctionCall
|| m_function_name != otherFunctionCall->m_function_name
|| m_args.size() != otherFunctionCall->m_args.size())
{
return false;
}
for(auto i = 0u; i < m_args.size(); i++)
{
const auto* arg = m_args[i].get();
const auto* otherArg = otherFunctionCall->m_args[i].get();
if (!arg->Equals(otherArg))
return false;
}
return true;
}
bool CommonExpressionFunctionCall::IsStatic() const
{
return false;
}
SimpleExpressionValue CommonExpressionFunctionCall::Evaluate() const
{
return SimpleExpressionValue(0);
}