Live Config
Loading...
Searching...
No Matches
LiveConfigTypes.h
1// Copyright (c) 2026 Nicholas Arthur
2// Licensed under the MIT License
3#pragma once
4
5#include "CoreMinimal.h"
6#include "LiveConfigPropertyName.h"
7#include "Profiles/LiveConfigProfile.h"
8#include "LiveConfigTypes.generated.h"
9
10LIVECONFIG_API DECLARE_LOG_CATEGORY_EXTERN(LogLiveConfig, Log, All);
11
12UENUM(BlueprintType)
13enum class ELiveConfigPropertyChangeType : uint8
14{
15 Name,
16 Description,
17 Type,
18 Value,
19 Tags
20};
21
22UENUM(BlueprintType)
23enum class ELiveConfigPropertyType : uint8
24{
25 String,
26 Int,
27 Float,
28 Bool,
29 Struct
30};
31
32USTRUCT(BlueprintType)
33struct LIVECONFIG_API FLiveConfigPropertyDefinition
34{
35 GENERATED_BODY()
36
37 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
38 FLiveConfigProperty PropertyName;
39
40 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
41 FString Description;
42
43 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
44 ELiveConfigPropertyType PropertyType = ELiveConfigPropertyType::String;
45
46 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
47 TArray<FName> Tags;
48
49 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
50 FString Value;
51
52 bool IsValid() const;
53};
54
59USTRUCT()
61{
62 GENERATED_BODY()
63
64 UPROPERTY()
65 TMap<FLiveConfigProperty, float> FloatValues;
66 UPROPERTY()
67 TMap<FLiveConfigProperty, int32> IntValues;
68 UPROPERTY()
69 TMap<FLiveConfigProperty, FString> StringValues;
70 UPROPERTY()
71 TMap<FLiveConfigProperty, bool> BoolValues;
72
73 void Reset();
74 void SetValue(const FLiveConfigPropertyDefinition& InValue);
75
76 template<typename T>
77 T GetValue(const FLiveConfigProperty& Property) const;
78
79 static void BuildConfig(const TMap<FLiveConfigProperty, FLiveConfigPropertyDefinition>& PropertyDefinitions,
80 const FLiveConfigProfile& EnvironmentProfile, const FLiveConfigProfile& ActiveProfile, FLiveConfigCache& OutCache);
81};
82
83template<>
84inline float FLiveConfigCache::GetValue<float>(const FLiveConfigProperty& Property) const
85{
86 if (const float* Value = FloatValues.Find(Property))
87 {
88 return *Value;
89 }
90
91 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find float value for property: %s"), *Property.ToString());
92 return 0.0f;
93}
94
95template<>
96inline int32 FLiveConfigCache::GetValue<int32>(const FLiveConfigProperty& Property) const
97{
98 if (const int32* Value = IntValues.Find(Property))
99 {
100 return *Value;
101 }
102
103 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find int32 value for property: %s"), *Property.ToString());
104 return 0;
105}
106
107template<>
108inline FString FLiveConfigCache::GetValue<FString>(const FLiveConfigProperty& Property) const
109{
110 if (const FString* Value = StringValues.Find(Property))
111 {
112 return *Value;
113 }
114
115 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find string value for property: %s"), *Property.ToString());
116 return FString();
117}
118
119template<>
120inline bool FLiveConfigCache::GetValue<bool>(const FLiveConfigProperty& Property) const
121{
122 if (const bool* Value = BoolValues.Find(Property))
123 {
124 return *Value;
125 }
126
127 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find bool value for property: %s"), *Property.ToString());
128 return false;
129}
130
131
Definition LiveConfigTypes.h:61
Definition LiveConfigProfile.h:24
Definition LiveConfigTypes.h:34
Definition LiveConfigPropertyName.h:14
FString ToString() const
Definition LiveConfigPropertyName.h:29