6#include "../json_helper.h"
19 if (
comp.type == type)
21 comp.properties = properties;
34 if (
comp.type == type)
44 if (
comp.type == type)
71 j[
"schema_version"] = 1;
72 j[
"type"] =
"EntityBlueprint";
76 j[
"components"] = json::array();
102 if (
compJson.contains(
"properties"))
133 json position = json::object();
136 position[
"z"] = 0.0f;
137 props[
"position"] = position;
144 json boundingBox = json::object();
145 boundingBox[
"x"] = x;
146 boundingBox[
"y"] = y;
147 boundingBox[
"w"] = width;
148 boundingBox[
"h"] = height;
149 props[
"boundingBox"] = boundingBox;
154 const std::string& spritePath,
159 props[
"spritePath"] = spritePath;
161 json srcRect = json::object();
166 props[
"srcRect"] = srcRect;
168 json hotSpot = json::object();
171 props[
"hotSpot"] = hotSpot;
180 json direction = json::object();
181 direction[
"x"] =
dirX;
182 direction[
"y"] =
dirY;
183 props[
"direction"] = direction;
185 json velocity = json::object();
186 velocity[
"x"] =
velX;
187 velocity[
"y"] =
velY;
188 props[
"velocity"] = velocity;
196 props[
"mass"] = mass;
197 props[
"speed"] = speed;
212 props[
"behaviorType"] = behaviorType;
ComponentTypeID GetComponentTypeID_Static()
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
Safely get a string value from JSON.
bool LoadJsonFromFile(const std::string &filepath, json &j)
Load and parse a JSON file.
void ForEachInArray(const json &j, const std::string &key, std::function< void(const json &, size_t)> callback)
Iterate over an array with a callback function.
bool SaveJsonToFile(const std::string &filepath, const json &j, int indent=4)
Save a JSON object to a file with formatting.
bool IsArray(const json &j, const std::string &key)
Check if a key contains an array.
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)
ComponentData CreatePositionComponent(float x, float y)
ComponentData CreatePhysicsBodyComponent(float mass, float speed)
ComponentData CreateHealthComponent(int current, int max)
void AddComponent(const std::string &type, const json &properties)
static EntityBlueprint LoadFromFile(const std::string &filepath)
std::vector< ComponentData > components
EntityBlueprint()=default
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