Added some error handling.

This commit is contained in:
xxAtrain223 2025-07-15 21:17:38 -05:00
commit c055e8cd92
2 changed files with 60 additions and 35 deletions

View file

@ -560,6 +560,7 @@ void LogicExpression::Impl::PopulateFunctionAdapters() {
REGISTER_LOGIC_FUNCTION(GetGSCount), REGISTER_LOGIC_FUNCTION(GetGSCount),
REGISTER_LOGIC_FUNCTION(HasBossSoul), REGISTER_LOGIC_FUNCTION(HasBossSoul),
REGISTER_LOGIC_FUNCTION(HasProjectile), REGISTER_LOGIC_FUNCTION(HasProjectile),
REGISTER_LOGIC_FUNCTION(CanOpenUnderwaterChest),
}; };
} }

View file

@ -24,6 +24,7 @@ struct ExpressionTable {
std::optional<LogicExpression::ValueVariant> AdultDay; std::optional<LogicExpression::ValueVariant> AdultDay;
std::optional<LogicExpression::ValueVariant> AdultNight; std::optional<LogicExpression::ValueVariant> AdultNight;
bool Expanded = false; bool Expanded = false;
std::string ErrorMessage;
}; };
ExpressionRow Root; ExpressionRow Root;
@ -106,7 +107,20 @@ static std::tuple<bool, bool, bool> CalculateCombines(const ExpressionTable::Exp
} }
static void PopulateConnectionExpression(LogicTrackerNode::Connection& connection, std::string expressionStr) { static void PopulateConnectionExpression(LogicTrackerNode::Connection& connection, std::string expressionStr) {
connection.ExpressionTable.Root = CreateExpressionRows(LogicExpression::Parse(expressionStr)); std::shared_ptr<LogicExpression> expression;
try {
expression = LogicExpression::Parse(expressionStr);
}
catch (const std::exception& e) {
connection.ExpressionTable.Root.ErrorMessage = std::string("Parse Error: ") + e.what();
connection.ExpressionTable.Root.Children.clear();
connection.ExpressionTable.CombineAll = true;
return;
}
try {
connection.ExpressionTable.Root = CreateExpressionRows(expression);
if (connection.ChildDayAccess) { if (connection.ChildDayAccess) {
logic->IsChild = true; logic->IsChild = true;
@ -148,6 +162,12 @@ static void PopulateConnectionExpression(LogicTrackerNode::Connection& connectio
logic->IsAdult = false; logic->IsAdult = false;
logic->AtNight = false; logic->AtNight = false;
} }
} catch (const std::exception& e) {
connection.ExpressionTable.Root.ErrorMessage = std::string("Eval Error: ") + e.what();
connection.ExpressionTable.Root.Children.clear();
connection.ExpressionTable.CombineAll = true;
return;
}
auto [combineAll, combineChild, combineAdult] = CalculateCombines(connection.ExpressionTable.Root); auto [combineAll, combineChild, combineAdult] = CalculateCombines(connection.ExpressionTable.Root);
connection.ExpressionTable.CombineAll = combineAll; connection.ExpressionTable.CombineAll = combineAll;
@ -293,7 +313,7 @@ static void DrawColoredWrappedText(const std::vector<std::pair<ImVec4, std::stri
firstWordInSegment = false; firstWordInSegment = false;
} }
} }
ImGui::SetCursorScreenPos(ImVec2(x, y + fontSize)); ImGui::SetCursorScreenPos(ImVec2(pos.x, y + fontSize));
} }
static void DrawCondition(const LogicExpression& expression) { static void DrawCondition(const LogicExpression& expression) {
@ -362,8 +382,12 @@ static void DrawExpressionRow(const ExpressionTable& table, ExpressionTable::Exp
ImGui::EndDisabled(); ImGui::EndDisabled();
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
DrawCondition(*row.Expression); DrawCondition(*row.Expression);
if (!row.ErrorMessage.empty()) {
ImGui::TextWrapped("%s", row.ErrorMessage.c_str());
}
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted(ToString(row.ChildDay).c_str()); ImGui::TextUnformatted(ToString(row.ChildDay).c_str());