mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-19 13:00:11 -07:00
Ran Clang Format.
This commit is contained in:
parent
0efa327a82
commit
c76ead04fb
7 changed files with 172 additions and 141 deletions
|
@ -37,7 +37,8 @@ enum class EntranceType {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ENTRANCE(check, condition, ...) \
|
#define ENTRANCE(check, condition, ...) \
|
||||||
Entrance(RandomizerRegion::check, [] { return condition; }, CleanCheckConditionString(#condition), ##__VA_ARGS__)
|
Entrance( \
|
||||||
|
RandomizerRegion::check, [] { return condition; }, CleanCheckConditionString(#condition), ##__VA_ARGS__)
|
||||||
|
|
||||||
class Entrance {
|
class Entrance {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -909,7 +909,7 @@ void RegionTable_Init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // Print all conditions for debugging
|
#if 0 // Print all conditions for debugging
|
||||||
// RANDOTODO: Remove before merging
|
// RANDOTODO: Remove before merging
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ void RegionTable_Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INFO("Parse Failure Conditions:\n{}", ss.str());
|
SPDLOG_INFO("Parse Failure Conditions:\n{}", ss.str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void ReplaceFirstInString(std::string& s, std::string const& toReplace, std::string const& replaceWith) {
|
constexpr void ReplaceFirstInString(std::string& s, std::string const& toReplace, std::string const& replaceWith) {
|
||||||
|
|
|
@ -23,7 +23,8 @@ class Region;
|
||||||
constexpr std::string CleanCheckConditionString(std::string condition);
|
constexpr std::string CleanCheckConditionString(std::string condition);
|
||||||
|
|
||||||
#define EVENT_ACCESS(event, condition) \
|
#define EVENT_ACCESS(event, condition) \
|
||||||
EventAccess(&logic->event, #event, [] { return condition; }, CleanCheckConditionString(#condition))
|
EventAccess( \
|
||||||
|
&logic->event, #event, [] { return condition; }, CleanCheckConditionString(#condition))
|
||||||
|
|
||||||
class EventAccess {
|
class EventAccess {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -15,23 +15,39 @@ std::string LogicExpression::Impl::GetTypeString() const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Value:
|
case Type::Value:
|
||||||
switch (valueType) {
|
switch (valueType) {
|
||||||
case ValueType::Boolean: return "Boolean";
|
case ValueType::Boolean:
|
||||||
case ValueType::Number: return "Number";
|
return "Boolean";
|
||||||
case ValueType::Enum: return "Enum";
|
case ValueType::Number:
|
||||||
case ValueType::Identifier: return "Variable";
|
return "Number";
|
||||||
default: return "Unknown Value";
|
case ValueType::Enum:
|
||||||
|
return "Enum";
|
||||||
|
case ValueType::Identifier:
|
||||||
|
return "Variable";
|
||||||
|
default:
|
||||||
|
return "Unknown Value";
|
||||||
}
|
}
|
||||||
case Type::FunctionCall: return "Function: " + functionName;
|
case Type::FunctionCall:
|
||||||
case Type::Not: return "Not";
|
return "Function: " + functionName;
|
||||||
case Type::And: return "And";
|
case Type::Not:
|
||||||
case Type::Or: return "Or";
|
return "Not";
|
||||||
case Type::Comparison: return "Comparison: " + operation;
|
case Type::And:
|
||||||
case Type::Add: return "Add";
|
return "And";
|
||||||
case Type::Subtract: return "Subtract";
|
case Type::Or:
|
||||||
case Type::Multiply: return "Multiply";
|
return "Or";
|
||||||
case Type::Divide: return "Divide";
|
case Type::Comparison:
|
||||||
case Type::Ternary: return "Ternary";
|
return "Comparison: " + operation;
|
||||||
default: return "Unknown";
|
case Type::Add:
|
||||||
|
return "Add";
|
||||||
|
case Type::Subtract:
|
||||||
|
return "Subtract";
|
||||||
|
case Type::Multiply:
|
||||||
|
return "Multiply";
|
||||||
|
case Type::Divide:
|
||||||
|
return "Divide";
|
||||||
|
case Type::Ternary:
|
||||||
|
return "Ternary";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,15 +271,13 @@ class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseMulDiv() {
|
std::shared_ptr<LogicExpression::Impl> ParseMulDiv() {
|
||||||
return ParseBinaryOp(
|
return ParseBinaryOp(pos, tokens, &Parser::ParsePrimary,
|
||||||
pos, tokens, &Parser::ParsePrimary,
|
{ { "*", LogicExpression::Type::Multiply }, { "/", LogicExpression::Type::Divide } });
|
||||||
{ { "*", LogicExpression::Type::Multiply }, { "/", LogicExpression::Type::Divide } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseAddSub() {
|
std::shared_ptr<LogicExpression::Impl> ParseAddSub() {
|
||||||
return ParseBinaryOp(
|
return ParseBinaryOp(pos, tokens, &Parser::ParseMulDiv,
|
||||||
pos, tokens, &Parser::ParseMulDiv,
|
{ { "+", LogicExpression::Type::Add }, { "-", LogicExpression::Type::Subtract } });
|
||||||
{ { "+", LogicExpression::Type::Add }, { "-", LogicExpression::Type::Subtract } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseComparison() {
|
std::shared_ptr<LogicExpression::Impl> ParseComparison() {
|
||||||
|
@ -277,13 +291,11 @@ class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseAnd() {
|
std::shared_ptr<LogicExpression::Impl> ParseAnd() {
|
||||||
return ParseBinaryOp(pos, tokens, &Parser::ParseComparison,
|
return ParseBinaryOp(pos, tokens, &Parser::ParseComparison, { { "&&", LogicExpression::Type::And } });
|
||||||
{ { "&&", LogicExpression::Type::And } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseOr() {
|
std::shared_ptr<LogicExpression::Impl> ParseOr() {
|
||||||
return ParseBinaryOp(pos, tokens, &Parser::ParseAnd,
|
return ParseBinaryOp(pos, tokens, &Parser::ParseAnd, { { "||", LogicExpression::Type::Or } });
|
||||||
{ { "||", LogicExpression::Type::Or } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LogicExpression::Impl> ParseTernary() {
|
std::shared_ptr<LogicExpression::Impl> ParseTernary() {
|
||||||
|
@ -420,8 +432,11 @@ std::string LogicExpression::Impl::GetExprErrorContext() const {
|
||||||
#define REGISTER_LOGIC_FUNCTION(fn) \
|
#define REGISTER_LOGIC_FUNCTION(fn) \
|
||||||
{ #fn, LogicExpression::Impl::RegisterLogicFunction(#fn, &Rando::Logic::fn) }
|
{ #fn, LogicExpression::Impl::RegisterLogicFunction(#fn, &Rando::Logic::fn) }
|
||||||
|
|
||||||
#define REGISTER_LOGIC_FUNCTION_WITH_DEFAULTS(fn, ...) \
|
#define REGISTER_LOGIC_FUNCTION_WITH_DEFAULTS(fn, ...) \
|
||||||
{ #fn, LogicExpression::Impl::RegisterLogicFunctionWithDefaults(#fn, &Rando::Logic::fn, std::make_tuple(__VA_ARGS__)) }
|
{ \
|
||||||
|
#fn, LogicExpression::Impl::RegisterLogicFunctionWithDefaults(#fn, &Rando::Logic::fn, \
|
||||||
|
std::make_tuple(__VA_ARGS__)) \
|
||||||
|
}
|
||||||
|
|
||||||
#define REGISTER_LOGIC_VARIABLE(var) \
|
#define REGISTER_LOGIC_VARIABLE(var) \
|
||||||
{ #var, LogicExpression::Impl::RegisterLogicVariable(#var, &Rando::Logic::var) }
|
{ #var, LogicExpression::Impl::RegisterLogicVariable(#var, &Rando::Logic::var) }
|
||||||
|
@ -463,7 +478,6 @@ static bool RegionAgeTimeAccess(const RandomizerRegion region, const RegionAgeTi
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
std::unordered_map<std::string, LogicExpression::Impl::FunctionAdapter> LogicExpression::Impl::functionAdapters;
|
std::unordered_map<std::string, LogicExpression::Impl::FunctionAdapter> LogicExpression::Impl::functionAdapters;
|
||||||
void LogicExpression::Impl::PopulateFunctionAdapters() {
|
void LogicExpression::Impl::PopulateFunctionAdapters() {
|
||||||
functionAdapters = {
|
functionAdapters = {
|
||||||
|
@ -792,9 +806,9 @@ LogicExpression::ValueVariant LogicExpression::Impl::EvaluateArithmetic(char op,
|
||||||
auto arith = [&](auto a, auto b) -> ValueVariant {
|
auto arith = [&](auto a, auto b) -> ValueVariant {
|
||||||
// Accept int, uint8_t, but not bool
|
// Accept int, uint8_t, but not bool
|
||||||
if constexpr ((std::is_same_v<std::decay_t<decltype(a)>, int> ||
|
if constexpr ((std::is_same_v<std::decay_t<decltype(a)>, int> ||
|
||||||
std::is_same_v<std::decay_t<decltype(a)>, uint8_t>) &&
|
std::is_same_v<std::decay_t<decltype(a)>,
|
||||||
(std::is_same_v<std::decay_t<decltype(b)>, int> ||
|
uint8_t>)&&(std::is_same_v<std::decay_t<decltype(b)>, int> ||
|
||||||
std::is_same_v<std::decay_t<decltype(b)>, uint8_t>)) {
|
std::is_same_v<std::decay_t<decltype(b)>, uint8_t>)) {
|
||||||
int l = static_cast<int>(a);
|
int l = static_cast<int>(a);
|
||||||
int r = static_cast<int>(b);
|
int r = static_cast<int>(b);
|
||||||
ValueVariant result;
|
ValueVariant result;
|
||||||
|
@ -830,11 +844,20 @@ LogicExpression::ValueVariant LogicExpression::Impl::EvaluateArithmetic(char op,
|
||||||
if (callback) {
|
if (callback) {
|
||||||
std::string opStr;
|
std::string opStr;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case '+': opStr = "Add"; break;
|
case '+':
|
||||||
case '-': opStr = "Subtract"; break;
|
opStr = "Add";
|
||||||
case '*': opStr = "Multiply"; break;
|
break;
|
||||||
case '/': opStr = "Divide"; break;
|
case '-':
|
||||||
default: opStr = "Unknown";
|
opStr = "Subtract";
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
opStr = "Multiply";
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
opStr = "Divide";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
opStr = "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the sub-expression string
|
// Get the sub-expression string
|
||||||
|
@ -1040,13 +1063,14 @@ ExpressionEvaluation EvaluateExpression(std::string condition) {
|
||||||
|
|
||||||
ExpressionEvaluation EvaluateExpression(std::shared_ptr<LogicExpression> expression) {
|
ExpressionEvaluation EvaluateExpression(std::shared_ptr<LogicExpression> expression) {
|
||||||
// Create a vector to store the evaluation sequence
|
// Create a vector to store the evaluation sequence
|
||||||
std::vector<std::tuple<std::shared_ptr<LogicExpression>, std::string, int, std::string, LogicExpression::ValueVariant>>
|
std::vector<
|
||||||
|
std::tuple<std::shared_ptr<LogicExpression>, std::string, int, std::string, LogicExpression::ValueVariant>>
|
||||||
evaluationSequence;
|
evaluationSequence;
|
||||||
|
|
||||||
// Define a callback that records each evaluation step
|
// Define a callback that records each evaluation step
|
||||||
auto recordCallback = [&evaluationSequence](const std::shared_ptr<LogicExpression>& expr,
|
auto recordCallback = [&evaluationSequence](const std::shared_ptr<LogicExpression>& expr, const std::string& path,
|
||||||
const std::string& path, int depth,
|
int depth, const std::string& type,
|
||||||
const std::string& type, const LogicExpression::ValueVariant& result) {
|
const LogicExpression::ValueVariant& result) {
|
||||||
evaluationSequence.emplace_back(expr, path, depth, type, result);
|
evaluationSequence.emplace_back(expr, path, depth, type, result);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,8 @@ class LogicExpression {
|
||||||
std::shared_ptr<LogicExpression> expression;
|
std::shared_ptr<LogicExpression> expression;
|
||||||
|
|
||||||
// Modified to accept path and depth
|
// Modified to accept path and depth
|
||||||
ValueVariant Evaluate(const std::string& path = "0", int depth = 0, const EvaluationCallback& callback = nullptr) const;
|
ValueVariant Evaluate(const std::string& path = "0", int depth = 0,
|
||||||
|
const EvaluationCallback& callback = nullptr) const;
|
||||||
|
|
||||||
// Helper to get a string representation of the type
|
// Helper to get a string representation of the type
|
||||||
std::string GetTypeString() const;
|
std::string GetTypeString() const;
|
||||||
|
@ -84,14 +85,16 @@ class LogicExpression {
|
||||||
private:
|
private:
|
||||||
std::string GetExprErrorContext() const;
|
std::string GetExprErrorContext() const;
|
||||||
// Updated to pass callback to children
|
// Updated to pass callback to children
|
||||||
ValueVariant EvaluateFunction(const std::string& path = "0", int depth = 0, const EvaluationCallback& callback = nullptr) const;
|
ValueVariant EvaluateFunction(const std::string& path = "0", int depth = 0,
|
||||||
|
const EvaluationCallback& callback = nullptr) const;
|
||||||
ValueVariant EvaluateEnum() const;
|
ValueVariant EvaluateEnum() const;
|
||||||
ValueVariant EvaluateVariable() const;
|
ValueVariant EvaluateVariable() const;
|
||||||
// Updated to pass callback to children
|
// Updated to pass callback to children
|
||||||
ValueVariant EvaluateArithmetic(char op, const std::string& path = "0", int depth = 0,
|
ValueVariant EvaluateArithmetic(char op, const std::string& path = "0", int depth = 0,
|
||||||
const EvaluationCallback& callback = nullptr) const;
|
const EvaluationCallback& callback = nullptr) const;
|
||||||
|
|
||||||
using FunctionAdapter = std::function<ValueVariant(const std::vector<std::shared_ptr<Impl>>&, const std::string&, int, const EvaluationCallback&)>;
|
using FunctionAdapter = std::function<ValueVariant(const std::vector<std::shared_ptr<Impl>>&,
|
||||||
|
const std::string&, int, const EvaluationCallback&)>;
|
||||||
|
|
||||||
static std::unordered_map<std::string, FunctionAdapter> functionAdapters;
|
static std::unordered_map<std::string, FunctionAdapter> functionAdapters;
|
||||||
static void PopulateFunctionAdapters();
|
static void PopulateFunctionAdapters();
|
||||||
|
@ -147,8 +150,8 @@ class LogicExpression {
|
||||||
// value. Template parameter T represents the expected type of the argument for the function
|
// value. Template parameter T represents the expected type of the argument for the function
|
||||||
// being registered.
|
// being registered.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T EvaluateArg(const std::shared_ptr<LogicExpression::Impl>& expr, const std::string& path,
|
static T EvaluateArg(const std::shared_ptr<LogicExpression::Impl>& expr, const std::string& path, int depth,
|
||||||
int depth, const EvaluationCallback& callback) {
|
const EvaluationCallback& callback) {
|
||||||
if constexpr (std::is_same_v<T, ConditionFn>) {
|
if constexpr (std::is_same_v<T, ConditionFn>) {
|
||||||
// Wrap the expression in a lambda to delay evaluation until the function is called.
|
// Wrap the expression in a lambda to delay evaluation until the function is called.
|
||||||
return [&expr = *expr, path, depth, callback]() -> bool {
|
return [&expr = *expr, path, depth, callback]() -> bool {
|
||||||
|
@ -171,9 +174,9 @@ class LogicExpression {
|
||||||
// calls 'function'. functionName is used for error reporting.
|
// calls 'function'. functionName is used for error reporting.
|
||||||
template <typename Function, typename... Args, size_t... Is>
|
template <typename Function, typename... Args, size_t... Is>
|
||||||
static ValueVariant CallFunctionImpl(const std::string& functionName, Function function,
|
static ValueVariant CallFunctionImpl(const std::string& functionName, Function function,
|
||||||
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback,
|
const std::string& path, int depth, const EvaluationCallback& callback,
|
||||||
std::index_sequence<Is...>) {
|
std::index_sequence<Is...>) {
|
||||||
// Each args[Is] is converted to its expected type using EvaluateArg<Args> and passed to
|
// Each args[Is] is converted to its expected type using EvaluateArg<Args> and passed to
|
||||||
// 'function'.
|
// 'function'.
|
||||||
return function(EvaluateArg<Args>(args[Is], path + "." + std::to_string(Is), depth, callback)...);
|
return function(EvaluateArg<Args>(args[Is], path + "." + std::to_string(Is), depth, callback)...);
|
||||||
|
@ -186,14 +189,15 @@ class LogicExpression {
|
||||||
template <typename Function, typename... Args>
|
template <typename Function, typename... Args>
|
||||||
static ValueVariant MakeFunctionAdapter(const std::string& functionName, Function function,
|
static ValueVariant MakeFunctionAdapter(const std::string& functionName, Function function,
|
||||||
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback) {
|
const std::string& path, int depth,
|
||||||
|
const EvaluationCallback& callback) {
|
||||||
constexpr size_t expectedArgCount = sizeof...(Args);
|
constexpr size_t expectedArgCount = sizeof...(Args);
|
||||||
if (args.size() != expectedArgCount) {
|
if (args.size() != expectedArgCount) {
|
||||||
throw std::runtime_error("Function " + functionName + " expects " + std::to_string(expectedArgCount) +
|
throw std::runtime_error("Function " + functionName + " expects " + std::to_string(expectedArgCount) +
|
||||||
" arguments, but got " + std::to_string(args.size()));
|
" arguments, but got " + std::to_string(args.size()));
|
||||||
}
|
}
|
||||||
return CallFunctionImpl<Function, Args...>(functionName, function, args, path, depth, callback,
|
return CallFunctionImpl<Function, Args...>(functionName, function, args, path, depth, callback,
|
||||||
std::index_sequence_for<Args...>{});
|
std::index_sequence_for<Args...>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper that deduces parameter types from the function and returns a FunctionAdapter.
|
// Wrapper that deduces parameter types from the function and returns a FunctionAdapter.
|
||||||
|
@ -205,11 +209,12 @@ class LogicExpression {
|
||||||
using traits = function_traits<Function>;
|
using traits = function_traits<Function>;
|
||||||
using ArgsTuple = typename traits::args_tuple;
|
using ArgsTuple = typename traits::args_tuple;
|
||||||
return [functionName, function](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
return [functionName, function](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback) -> ValueVariant {
|
const std::string& path, int depth,
|
||||||
|
const EvaluationCallback& callback) -> ValueVariant {
|
||||||
return std::apply(
|
return std::apply(
|
||||||
[&](auto... dummy) {
|
[&](auto... dummy) {
|
||||||
return MakeFunctionAdapter<Function, decltype(dummy)...>(functionName, function, args,
|
return MakeFunctionAdapter<Function, decltype(dummy)...>(functionName, function, args, path,
|
||||||
path, depth, callback);
|
depth, callback);
|
||||||
},
|
},
|
||||||
ArgsTuple{}); // Unpacks the expected parameter types.
|
ArgsTuple{}); // Unpacks the expected parameter types.
|
||||||
};
|
};
|
||||||
|
@ -218,10 +223,11 @@ class LogicExpression {
|
||||||
// Helper to call pointer-to-member function on "logic" with extracted arguments.
|
// Helper to call pointer-to-member function on "logic" with extracted arguments.
|
||||||
template <typename MemberFunction, typename... Args, size_t... Is>
|
template <typename MemberFunction, typename... Args, size_t... Is>
|
||||||
static ValueVariant CallMemberFunctionImpl(const std::string& functionName, MemberFunction function,
|
static ValueVariant CallMemberFunctionImpl(const std::string& functionName, MemberFunction function,
|
||||||
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback,
|
const std::string& path, int depth,
|
||||||
std::index_sequence<Is...>) {
|
const EvaluationCallback& callback, std::index_sequence<Is...>) {
|
||||||
return ((*logic).*function)(EvaluateArg<Args>(args[Is], path + "." + std::to_string(Is), depth, callback)...);
|
return ((*logic).*
|
||||||
|
function)(EvaluateArg<Args>(args[Is], path + "." + std::to_string(Is), depth, callback)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of RegisterLogicFunction that wraps a pointer-to-member function from Logic.
|
// Implementation of RegisterLogicFunction that wraps a pointer-to-member function from Logic.
|
||||||
|
@ -230,14 +236,15 @@ class LogicExpression {
|
||||||
using traits = function_traits<Function>;
|
using traits = function_traits<Function>;
|
||||||
using ArgsTuple = typename traits::args_tuple;
|
using ArgsTuple = typename traits::args_tuple;
|
||||||
return [functionName, function](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
return [functionName, function](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback) -> ValueVariant {
|
const std::string& path, int depth,
|
||||||
|
const EvaluationCallback& callback) -> ValueVariant {
|
||||||
return std::apply(
|
return std::apply(
|
||||||
[&](auto... dummy) {
|
[&](auto... dummy) {
|
||||||
constexpr size_t expectedArgCount = sizeof...(dummy);
|
constexpr size_t expectedArgCount = sizeof...(dummy);
|
||||||
if (args.size() != expectedArgCount) {
|
if (args.size() != expectedArgCount) {
|
||||||
throw std::runtime_error("Function " + functionName + " expects " +
|
throw std::runtime_error("Function " + functionName + " expects " +
|
||||||
std::to_string(expectedArgCount) + " arguments, but got " +
|
std::to_string(expectedArgCount) + " arguments, but got " +
|
||||||
std::to_string(args.size()));
|
std::to_string(args.size()));
|
||||||
}
|
}
|
||||||
return CallMemberFunctionImpl<Function, decltype(dummy)...>(
|
return CallMemberFunctionImpl<Function, decltype(dummy)...>(
|
||||||
functionName, function, args, path, depth, callback,
|
functionName, function, args, path, depth, callback,
|
||||||
|
@ -252,49 +259,51 @@ class LogicExpression {
|
||||||
template <typename Function, typename Tuple, size_t... Is>
|
template <typename Function, typename Tuple, size_t... Is>
|
||||||
static ValueVariant
|
static ValueVariant
|
||||||
CallMemberFunctionWithDefaultsImpl(const std::string& functionName, Function function,
|
CallMemberFunctionWithDefaultsImpl(const std::string& functionName, Function function,
|
||||||
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback,
|
const std::string& path, int depth, const EvaluationCallback& callback,
|
||||||
Tuple&& defaults, std::index_sequence<Is...>) {
|
Tuple&& defaults, std::index_sequence<Is...>) {
|
||||||
constexpr size_t expectedArgCount = sizeof...(Is);
|
constexpr size_t expectedArgCount = sizeof...(Is);
|
||||||
|
|
||||||
// Ensure the number of provided arguments does not exceed the expected count
|
// Ensure the number of provided arguments does not exceed the expected count
|
||||||
if (args.size() > expectedArgCount) {
|
if (args.size() > expectedArgCount) {
|
||||||
throw std::runtime_error("Function " + functionName + " expects up to " +
|
throw std::runtime_error("Function " + functionName + " expects up to " +
|
||||||
std::to_string(expectedArgCount) + " arguments, but got " +
|
std::to_string(expectedArgCount) + " arguments, but got " +
|
||||||
std::to_string(args.size()));
|
std::to_string(args.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate provided arguments and fill missing ones with defaults
|
// Evaluate provided arguments and fill missing ones with defaults
|
||||||
return ((*logic).*
|
return ((*logic).*function)((Is < args.size()
|
||||||
function)((Is < args.size() ?
|
? EvaluateArg<std::tuple_element_t<Is, std::decay_t<Tuple>>>(
|
||||||
EvaluateArg<std::tuple_element_t<Is, std::decay_t<Tuple>>>(args[Is], path + "." + std::to_string(Is), depth, callback)
|
args[Is], path + "." + std::to_string(Is), depth, callback)
|
||||||
: std::get<Is>(defaults))...);
|
: std::get<Is>(defaults))...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper for member functions with default parameters
|
// Wrapper for member functions with default parameters
|
||||||
template <typename Function, typename... Args>
|
template <typename Function, typename... Args>
|
||||||
static FunctionAdapter RegisterLogicFunctionWithDefaults(const std::string& functionName, Function function,
|
static FunctionAdapter RegisterLogicFunctionWithDefaults(const std::string& functionName, Function function,
|
||||||
std::tuple<Args...> defaults) {
|
std::tuple<Args...> defaults) {
|
||||||
return [functionName, function, defaults](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
return [functionName, function, defaults](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback) -> ValueVariant {
|
const std::string& path, int depth,
|
||||||
|
const EvaluationCallback& callback) -> ValueVariant {
|
||||||
constexpr size_t expectedArgCount = sizeof...(Args);
|
constexpr size_t expectedArgCount = sizeof...(Args);
|
||||||
return CallMemberFunctionWithDefaultsImpl(functionName, function, args, path, depth, callback,
|
return CallMemberFunctionWithDefaultsImpl(functionName, function, args, path, depth, callback, defaults,
|
||||||
defaults,
|
std::make_index_sequence<expectedArgCount>{});
|
||||||
std::make_index_sequence<expectedArgCount>{});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this function in the Template Magic section to implement variable registration.
|
// Add this function in the Template Magic section to implement variable registration.
|
||||||
template <typename T> static FunctionAdapter RegisterLogicVariable(const std::string& varName, T Rando::Logic::*var) {
|
template <typename T>
|
||||||
return [varName, var](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args,
|
static FunctionAdapter RegisterLogicVariable(const std::string& varName, T Rando::Logic::*var) {
|
||||||
const std::string& path, int depth, const EvaluationCallback& callback) -> ValueVariant {
|
return
|
||||||
if (!args.empty()) {
|
[varName, var](const std::vector<std::shared_ptr<LogicExpression::Impl>>& args, const std::string& path,
|
||||||
throw std::runtime_error("Variable " + varName + " expects 0 arguments, but got " +
|
int depth, const EvaluationCallback& callback) -> ValueVariant {
|
||||||
std::to_string(args.size()));
|
if (!args.empty()) {
|
||||||
}
|
throw std::runtime_error("Variable " + varName + " expects 0 arguments, but got " +
|
||||||
auto value = (*logic).*var;
|
std::to_string(args.size()));
|
||||||
return GetValue<T>(value);
|
}
|
||||||
};
|
auto value = (*logic).*var;
|
||||||
|
return GetValue<T>(value);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ typedef enum {
|
||||||
|
|
||||||
#define MAX_TRICK_NAME_SIZE 50
|
#define MAX_TRICK_NAME_SIZE 50
|
||||||
|
|
||||||
#define TWO_ACTOR_PARAMS(a, b) ((((a) & 0xFFFF) << 16) | ((b) & 0xFFFF))
|
#define TWO_ACTOR_PARAMS(a, b) ((((a)&0xFFFF) << 16) | ((b)&0xFFFF))
|
||||||
|
|
||||||
// This should probably go in a less rando-specific location
|
// This should probably go in a less rando-specific location
|
||||||
// but the best location will probably be in the modding engine
|
// but the best location will probably be in the modding engine
|
||||||
|
|
|
@ -68,12 +68,7 @@ static ExpressionTable::ExpressionRow CreateExpressionRows(const std::shared_ptr
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class AgeTime {
|
enum class AgeTime { ChildDay, ChildNight, AdultDay, AdultNight };
|
||||||
ChildDay,
|
|
||||||
ChildNight,
|
|
||||||
AdultDay,
|
|
||||||
AdultNight
|
|
||||||
};
|
|
||||||
|
|
||||||
static void PopulateExpressionValues(ExpressionTable::ExpressionRow& row, const ExpressionEvaluation& eval,
|
static void PopulateExpressionValues(ExpressionTable::ExpressionRow& row, const ExpressionEvaluation& eval,
|
||||||
AgeTime ageTime) {
|
AgeTime ageTime) {
|
||||||
|
@ -107,7 +102,7 @@ static std::tuple<bool, bool, bool> CalculateCombines(const ExpressionTable::Exp
|
||||||
combineChild &= childCombineChild;
|
combineChild &= childCombineChild;
|
||||||
combineAdult &= childCombineAdult;
|
combineAdult &= childCombineAdult;
|
||||||
}
|
}
|
||||||
return {combineAll, combineChild, combineAdult};
|
return { combineAll, combineChild, combineAdult };
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PopulateConnectionExpression(LogicTrackerNode::Connection& connection, std::string expressionStr) {
|
static void PopulateConnectionExpression(LogicTrackerNode::Connection& connection, std::string expressionStr) {
|
||||||
|
@ -196,7 +191,8 @@ void LogicTrackerWindow::ShowRandomizerCheck(RandomizerCheck randomizerCheck) {
|
||||||
expandNodeId = node.NodeId;
|
expandNodeId = node.NodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion toRandomizerRegion, RandomizerRegion fromRandomizerRegion) {
|
void LogicTrackerWindow::ShowRandomizerRegion(RandomizerRegion toRandomizerRegion,
|
||||||
|
RandomizerRegion fromRandomizerRegion) {
|
||||||
const auto& region = RegionTable(toRandomizerRegion);
|
const auto& region = RegionTable(toRandomizerRegion);
|
||||||
|
|
||||||
LogicTrackerNode node;
|
LogicTrackerNode node;
|
||||||
|
@ -294,8 +290,7 @@ static void DrawCondition(const LogicExpression& expression) {
|
||||||
{ defaultColor, " " + expression.GetOperation() + " " },
|
{ defaultColor, " " + expression.GetOperation() + " " },
|
||||||
{ fontColors[1], expression.GetChildren()[1]->ToString() } });
|
{ fontColors[1], expression.GetChildren()[1]->ToString() } });
|
||||||
} else if (type == LogicExpression::Type::Not) {
|
} else if (type == LogicExpression::Type::Not) {
|
||||||
DrawColoredWrappedText({ { defaultColor, "!" },
|
DrawColoredWrappedText({ { defaultColor, "!" }, { fontColors[0], expression.GetChildren()[0]->ToString() } });
|
||||||
{ fontColors[0], expression.GetChildren()[0]->ToString() } });
|
|
||||||
} else if (type == LogicExpression::Type::FunctionCall) {
|
} else if (type == LogicExpression::Type::FunctionCall) {
|
||||||
std::vector<std::pair<ImVec4, std::string>> segments;
|
std::vector<std::pair<ImVec4, std::string>> segments;
|
||||||
segments.emplace_back(fontColors[0], expression.GetFunctionName());
|
segments.emplace_back(fontColors[0], expression.GetFunctionName());
|
||||||
|
@ -482,8 +477,9 @@ static void DrawNode(LogicTrackerNode& node) {
|
||||||
ImGui::SetNextItemOpen(expandNodeId == node.NodeId, ImGuiCond_Always);
|
ImGui::SetNextItemOpen(expandNodeId == node.NodeId, ImGuiCond_Always);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool connectionOpen = ImGui::CollapsingHeader(
|
bool connectionOpen =
|
||||||
("From " + connection.ParentName).c_str(), ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanAvailWidth);
|
ImGui::CollapsingHeader(("From " + connection.ParentName).c_str(),
|
||||||
|
ImGuiTreeNodeFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanAvailWidth);
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("Show Connection Logic");
|
ImGui::SetTooltip("Show Connection Logic");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue