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()
13enum class ELiveConfigSyncMode : uint8
14{
16 AlwaysSync,
18 Prompt,
20 NeverSync
21};
22
23UENUM(BlueprintType)
24enum class ELiveConfigPropertyChangeType : uint8
25{
26 Name,
27 Description,
28 Type,
29 Value,
30 Tags
31};
32
33UENUM(BlueprintType)
34enum class ELiveConfigPropertyType : uint8
35{
36 String,
37 Int,
38 Float,
39 Bool,
40 Struct
41};
42
43UENUM()
44enum class ELiveConfigSourceType : uint8
45{
47 None,
49 HttpCsv,
51 LocalCsv
52};
53
54DECLARE_DELEGATE_OneParam(FOnRemoteOverridesFetched, const FLiveConfigProfile&);
55
56USTRUCT(BlueprintType)
57struct LIVECONFIG_API FLiveConfigPropertyDefinition
58{
59 GENERATED_BODY()
60
61 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
62 FLiveConfigProperty PropertyName;
63
64 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
65 FString Description;
66
67 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
68 ELiveConfigPropertyType PropertyType = ELiveConfigPropertyType::String;
69
70 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
71 TArray<FName> Tags;
72
73 UPROPERTY(Config, BlueprintReadWrite, EditAnywhere, Category = "Property")
74 FString Value;
75
76 bool IsDeprecated() const;
77 bool IsValid() const;
78};
79
84USTRUCT()
86{
87 GENERATED_BODY()
88
89 UPROPERTY()
90 TMap<FLiveConfigProperty, float> FloatValues;
91 UPROPERTY()
92 TMap<FLiveConfigProperty, int32> IntValues;
93 UPROPERTY()
94 TMap<FLiveConfigProperty, FString> StringValues;
95 UPROPERTY()
96 TMap<FLiveConfigProperty, bool> BoolValues;
97
98 void Reset();
99 void SetValue(const FLiveConfigPropertyDefinition& InValue);
100
101 template<typename T>
102 T GetValue(const FLiveConfigProperty& Property) const;
103
104 static void BuildConfig(const TMap<FLiveConfigProperty, FLiveConfigPropertyDefinition>& PropertyDefinitions,
105 const FLiveConfigProfile& EnvironmentProfile, const FLiveConfigProfile& ActiveProfile, FLiveConfigCache& OutCache);
106};
107
108template<>
109inline float FLiveConfigCache::GetValue<float>(const FLiveConfigProperty& Property) const
110{
111 if (const float* Value = FloatValues.Find(Property))
112 {
113 return *Value;
114 }
115
116 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find float value for property: %s"), *Property.ToString());
117 return 0.0f;
118}
119
120template<>
121inline int32 FLiveConfigCache::GetValue<int32>(const FLiveConfigProperty& Property) const
122{
123 if (const int32* Value = IntValues.Find(Property))
124 {
125 return *Value;
126 }
127
128 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find int32 value for property: %s"), *Property.ToString());
129 return 0;
130}
131
132template<>
133inline FString FLiveConfigCache::GetValue<FString>(const FLiveConfigProperty& Property) const
134{
135 if (const FString* Value = StringValues.Find(Property))
136 {
137 return *Value;
138 }
139
140 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find string value for property: %s"), *Property.ToString());
141 return FString();
142}
143
144template<>
145inline bool FLiveConfigCache::GetValue<bool>(const FLiveConfigProperty& Property) const
146{
147 if (const bool* Value = BoolValues.Find(Property))
148 {
149 return *Value;
150 }
151
152 UE_LOG(LogLiveConfig, Warning, TEXT("Failed to find bool value for property: %s"), *Property.ToString());
153 return false;
154}
155
156
Definition LiveConfigTypes.h:86
Definition LiveConfigProfile.h:24
Definition LiveConfigTypes.h:58
Definition LiveConfigPropertyName.h:14
FString ToString() const
Definition LiveConfigPropertyName.h:29