Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BlueprintValidator.h
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - Blueprint Validator
3 *
4 * Validates blueprint integrity and enforces catalog consistency
5 * Provides error reporting for invalid node types and parameters
6 * Also handles JSON schema validation and normalization
7 */
8
9#pragma once
10
11#include <string>
12#include <vector>
13#include "NodeGraphManager.h"
14#include "../../Source/third_party/imgui/imgui.h"
15#include "../../Source/third_party/nlohmann/json.hpp"
16
17namespace Olympe
18{
19 // Validation error severity levels
20 enum class ErrorSeverity
21 {
22 Info, // Informational message
23 Warning, // Non-critical issue
24 Error, // Critical issue that should be fixed
25 Critical // Blocking issue that prevents execution
26 };
27
28 // Validation error structure
30 {
31 int nodeId = -1; // Node ID with the error (-1 for graph-level errors)
32 std::string nodeName; // Node name for display
33 std::string message; // Error message
35 std::string category; // Error category (e.g., "Type", "Parameter", "Link")
36
37 ValidationError() = default;
38 ValidationError(int nId, const std::string& nName, const std::string& msg,
39 ErrorSeverity sev = ErrorSeverity::Error, const std::string& cat = "")
41 };
42
43 /**
44 * BlueprintValidator - Validates node graphs against catalogs
45 * Ensures type safety and parameter consistency
46 * Also provides JSON schema validation and normalization
47 */
49 {
50 public:
53
54 // Node graph validation (existing)
55 std::vector<ValidationError> ValidateGraph(const NodeGraph* graph);
56 std::vector<ValidationError> ValidateNode(const NodeGraph* graph, int nodeId);
57 bool IsGraphValid(const NodeGraph* graph);
58 int GetErrorCount(const std::vector<ValidationError>& errors, ErrorSeverity severity) const;
59
60 // JSON schema validation and normalization (new)
61 // Detect blueprint type from JSON structure using heuristics
62 std::string DetectType(const nlohmann::json& blueprint);
63
64 // Normalize JSON to ensure required fields exist
65 // Returns true if changes were made
67
68 // Validate JSON against per-type required fields
69 // Returns true if valid, fills errors string if not
70 bool ValidateJSON(const nlohmann::json& blueprint, std::string& errors);
71
72 // Severity to string conversion
73 static const char* SeverityToString(ErrorSeverity severity);
74 static ImVec4 SeverityToColor(ErrorSeverity severity);
75
76 private:
77 // Validation helpers (existing)
78 void ValidateNodeType(const NodeGraph* graph, const GraphNode* node,
79 std::vector<ValidationError>& errors);
81 std::vector<ValidationError>& errors);
82 void ValidateNodeLinks(const NodeGraph* graph, const GraphNode* node,
83 std::vector<ValidationError>& errors);
84
85 // JSON validation helpers (new)
86 bool ValidateBehaviorTree(const nlohmann::json& blueprint, std::string& errors);
87 bool ValidateHFSM(const nlohmann::json& blueprint, std::string& errors);
88 bool ValidateEntityPrefab(const nlohmann::json& blueprint, std::string& errors);
89 bool ValidateUIBlueprint(const nlohmann::json& blueprint, std::string& errors);
90 bool ValidateLevel(const nlohmann::json& blueprint, std::string& errors);
91 };
92}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
BlueprintValidator - Validates node graphs against catalogs Ensures type safety and parameter consist...
int GetErrorCount(const std::vector< ValidationError > &errors, ErrorSeverity severity) const
static ImVec4 SeverityToColor(ErrorSeverity severity)
std::vector< ValidationError > ValidateNode(const NodeGraph *graph, int nodeId)
bool ValidateUIBlueprint(const nlohmann::json &blueprint, std::string &errors)
std::string DetectType(const nlohmann::json &blueprint)
bool Normalize(nlohmann::json &blueprint)
void ValidateNodeType(const NodeGraph *graph, const GraphNode *node, std::vector< ValidationError > &errors)
bool ValidateHFSM(const nlohmann::json &blueprint, std::string &errors)
bool ValidateEntityPrefab(const nlohmann::json &blueprint, std::string &errors)
bool IsGraphValid(const NodeGraph *graph)
void ValidateNodeLinks(const NodeGraph *graph, const GraphNode *node, std::vector< ValidationError > &errors)
bool ValidateJSON(const nlohmann::json &blueprint, std::string &errors)
void ValidateNodeParameters(const NodeGraph *graph, const GraphNode *node, std::vector< ValidationError > &errors)
bool ValidateLevel(const nlohmann::json &blueprint, std::string &errors)
static const char * SeverityToString(ErrorSeverity severity)
bool ValidateBehaviorTree(const nlohmann::json &blueprint, std::string &errors)
std::vector< ValidationError > ValidateGraph(const NodeGraph *graph)
nlohmann::json json
ValidationError(int nId, const std::string &nName, const std::string &msg, ErrorSeverity sev=ErrorSeverity::Error, const std::string &cat="")