24#include <unordered_map>
43 std::cout <<
"[ComponentRegistry] Registered: " << componentName <<
"\n";
53 std::vector<std::string> components;
57 components.push_back(
kv.first);
77 SYSTEM_LOG <<
"PrefabFactory::PreloadAllPrefabs: Already preloaded\n";
81 SYSTEM_LOG <<
"+===========================================================+\n";
82 SYSTEM_LOG <<
"| PREFAB FACTORY: PRELOADING ALL PREFABS |\n";
83 SYSTEM_LOG <<
"+===========================================================+\n";
100 if (
bp &&
bp->isValid)
106 SYSTEM_LOG <<
"\nok - PrefabFactory ready\n\n";
114 SYSTEM_LOG <<
"/!\\ PrefabFactory: Prefabs not preloaded! Call PreloadAllPrefabs() first\n";
122 SYSTEM_LOG <<
"x PrefabFactory: Prefab '" << prefabName <<
"' not found\n";
136 SYSTEM_LOG <<
"PrefabFactory::CreateEntity '" << prefabName <<
"' created (ID: " <<
newEntity <<
")\n";
178 return m_scanner->IsTypeRegistered(type);
197 SYSTEM_LOG <<
"PrefabFactory::CreateEntityFromBlueprint: Invalid blueprint '"
208 SYSTEM_LOG <<
"PrefabFactory::CreateEntityFromBlueprint: Failed to create entity for '"
226 SYSTEM_LOG <<
"PrefabFactory::CreateEntityFromBlueprint: Failed to instantiate component '"
227 <<
componentDef.componentType <<
"' on entity " << entity <<
"\n";
263 SYSTEM_LOG <<
"[PrefabFactory::CreateEntityFromBlueprint] Loaded BehaviorTree: " <<
btPath <<
" (ID=" << treeId <<
")\n";
267 SYSTEM_LOG <<
"[PrefabFactory::CreateEntityFromBlueprint] WARNING: BT not found or invalid: " <<
btPath <<
"\n";
294 SYSTEM_LOG <<
"PrefabFactory::CreateEntityWithOverrides: Invalid blueprint '"
305 SYSTEM_LOG <<
"PrefabFactory::CreateEntityWithOverrides: Failed to create entity for '"
341 SYSTEM_LOG <<
" /!\\ Failed to instantiate component: " <<
resolved.componentType <<
"\n";
383 SYSTEM_LOG <<
"[PrefabFactory::CreateEntityWithOverrides] Loaded BehaviorTree: " <<
btPath <<
" (ID=" << treeId <<
")\n";
387 SYSTEM_LOG <<
"[PrefabFactory::CreateEntityWithOverrides] WARNING: BT not found or invalid: " <<
btPath <<
"\n";
433 if (type ==
"BehaviorTreeRuntime_data")
435 else if (type ==
"Position_data")
437 else if (type ==
"Identity_data")
439 else if (type ==
"PhysicsBody_data")
441 else if (type ==
"VisualSprite_data")
443 else if (type ==
"VisualAnimation_data")
445 else if (type ==
"AIBlackboard_data")
447 else if (type ==
"AISenses_data")
449 else if (type ==
"MoveIntent_data")
451 else if (type ==
"NavigationAgent_data")
460 if (type ==
"Identity" || type ==
"Identity_data")
462 else if (type ==
"Position" || type ==
"Position_data")
464 else if (type ==
"PhysicsBody" || type ==
"PhysicsBody_data")
466 else if (type ==
"VisualSprite" || type ==
"VisualSprite_data")
468 else if (type ==
"VisualAnimation" || type ==
"VisualAnimation_data")
470 else if (type ==
"VisualEditor" || type ==
"VisualEditor_data")
472 else if (type ==
"AIBehavior" || type ==
"AIBehavior_data")
474 else if (type ==
"AIBlackboard" || type ==
"AIBlackboard_data")
476 else if (type ==
"AISenses" || type ==
"AISenses_data")
478 else if (type ==
"AIState" || type ==
"AIState_data")
480 else if (type ==
"BehaviorTreeRuntime" || type ==
"BehaviorTreeRuntime_data")
482 else if (type ==
"MoveIntent" || type ==
"MoveIntent_data")
484 else if (type ==
"AttackIntent" || type ==
"AttackIntent_data")
486 else if (type ==
"BoundingBox" || type ==
"BoundingBox_data")
488 else if (type ==
"Movement" || type ==
"Movement_data")
490 else if (type ==
"Health" || type ==
"Health_data")
492 else if (type ==
"TriggerZone" || type ==
"TriggerZone_data")
494 else if (type ==
"CollisionZone" || type ==
"CollisionZone_data")
496 else if (type ==
"Animation" || type ==
"Animation_data")
498 else if (type ==
"FX" || type ==
"FX_data")
500 else if (type ==
"AudioSource" || type ==
"AudioSource_data")
502 else if (type ==
"Controller" || type ==
"Controller_data")
504 else if (type ==
"PlayerController" || type ==
"PlayerController_data")
506 else if (type ==
"PlayerBinding" || type ==
"PlayerBinding_data")
508 else if (type ==
"NPC" || type ==
"NPC_data")
510 else if (type ==
"Inventory" || type ==
"Inventory_data")
512 else if (type ==
"Camera" || type ==
"Camera_data")
514 else if (type ==
"CameraTarget" || type ==
"CameraTarget_data")
516 else if (type ==
"CameraEffects" || type ==
"CameraEffects_data")
518 else if (type ==
"CameraBounds" || type ==
"CameraBounds_data")
520 else if (type ==
"CameraInputBinding" || type ==
"CameraInputBinding_data")
522 else if (type ==
"InputMapping" || type ==
"InputMapping_data")
526 SYSTEM_LOG <<
"PrefabFactory::InstantiateComponent: Unknown component type '"
528 SYSTEM_LOG <<
" Available auto-registered components:\n";
545 static const std::unordered_map<std::string, EntityType>
typeMap = {
570 std::cerr <<
"[PrefabFactory] ERROR: Identity_data not found for entity " << entity << std::endl;
571 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
603 std::cerr <<
"[PrefabFactory] ERROR: Position_data not found for entity " << entity << std::endl;
604 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
633 std::cerr <<
"[PrefabFactory] ERROR: PhysicsBody_data not found for entity " << entity << std::endl;
634 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
667 std::cerr <<
"[PrefabFactory] ERROR: VisualSprite_data not found for entity " << entity << std::endl;
668 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
685 SYSTEM_LOG <<
"PrefabFactory::InstantiateVisualSprite: Failed to load sprite '"
686 << spritePath <<
"' - component will have null sprite\n";
763 SYSTEM_LOG <<
"PrefabFactory::InstantiateVisualEditor: Failed to load sprite '"
764 << spritePath <<
"' - component will have null sprite\n";
816 std::cerr <<
"[PrefabFactory] ERROR: VisualAnimation_data not found for entity " << entity << std::endl;
817 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
877 std::cerr <<
"[PrefabFactory] ERROR: AIBlackboard_data not found for entity " << entity << std::endl;
878 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
914 std::cerr <<
"[PrefabFactory] ERROR: AISenses_data not found for entity " << entity << std::endl;
915 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
1313 SYSTEM_LOG <<
"[PrefabFactory] ERROR: NavigationAgent_data should exist (auto-registration)\n";
1348 SYSTEM_LOG <<
"PrefabFactory::InstantiateAIState: Warning - Unknown state '"
1349 <<
stateStr <<
"', defaulting to Idle\n";
1363 SYSTEM_LOG <<
"PrefabFactory::InstantiateAIState: Warning - Unknown previousState '"
1364 <<
stateStr <<
"', defaulting to Idle\n";
1386 std::cerr <<
"[PrefabFactory] ERROR: BehaviorTreeRuntime_data not found for entity " << entity << std::endl;
1387 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
1401 std::cerr <<
"[PrefabFactory] Entity " << entity <<
" AITreeAssetId set to " <<
btRuntime.AITreeAssetId << std::endl;
1406 std::cerr <<
"[PrefabFactory] Entity " << entity <<
" treeAssetId (old) set to " <<
btRuntime.AITreeAssetId << std::endl;
1410 std::string treePath;
1420 if (!treePath.empty())
1433 std::cerr <<
"[PrefabFactory] Mapped BehaviorTree: " << treePath <<
" -> ID " << treeId <<
" for entity " <<
identity->name << std::endl;
1435 std::cerr <<
"[PrefabFactory] Mapped BehaviorTree: " << treePath <<
" -> ID " << treeId <<
" for entity " << entity << std::endl;
1441 std::cerr <<
"[PrefabFactory] WARNING: BehaviorTree not loaded: " << treePath
1442 <<
" (ID=" << treeId <<
") - this should not happen if dependencies were loaded correctly" << std::endl;
1464 std::cerr <<
"[PrefabFactory] ERROR: MoveIntent_data not found for entity " << entity << std::endl;
1465 std::cerr <<
"[PrefabFactory] This should have been created by auto-registration!" << std::endl;
1538 SYSTEM_LOG <<
"PrefabFactory::InstantiateAttackIntent: Warning - Unknown attackType '"
1539 <<
typeStr <<
"', defaulting to Melee\n";
Data-driven behavior tree system for AI decision making.
Core ECS component definitions.
RenderLayer
Render layer enumeration for Z-ordering.
ComponentTypeID GetComponentTypeID_Static()
const EntityID INVALID_ENTITY_ID
static EntityType StringToEntityType(const std::string &typeStr)
void RegisterComponentFactory_Internal(const char *componentName, std::function< bool(EntityID, const ComponentDefinition &)> factory)
World and ECS Manager for Olympe Engine.
uint32_t GetTreeIdFromPath(const std::string &treePath) const
const BehaviorTreeAsset * GetTree(uint32_t treeId) const
static BehaviorTreeManager & Get()
static DataManager & Get()
Sprite * GetSprite(const std::string &id, const std::string &path, ResourceCategory category=ResourceCategory::GameEntity)
std::vector< ResolvedComponentInstance > Resolve(const PrefabBlueprint &prefab, const LevelInstanceParameters &instanceParams)
bool InstantiatePosition(EntityID entity, const ComponentDefinition &def)
bool InstantiateAIBehavior(EntityID entity, const ComponentDefinition &def)
void RegisterComponentFactory(const std::string &componentName, std::function< bool(EntityID, const ComponentDefinition &)> factory)
Register a component factory (called by auto-registration system)
bool InstantiateComponent(EntityID entity, const ComponentDefinition &componentDef)
Instantiate a single component on an entity.
bool InstantiateAttackIntent(EntityID entity, const ComponentDefinition &def)
bool InstantiateAudioSource(EntityID entity, const ComponentDefinition &def)
bool InstantiateCameraEffects(EntityID entity, const ComponentDefinition &def)
std::unique_ptr< PrefabScanner > m_scanner
std::map< std::string, std::function< bool(EntityID, const ComponentDefinition &)> > m_componentFactories
bool InstantiateCameraBounds(EntityID entity, const ComponentDefinition &def)
bool IsComponentRegistered(const std::string &componentName) const
Check if a component is registered.
bool InstantiatePhysicsBody(EntityID entity, const ComponentDefinition &def)
bool InstantiateCamera(EntityID entity, const ComponentDefinition &def)
bool InstantiatePlayerController(EntityID entity, const ComponentDefinition &def)
std::string NormalizeType(const std::string &type) const
Normalize a type string to canonical form.
bool InstantiateAIBlackboard(EntityID entity, const ComponentDefinition &def)
PrefabRegistry m_prefabRegistry
bool AreTypesEquivalent(const std::string &type1, const std::string &type2) const
Check if two types are equivalent.
bool InstantiateController(EntityID entity, const ComponentDefinition &def)
bool GetCanonicalInfo(const std::string &type, std::string &outCanonical, std::string &outPrefabFile) const
Get canonical type info for debugging.
void SetPrefabRegistry(const PrefabRegistry ®istry)
Set the prefab registry cache.
bool IsTypeRegistered(const std::string &type) const
Check if a type is registered.
bool InstantiateBoundingBox(EntityID entity, const ComponentDefinition &def)
EntityID CreateEntityWithOverrides(const PrefabBlueprint &blueprint, const LevelInstanceParameters &instanceParams, bool autoAssignLayer=true)
Create entity from blueprint with level instance parameter overrides.
bool InstantiateVisualSprite(EntityID entity, const ComponentDefinition &def)
bool InstantiateVisualAnimation(EntityID entity, const ComponentDefinition &def)
bool InstantiateMoveIntent(EntityID entity, const ComponentDefinition &def)
std::vector< std::string > GetRegisteredComponents() const
Get list of all registered components (for debugging)
bool InstantiatePlayerBinding(EntityID entity, const ComponentDefinition &def)
bool InstantiateBehaviorTreeRuntime(EntityID entity, const ComponentDefinition &def)
EntityID CreateEntityFromBlueprint(const PrefabBlueprint &blueprint, bool autoAssignLayer=true)
Create entity from a parsed blueprint.
bool InstantiateCollisionZone(EntityID entity, const ComponentDefinition &def)
std::map< std::string, PrefabBuilder > m_prefabs
bool InstantiateVisualEditor(EntityID entity, const ComponentDefinition &def)
bool InstantiateFX(EntityID entity, const ComponentDefinition &def)
bool InstantiateAIState(EntityID entity, const ComponentDefinition &def)
static PrefabFactory & Get()
Get singleton instance.
bool InstantiateInputMapping(EntityID entity, const ComponentDefinition &def)
bool InstantiateNavigationAgent(EntityID entity, const ComponentDefinition &def)
bool InstantiateCameraInputBinding(EntityID entity, const ComponentDefinition &def)
bool InstantiateAISenses(EntityID entity, const ComponentDefinition &def)
bool InstantiateIdentity(EntityID entity, const ComponentDefinition &def)
EntityID CreateEntity(const std::string &prefabName)
Create an entity using legacy prefab system.
EntityID CreateEntityFromPrefabName(const std::string &prefabName)
Create entity from prefab name.
bool InstantiateAnimation(EntityID entity, const ComponentDefinition &def)
bool InstantiateHealth(EntityID entity, const ComponentDefinition &def)
bool InstantiateNPC(EntityID entity, const ComponentDefinition &def)
void PreloadAllPrefabs(const std::string &prefabDirectory="Blueprints/EntityPrefab")
Preload all prefabs from directory.
bool InstantiateTriggerZone(EntityID entity, const ComponentDefinition &def)
bool InstantiateMovement(EntityID entity, const ComponentDefinition &def)
bool InstantiateInventory(EntityID entity, const ComponentDefinition &def)
bool InstantiateCameraTarget(EntityID entity, const ComponentDefinition &def)
const PrefabBlueprint * Find(const std::string &name) const
std::vector< std::string > GetAllPrefabNames() const
Core ECS manager and world coordinator.
static World & Get()
Get singleton instance (short form)
T & AddComponent(EntityID entity, Args &&... args)
bool HasComponent(EntityID entity) const
RenderLayer GetDefaultLayerForType(EntityType type) const
Get the default render layer for an entity type Automatically assigns appropriate layer based on enti...
T & GetComponent(EntityID entity)
void SetEntityLayer(EntityID entity, RenderLayer layer)
Set entity render layer (updates position.z)
Header file for PrefabFactory class, responsible for creating game object prefabs.
std::string soundEffectID
Bounding box component for collision detection.
SDL_FRect boundingBox
Collision rectangle.
std::string componentType
const ComponentParameter * GetParameter(const std::string &name) const
bool HasParameter(const std::string &name) const
EntityID AsEntityRef() const
std::string AsString() const
SDL_Color AsColor() const
Identity component for entity identification.
std::string name
Entity name identifier.
Position component for spatial location.
Vector position
2D/3D position vector
std::vector< ComponentDefinition > components
ECS component for animated sprites.