Ember
Loading...
Searching...
No Matches
BehaviorTreeProject.h
Go to the documentation of this file.
1#pragma once
2
3#include "Types/Types.h"
4#include <map>
5#include <memory>
6#include <nlohmann/json.hpp>
7#include <set>
8#include <vector>
9
10namespace EmberCore {
11
25
31 bool exists = false;
32 bool is_valid_xml = false;
33 bool has_behavior_trees = false;
34 int tree_count = 0;
35 std::vector<String> tree_ids;
36 std::vector<String> subtree_refs;
37 std::vector<String> errors;
38 std::vector<String> warnings;
39
40 // Blackboard tracking
41 bool has_blackboards = false;
43 std::vector<String> blackboard_ids;
44 std::vector<String> blackboard_includes;
45
46 bool IsValid() const { return exists && is_valid_xml && (has_behavior_trees || has_blackboards) && errors.empty(); }
47};
48
53 bool is_valid = false;
54 std::vector<ResourceValidationStatus> resource_statuses;
55 std::map<String, TreeImplementationStatus> tree_statuses;
56 std::vector<String> errors;
57 std::vector<String> warnings;
58 std::vector<String> unimplemented_trees;
59 std::vector<String> circular_references;
60
61 // Blackboard validation
62 std::vector<String> unresolved_blackboard_includes;
63 std::vector<String> duplicate_blackboard_ids;
64
65 int GetValidFileCount() const;
66 int GetTotalTreeCount() const;
67 int GetImplementedTreeCount() const;
68 String GenerateReport() const;
69};
70
79 public:
81 explicit BehaviorTreeProject(const String &name, const String &description = "");
83
84 // Project metadata
85 String GetName() const { return name_; }
86 void SetName(const String &name);
87
89 void SetDescription(const String &description);
90
91 String GetVersion() const { return version_; }
92 void SetVersion(const String &version) { version_ = version; }
93
94 int64_t GetCreatedTimestamp() const { return created_timestamp_; }
95 int64_t GetModifiedTimestamp() const { return modified_timestamp_; }
97
98 // Parser profile association
100 void SetParserProfileName(const String &profile_name);
101
102 // Resource management
103 bool AddResource(const String &filepath);
104 bool RemoveResource(const String &filepath);
105 bool HasResource(const String &filepath) const;
106 void ClearResources();
107 const std::vector<String> &GetResources() const { return resources_; }
108 size_t GetResourceCount() const { return resources_.size(); }
109
110 // Project file path (where the .btproj file is saved)
112 void SetProjectFilePath(const String &filepath) { project_filepath_ = filepath; }
113
114 // Get the base directory for resolving relative resource paths
115 String GetBaseDirectory() const;
116
117 // Resolve a resource path (relative to project file or absolute)
118 String ResolveResourcePath(const String &resource_path) const;
119
120 // Convert an absolute path to relative (for storage)
121 String MakeRelativePath(const String &absolute_path) const;
122
123 // Validation
126 bool IsValid() const;
127
128 // Tree implementation tracking (populated after parsing)
129 void SetTreeImplementationStatus(const std::map<String, TreeImplementationStatus> &statuses);
130 const std::map<String, TreeImplementationStatus> &GetTreeImplementationStatuses() const { return tree_statuses_; }
131 std::vector<String> GetUnimplementedReferences() const;
132 std::vector<String> GetImplementedTrees() const;
133 bool IsTreeImplemented(const String &tree_id) const;
134
135 // JSON serialization/deserialization
136 nlohmann::json ToJson() const;
137 void FromJson(const nlohmann::json &json);
138
139 // File I/O
140 bool SaveToFile(const String &filepath);
141 bool LoadFromFile(const String &filepath);
142
143 // Cloning
144 std::shared_ptr<BehaviorTreeProject> Clone(const String &new_name = "") const;
145
146 // Factory methods
147 static std::shared_ptr<BehaviorTreeProject> CreateEmpty(const String &name);
148
149 private:
150 // Helper to get current timestamp
151 static int64_t GetCurrentTimestamp();
152
153 // Validate a single resource file
155
156 private:
162
165
166 std::vector<String> resources_;
167
168 // Tree implementation tracking (populated after full parsing)
169 std::map<String, TreeImplementationStatus> tree_statuses_;
170};
171
172} // namespace EmberCore
String MakeRelativePath(const String &absolute_path) const
String project_filepath_
Path to the project file itself.
std::shared_ptr< BehaviorTreeProject > Clone(const String &new_name="") const
const std::map< String, TreeImplementationStatus > & GetTreeImplementationStatuses() const
void SetVersion(const String &version)
std::map< String, TreeImplementationStatus > tree_statuses_
bool AddResource(const String &filepath)
bool LoadFromFile(const String &filepath)
ProjectValidationReport ValidateWithParser(class LibXMLBehaviorTreeParser *parser) const
std::vector< String > GetImplementedTrees() const
ResourceValidationStatus ValidateSingleResource(const String &filepath) const
void SetParserProfileName(const String &profile_name)
void SetTreeImplementationStatus(const std::map< String, TreeImplementationStatus > &statuses)
std::vector< String > GetUnimplementedReferences() const
bool SaveToFile(const String &filepath)
void FromJson(const nlohmann::json &json)
static std::shared_ptr< BehaviorTreeProject > CreateEmpty(const String &name)
bool HasResource(const String &filepath) const
const std::vector< String > & GetResources() const
String parser_profile_name_
Name of the parser profile to use.
bool RemoveResource(const String &filepath)
void SetProjectFilePath(const String &filepath)
ProjectValidationReport ValidateResources() const
bool IsTreeImplemented(const String &tree_id) const
std::vector< String > resources_
List of XML file paths (relative to project file)
String ResolveResourcePath(const String &resource_path) const
void SetDescription(const String &description)
Thread-safe XML parser using libxml2 for behavior tree files.
Main types header for EmberCore.
std::string String
Framework-agnostic string type.
Definition String.h:14
Complete validation report for a project.
std::vector< String > unresolved_blackboard_includes
Blackboard includes not found in project.
std::vector< String > warnings
Project-level warnings.
std::vector< ResourceValidationStatus > resource_statuses
Status for each resource.
std::vector< String > unimplemented_trees
Trees referenced but not implemented.
std::vector< String > errors
Project-level errors.
std::vector< String > duplicate_blackboard_ids
Duplicate blackboard IDs across files.
bool is_valid
Overall validation status.
std::vector< String > circular_references
Circular reference chains detected.
std::map< String, TreeImplementationStatus > tree_statuses
Status for each tree.
Resource validation status for a single file.
int blackboard_count
Number of blackboards found in the file.
std::vector< String > blackboard_ids
IDs of blackboards found in the file.
std::vector< String > errors
Validation errors for this file.
std::vector< String > tree_ids
IDs of trees found in the file.
std::vector< String > blackboard_includes
IDs referenced via includes="..." attribute.
int tree_count
Number of trees found in the file.
bool has_behavior_trees
File contains BehaviorTree elements.
std::vector< String > subtree_refs
IDs of SubTrees referenced in this file.
std::vector< String > warnings
Validation warnings for this file.
bool has_blackboards
File contains Blackboard elements.
String defined_in_file
Which file defines this tree (empty if not defined)
bool has_root_node
Whether tree has a root node.
bool is_implemented
Has actual implementation (not just empty/placeholder)
std::vector< String > referenced_in_files
Which files reference this tree via SubTree.