Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
PrefabLoader.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <map>
6#include "./../../third_party/nlohmann/json.hpp"
7
8namespace Olympe
9{
10 using json = nlohmann::json;
11
12 // Forward declarations
13 struct ComponentData;
14 struct ComponentSchema;
15 struct ParameterDefinition;
16 struct EntityPrefab;
17
18 enum class ParameterType
19 {
20 Boolean,
21 Integer,
22 Float,
23 String,
24 Vector2,
25 Vector3,
26 Vector4,
27 Color,
29 };
30
32 {
33 std::string name;
35 std::string defaultValue;
36 std::string description;
38 std::vector<std::string> allowedValues; // For enum-like parameters
39
44
45 explicit ParameterDefinition(const std::string& n)
47 {
48 }
49
50 json ToJson() const;
51 static ParameterDefinition FromJson(const json& data);
52 };
53
55 {
56 std::string componentName;
57 std::string category;
58 std::string description;
59 std::vector<ParameterDefinition> parameters;
61
66
67 explicit ComponentSchema(const std::string& name)
69 {
70 }
71
72 json ToJson() const;
73 static ComponentSchema FromJson(const json& data);
74 };
75
77 {
78 std::string componentType;
79 std::string componentName;
80 std::map<std::string, std::string> properties;
81 bool enabled;
82
84 : enabled(true)
85 {
86 }
87
88 explicit ComponentData(const std::string& type)
89 : componentType(type), enabled(true)
90 {
91 }
92
93 json ToJson() const;
94 static ComponentData FromJson(const json& data);
95 };
96
98 {
99 std::string prefabName;
100 std::string prefabPath;
101 std::vector<ComponentData> components;
102 std::map<std::string, std::string> metadata;
104
106 : schemaVersion(4)
107 {
108 }
109
110 explicit EntityPrefab(const std::string& name)
111 : prefabName(name), schemaVersion(4)
112 {
113 }
114
115 json ToJson() const;
116 static EntityPrefab FromJson(const json& data);
117 };
118
120 {
121 public:
122 static EntityPrefab LoadFromFile(const std::string& filePath);
123 static void SaveToFile(const std::string& filePath, const EntityPrefab& prefab);
124
125 static json LoadJsonFromFile(const std::string& filePath);
126 static void SaveJsonToFile(const std::string& filePath, const json& data);
127
129 static std::vector<ComponentSchema> LoadAllSchemas(const std::string& schemasPath);
130
131 static bool ValidatePrefab(const EntityPrefab& prefab);
133
134 private:
135 PrefabLoader() = default;
136 static std::string GetSchemaVersion(const json& data);
137 static ComponentSchema ParseSchemaV4(const json& data);
139 };
140}
nlohmann::json json
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static void SaveJsonToFile(const std::string &filePath, const json &data)
static EntityPrefab LoadFromFile(const std::string &filePath)
static bool ValidatePrefab(const EntityPrefab &prefab)
static json LoadJsonFromFile(const std::string &filePath)
static std::vector< ComponentSchema > LoadAllSchemas(const std::string &schemasPath)
static ComponentSchema ParseSchemaV4(const json &data)
static void SaveToFile(const std::string &filePath, const EntityPrefab &prefab)
static bool ValidateComponentData(const ComponentData &component, const ComponentSchema &schema)
static std::string GetSchemaVersion(const json &data)
static ComponentSchema ParseComponentSchema(const json &schemaJson)
static json SerializeSchemaV4(const EntityPrefab &prefab)
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
@ EntityPrefab
.pref.json files (Entity Prefab)
nlohmann::json json
static ComponentData FromJson(const json &data)
ComponentData(const std::string &type)
std::string componentType
std::map< std::string, std::string > properties
std::string componentName
ComponentSchema(const std::string &name)
static ComponentSchema FromJson(const json &data)
std::vector< ParameterDefinition > parameters
EntityPrefab(const std::string &name)
std::vector< ComponentData > components
std::string prefabName
std::map< std::string, std::string > metadata
static EntityPrefab FromJson(const json &data)
ParameterDefinition(const std::string &n)
std::vector< std::string > allowedValues
static ParameterDefinition FromJson(const json &data)