14#include "third_party/nlohmann/json.hpp"
25 SYSTEM_LOG <<
"ParameterSchemaRegistry auto-initialized" << std::endl;
31 SYSTEM_LOG <<
"Initializing built-in parameter schemas..." << std::endl;
35 "position",
"Position_data",
"position",
46 "speed",
"PhysicsBody_data",
"speed",
52 "mass",
"PhysicsBody_data",
"mass",
58 "friction",
"PhysicsBody_data",
"friction",
64 "useGravity",
"PhysicsBody_data",
"useGravity",
71 "alertRadius",
"AIBlackboard_data",
"alertRadius",
77 "health",
"AIBlackboard_data",
"health",
84 "patrolPoints",
"AIBlackboard_data",
"patrolPoints",
90 "initialized",
"AIBlackboard_data",
"initialized",
96 "patrolRoute",
"AIBlackboard_data",
"patrolRoute",
103 "spritePath",
"VisualSprite_data",
"spritePath",
109 "hotSpot",
"VisualSprite_data",
"hotSpot",
115 "color",
"VisualSprite_data",
"color",
122 "width",
"VisualSprite_data",
"width",
128 "height",
"VisualSprite_data",
"height",
134 "layer",
"VisualSprite_data",
"layer",
141 "name",
"Identity_data",
"name",
147 "type",
"Identity_data",
"type",
155 "category",
"Identity_data",
"tag",
162 "tag",
"Identity_data",
"tag",
168 "entityType",
"Identity_data",
"entityType",
175 "width",
"BoundingBox_data",
"width",
181 "height",
"BoundingBox_data",
"height",
187 "offsetX",
"BoundingBox_data",
"offsetX",
193 "offsetY",
"BoundingBox_data",
"offsetY",
200 "speed",
"Movement_data",
"speed",
206 "acceleration",
"Movement_data",
"acceleration",
213 "maxHealth",
"Health_data",
"maxHealth",
219 "currentHealth",
"Health_data",
"currentHealth",
225 "invulnerable",
"Health_data",
"invulnerable",
233 "spritePath",
"VisualEditor_data",
"spritePath",
240 "width",
"VisualEditor_data",
"width",
246 "height",
"VisualEditor_data",
"height",
252 "layer",
"VisualEditor_data",
"layer",
259 "currentState",
"AIState_data",
"currentState",
265 "previousState",
"AIState_data",
"previousState",
272 "visionRange",
"AISenses_data",
"visionRange",
278 "hearingRange",
"AISenses_data",
"hearingRange",
284 "alertLevel",
"AISenses_data",
"alertLevel",
291 "AITreePath",
"BehaviorTreeRuntime_data",
"AITreePath",
297 "active",
"BehaviorTreeRuntime_data",
"active",
304 "targetX",
"MoveIntent_data",
"targetX",
310 "targetY",
"MoveIntent_data",
"targetY",
316 "hasTarget",
"MoveIntent_data",
"hasTarget",
323 "damage",
"AttackIntent_data",
"damage",
329 "attackRange",
"AttackIntent_data",
"attackRange",
335 "cooldown",
"AttackIntent_data",
"cooldown",
342 "playerIndex",
"PlayerBinding_data",
"playerIndex",
348 "controlScheme",
"PlayerBinding_data",
"controlScheme",
355 "enabled",
"Controller_data",
"enabled",
361 "inputEnabled",
"Controller_data",
"inputEnabled",
366 SYSTEM_LOG <<
"Built-in parameter schemas initialized: "
378 std::ifstream
file(filepath);
390 catch (
const std::exception&
e)
392 SYSTEM_LOG <<
" x JSON parse error: " <<
e.what() << std::endl;
396 if (!
root.contains(
"schemas") || !
root[
"schemas"].is_array())
413 std::string componentType =
schemaJson[
"componentType"].get<std::string>();
532 int r = std::stoi(
colorStr.substr(1, 2),
nullptr, 16);
533 int g = std::stoi(
colorStr.substr(3, 2),
nullptr, 16);
534 int b = std::stoi(
colorStr.substr(5, 2),
nullptr, 16);
535 int a = (
colorStr.length() >= 9) ? std::stoi(
colorStr.substr(7, 2),
nullptr, 16) : 255;
576 const std::string& componentType =
it->second;
603 return &(
it->second);
611 SYSTEM_LOG <<
"Warning: No schema found for parameter '" << parameterName <<
"'" << std::endl;
630 SYSTEM_LOG <<
"Warning: Converting float to int for parameter '" << parameterName <<
"'" << std::endl;
640 SYSTEM_LOG <<
"Error: Type mismatch for parameter '" << parameterName
641 <<
"'. Expected type " <<
static_cast<int>(
entry->expectedType)
642 <<
" but got " <<
static_cast<int>(
param.type) << std::endl;
654 if (
schema.componentType.empty())
663 if (
entry.isRequired)
686 it->second.parameters.find(
paramName) !=
it->second.parameters.end())
699 SYSTEM_LOG <<
"[SchemaDiscovery] Auto-registered: "
701 <<
" (type: " <<
static_cast<int>(
paramValue.type) <<
")"
715 const std::string& componentType,
ComponentTypeID GetComponentTypeID_Static()
ComponentParameter ParseDefaultValue(const nlohmann::json &valueJson, ComponentParameter::Type type) const
const ParameterSchemaEntry * FindParameterSchema(const std::string ¶meterName) const
void RegisterParameterSchema(const ParameterSchemaEntry &entry)
bool LoadSchemaFromFile(const std::string &filepath)
void DiscoverComponentSchema(const ComponentDefinition &componentDef)
bool ValidateParameter(const std::string ¶meterName, const ComponentParameter ¶m) const
bool LoadFromJSON(const std::string &filepath)
const ComponentSchema * GetComponentSchema(const std::string &componentType) const
void InitializeBuiltInSchemas()
void DiscoverSchemasFromPrefab(const PrefabBlueprint &prefab)
std::map< std::string, ComponentSchema > componentSchemas_
size_t GetSchemaCount() const
std::map< std::string, std::string > aliasToParameter_
void AutoRegisterParameter(const std::string &componentType, const std::string ¶mName, ComponentParameter::Type paramType, const ComponentParameter &defaultValue)
ComponentParameter::Type StringToParameterType(const std::string &typeStr) const
std::map< std::string, std::string > parameterToComponent_
static ComponentParameter FromBool(bool value)
static ComponentParameter FromFloat(float value)
static ComponentParameter FromVector2(float x, float y)
static ComponentParameter FromVector3(float x, float y, float z)
static ComponentParameter FromColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
static ComponentParameter FromInt(int value)
static ComponentParameter FromString(const std::string &value)
std::string componentType
std::map< std::string, ParameterSchemaEntry > parameters