Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
EntityBlueprint.h
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - Entity Blueprint
3 *
4 * Defines the JSON structure and C++ representation for entity blueprints.
5 * An entity blueprint contains component data that can be serialized to/from JSON.
6 */
7
8#pragma once
9#include <string>
10#include <vector>
11#include "../../Source/third_party/nlohmann/json.hpp"
12
13namespace Olympe {
14namespace Blueprint {
15
16// Forward declarations
17using json = nlohmann::json;
18
19// Component data holder - stores arbitrary component properties as JSON
21{
22 std::string type; // Component type name (e.g., "Position", "BoundingBox", "VisualSprite")
23 json properties; // Component properties as JSON object
24
25 ComponentData() = default;
26 ComponentData(const std::string& t) : type(t) {}
27 ComponentData(const std::string& t, const json& props) : type(t), properties(props) {}
28};
29
30// Entity Blueprint - complete definition of an entity in JSON format
32{
33 std::string name; // Entity name/identifier
34 std::string description; // Optional description
35 std::vector<ComponentData> components; // List of components with their properties
36
37 EntityBlueprint() = default;
38 EntityBlueprint(const std::string& n) : name(n) {}
39
40 // Add a component with its properties
41 void AddComponent(const std::string& type, const json& properties);
42
43 // Get component data by type (returns nullptr if not found)
44 ComponentData* GetComponent(const std::string& type);
45 const ComponentData* GetComponent(const std::string& type) const;
46
47 // Check if entity has a specific component
48 bool HasComponent(const std::string& type) const;
49
50 // Remove a component by type
51 bool RemoveComponent(const std::string& type);
52
53 // Serialization
54 json ToJson() const;
55 static EntityBlueprint FromJson(const json& j);
56
57 // File I/O
58 bool SaveToFile(const std::string& filepath) const;
59 static EntityBlueprint LoadFromFile(const std::string& filepath);
60};
61
62// Helper functions for creating common component data
63
64// Position component (x, y)
66
67// BoundingBox component (x, y, width, height)
68ComponentData CreateBoundingBoxComponent(float x, float y, float width, float height);
69
70// VisualSprite component (sprite path, source rect)
72 const std::string& spritePath,
73 float srcX, float srcY, float srcWidth, float srcHeight,
74 float hotSpotX = 0.0f, float hotSpotY = 0.0f
75);
76
77// Movement component (direction, velocity)
78ComponentData CreateMovementComponent(float dirX, float dirY, float velX, float velY);
79
80// PhysicsBody component (mass, speed)
81ComponentData CreatePhysicsBodyComponent(float mass, float speed);
82
83// Health component (current, max)
85
86// AIBehavior component (behavior type)
87ComponentData CreateAIBehaviorComponent(const std::string& behaviorType);
88
89} // namespace Blueprint
90} // namespace Olympe
nlohmann::json json
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
ComponentData CreateVisualSpriteComponent(const std::string &spritePath, float srcX, float srcY, float srcWidth, float srcHeight, float hotSpotX, float hotSpotY)
ComponentData CreateBoundingBoxComponent(float x, float y, float width, float height)
ComponentData CreateMovementComponent(float dirX, float dirY, float velX, float velY)
ComponentData CreateAIBehaviorComponent(const std::string &behaviorType)
nlohmann::json json
ComponentData CreatePositionComponent(float x, float y)
ComponentData CreatePhysicsBodyComponent(float mass, float speed)
ComponentData CreateHealthComponent(int current, int max)
< Provides AssetID and INVALID_ASSET_ID
@ Blueprint
.ats files (SubGraph/VisualScript)
nlohmann::json json
ComponentData(const std::string &t)
ComponentData(const std::string &t, const json &props)
void AddComponent(const std::string &type, const json &properties)
static EntityBlueprint LoadFromFile(const std::string &filepath)
std::vector< ComponentData > components
EntityBlueprint(const std::string &n)
bool SaveToFile(const std::string &filepath) const
static EntityBlueprint FromJson(const json &j)
bool RemoveComponent(const std::string &type)
ComponentData * GetComponent(const std::string &type)
bool HasComponent(const std::string &type) const