Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ParameterResolver.h
Go to the documentation of this file.
1/*
2Olympe Engine V2 - 2025
3Nicolas Chereau
4nchereau@gmail.com
5
6This file is part of Olympe Engine V2.
7
8ParameterResolver purpose: Resolves and merges prefab blueprint parameters with
9level instance parameters to create final component configurations. Handles property
10overrides with priority-based merging and type conversion.
11*/
12
13#pragma once
14
15#include <string>
16#include <map>
17#include <vector>
18#include "vector.h"
19#include "ComponentDefinition.h"
20#include "PrefabScanner.h"
21
22// Forward declarations
23namespace Olympe {
24namespace Blueprint {
25 struct EntityBlueprint;
26}
27}
28
29// Object reference for linking level objects together
31{
32 std::string propertyName; // Name of the property that references another object
33 std::string targetObjectId; // ID of the target object in the level
34 std::string targetObjectName; // Name of the target object (for debugging)
35
36 ObjectReference() = default;
37 ObjectReference(const std::string& prop, const std::string& id, const std::string& name)
39};
40
41// Level instance parameters - represents an object instance in a level
43{
44 std::string objectName; // Unique name/ID of this object instance
45 std::string objectType; // Prefab type (e.g., "player", "enemy")
46 Vector position; // Position in the level (x, y, z)
47 std::map<std::string, ComponentParameter> properties; // Custom property overrides (legacy/flat)
48
49 // NEW: Component-scoped overrides to prevent cross-component overwrites
50 // Maps: componentType -> (parameterName -> parameterValue)
51 // Example: componentOverrides["Transform"]["width"] = ComponentParameter::FromFloat(32.0f)
52 std::map<std::string, std::map<std::string, ComponentParameter>> componentOverrides;
53
54 std::vector<ObjectReference> objectReferences; // References to other objects
55
57 LevelInstanceParameters(const std::string& name, const std::string& type)
58 : objectName(name), objectType(type), position(0.0f, 0.0f, 0.0f) {}
59};
60
61// Resolved component instance - final component with merged parameters
63{
64 std::string componentType; // Component type name
65 std::map<std::string, ComponentParameter> parameters; // Final resolved parameters
66 bool isValid; // Whether resolution was successful
67 std::vector<std::string> errors; // Errors encountered during resolution
68
70 explicit ResolvedComponentInstance(const std::string& type)
71 : componentType(type), isValid(true) {}
72};
73
74// ParameterResolver - Resolves prefab and level parameters into final component configurations
76{
77public:
80
81 // Main resolution method
82 // Merges prefab defaults with level instance parameters
83 // Priority: Level position > Level custom properties > Prefab defaults
84 std::vector<ResolvedComponentInstance> Resolve(
87 );
88
89private:
90 // Resolve a single component with instance parameters
94 );
95
96 // Apply a property override from level to component
99 const std::string& propertyName,
101 );
102
103 // Extract component-specific parameters from level properties
104 std::map<std::string, ComponentParameter> ExtractComponentParameters(
105 const std::string& componentType,
107 );
108
109 // Convert level property to component parameter (with type conversion)
111 const std::string& propertyName,
113 ComponentParameter::Type expectedType
114 );
115
116 // Validate a resolved component
118};
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::map< std::string, ComponentParameter > ExtractComponentParameters(const std::string &componentType, const LevelInstanceParameters &instanceParams)
void ApplyPropertyOverride(ResolvedComponentInstance &component, const std::string &propertyName, const ComponentParameter &propertyValue)
ResolvedComponentInstance ResolveComponent(const ComponentDefinition &componentDef, const LevelInstanceParameters &instanceParams)
std::vector< ResolvedComponentInstance > Resolve(const PrefabBlueprint &prefab, const LevelInstanceParameters &instanceParams)
ComponentParameter ConvertLevelProperty(const std::string &propertyName, const ComponentParameter &levelProperty, ComponentParameter::Type expectedType)
void ValidateResolvedComponent(ResolvedComponentInstance &component)
std::map< std::string, std::map< std::string, ComponentParameter > > componentOverrides
LevelInstanceParameters()=default
std::vector< ObjectReference > objectReferences
std::map< std::string, ComponentParameter > properties
LevelInstanceParameters(const std::string &name, const std::string &type)
ObjectReference(const std::string &prop, const std::string &id, const std::string &name)
std::string targetObjectName
ObjectReference()=default
std::string propertyName
std::string targetObjectId
std::vector< std::string > errors
ResolvedComponentInstance(const std::string &type)
std::map< std::string, ComponentParameter > parameters