Skip to content

Commit 12586ed

Browse files
refactor: UConfigPropertys are now directly given the json value from which they should deserialize
For `URawFormatValue::FromJson` of values capable of having children, if the `UConfigProperty` is avaliable, that `UConfigProperty` is now used to perform the deserialize of the child value.
1 parent 6999ae4 commit 12586ed

12 files changed

Lines changed: 79 additions & 9 deletions

Mods/SML/Source/SML/Private/Configuration/ConfigManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ void UConfigManager::LoadConfigurationInternal(const FConfigId& ConfigId, URootC
9696

9797
//Convert JSON tree into the raw value tree and feed it to root section value
9898
const TSharedRef<FJsonValue> RootValue = MakeShareable(new FJsonValueObject(JsonObject));
99-
URawFormatValue* RawFormatValue = URawFormatValueObject::FromJson(this, RootValue);
100-
RootConfigValueHolder->GetWrappedValue()->Deserialize(RawFormatValue);
99+
RootConfigValueHolder->GetWrappedValue()->DeserializeFromJson(RootValue);
101100

102101
UE_LOG(LogConfigManager, Display, TEXT("Successfully loaded configuration from %s"), *ConfigurationFilePath);
103102

Mods/SML/Source/SML/Public/Configuration/ConfigProperty.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "FGGameMode.h"
44
#include "UObject/Object.h"
55
#include "Configuration/CodeGeneration/ConfigVariableDescriptor.h"
6+
#include "Configuration/RawFileFormat/Json/JsonRawFormatConverter.h"
67
#include "Reflection/BlueprintReflectedObject.h"
8+
#include "SatisfactoryModLoader.h"
79
#include "ConfigProperty.generated.h"
810

911
class URawFormatValue;
@@ -59,6 +61,19 @@ class SML_API UConfigProperty : public UObject {
5961
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
6062
void Deserialize(const URawFormatValue* Value);
6163

64+
/** Deserializes passed json value into this property state */
65+
void DeserializeFromJson(const TSharedPtr<FJsonValue>& JsonValue) {
66+
Deserialize(CreateRawFormatValue(this, JsonValue));
67+
}
68+
69+
/** Creates a raw format value from the passed json value */
70+
virtual URawFormatValue* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) {
71+
// This is a fallback. Derived classes should create a specific raw format value based on the expected type.
72+
UE_LOG(LogSatisfactoryModLoader, Warning, TEXT("Creating raw format value for property %s with fallback implementation."), *GetName());
73+
#pragma warning(suppress : 4996)
74+
return FJsonRawFormatConverter::ConvertToRawFormat(Outer, JsonValue);
75+
}
76+
6277
/** Marks this property directly, forcing file system synchronization to happen afterwards */
6378
UFUNCTION(BlueprintCallable)
6479
virtual void MarkDirty();

Mods/SML/Source/SML/Public/Configuration/ConfigValueObjectInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class SML_API IConfigValueObjectInterface {
1212
GENERATED_BODY()
1313
public:
1414
/** Returns the child property of this property at the specified index */
15-
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
16-
UConfigProperty* GetChildProperty(const FString& PropertyName);
15+
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
16+
UConfigProperty* GetChildProperty(const FString& PropertyName);
1717
};

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyArray.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "Configuration/ConfigProperty.h"
33
#include "Configuration/ConfigValueArrayInterface.h"
44
#include "Configuration/ConfigValueDirtyHandlerInterface.h"
5+
#include "Configuration/RawFileFormat/RawFormatValueArray.h"
56
#include "ConfigPropertyArray.generated.h"
67

78
/** Describes array configuration property with single nested element type */
@@ -58,6 +59,10 @@ class SML_API UConfigPropertyArray : public UConfigProperty, public IConfigValue
5859
virtual bool ResetToDefault_Implementation() override;
5960
virtual bool IsSetToDefaultValue_Implementation() const override;
6061
virtual FString GetDefaultValueAsString_Implementation() const override;
62+
63+
virtual URawFormatValueArray* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
64+
return URawFormatValueArray::FromJson(Outer, JsonValue);
65+
}
6166
//End UConfigProperty
6267

6368
//Begin IConfigValueDirtyHandlerInterface

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyBool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/RawFileFormat/RawFormatValueBool.h"
34
#include "ConfigPropertyBool.generated.h"
45

56
UCLASS()
@@ -32,5 +33,9 @@ class SML_API UConfigPropertyBool : public UConfigProperty {
3233
virtual bool ResetToDefault_Implementation() override;
3334
virtual bool IsSetToDefaultValue_Implementation() const override;
3435
virtual FString GetDefaultValueAsString_Implementation() const override;
36+
37+
virtual URawFormatValueBool* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
38+
return URawFormatValueBool::FromJson(Outer, JsonValue);
39+
}
3540
//End UConfigProperty
3641
};

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyClass.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/RawFileFormat/RawFormatValueString.h"
34
#include "ConfigPropertyClass.generated.h"
45

56
UCLASS()
@@ -60,5 +61,9 @@ class SML_API UConfigPropertyClass : public UConfigProperty {
6061
virtual bool ResetToDefault_Implementation() override;
6162
virtual bool IsSetToDefaultValue_Implementation() const override;
6263
virtual FString GetDefaultValueAsString_Implementation() const override;
64+
65+
virtual URawFormatValueString* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
66+
return URawFormatValueString::FromJson(Outer, JsonValue);
67+
}
6368
//End UConfigProperty
6469
};

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyFloat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/RawFileFormat/RawFormatValueNumber.h"
34
#include "ConfigPropertyFloat.generated.h"
45

56
UCLASS()
@@ -32,5 +33,9 @@ class SML_API UConfigPropertyFloat : public UConfigProperty {
3233
virtual bool ResetToDefault_Implementation() override;
3334
virtual bool IsSetToDefaultValue_Implementation() const override;
3435
virtual FString GetDefaultValueAsString_Implementation() const override;
36+
37+
virtual URawFormatValueNumber* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
38+
return URawFormatValueNumber::FromJson(Outer, JsonValue);
39+
}
3540
//End UConfigProperty
3641
};

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyInteger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/RawFileFormat/RawFormatValueNumber.h"
34
#include "ConfigPropertyInteger.generated.h"
45

56
UCLASS()
@@ -32,5 +33,9 @@ class SML_API UConfigPropertyInteger : public UConfigProperty {
3233
virtual bool ResetToDefault_Implementation() override;
3334
virtual bool IsSetToDefaultValue_Implementation() const override;
3435
virtual FString GetDefaultValueAsString_Implementation() const override;
36+
37+
virtual URawFormatValueNumber* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
38+
return URawFormatValueNumber::FromJson(Outer, JsonValue);
39+
}
3540
//End UConfigProperty
3641
};

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertySection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "Configuration/ConfigProperty.h"
33
#include "Configuration/ConfigValueObjectInterface.h"
44
#include "Configuration/ConfigValueDirtyHandlerInterface.h"
5+
#include "Configuration/RawFileFormat/RawFormatValueObject.h"
56
#include "ConfigPropertySection.generated.h"
67

78
/** Describes a single configuration section with nested properties */
@@ -38,6 +39,10 @@ class SML_API UConfigPropertySection : public UConfigProperty, public IConfigVal
3839
virtual bool ResetToDefault_Implementation() override;
3940
virtual bool IsSetToDefaultValue_Implementation() const override;
4041
virtual FString GetDefaultValueAsString_Implementation() const override;
42+
43+
virtual URawFormatValueObject* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
44+
return URawFormatValueObject::FromJson(Outer, JsonValue);
45+
}
4146
//End UConfigProperty
4247

4348
//Begin IConfigValueDirtyHandlerInterface

Mods/SML/Source/SML/Public/Configuration/Properties/ConfigPropertyString.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/RawFileFormat/RawFormatValueString.h"
34
#include "ConfigPropertyString.generated.h"
45

56
UCLASS()
@@ -32,5 +33,9 @@ class SML_API UConfigPropertyString : public UConfigProperty {
3233
virtual bool ResetToDefault_Implementation() override;
3334
virtual bool IsSetToDefaultValue_Implementation() const override;
3435
virtual FString GetDefaultValueAsString_Implementation() const override;
36+
37+
virtual URawFormatValueString* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
38+
return URawFormatValueString::FromJson(Outer, JsonValue);
39+
}
3540
//End UConfigProperty
3641
};

0 commit comments

Comments
 (0)