Skip to content

Commit 873428a

Browse files
feat: add new config property for storing raw values
1 parent 12586ed commit 873428a

11 files changed

Lines changed: 192 additions & 1 deletion

File tree

Binary file not shown.

Mods/SML/Source/SML/Private/Configuration/CodeGeneration/ConfigVariableDescriptor.cpp

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ void FConfigVariableDescriptor::SetupAsObject(UClass* NewBaseObjectClass) {
107107
this->BaseObjectClass = NewBaseObjectClass;
108108
}
109109

110+
void FConfigVariableDescriptor::SetupAsRawJsonValue() {
111+
this->VariableType = EConfigVariableType::ECVT_RawJsonValue;
112+
}
113+
110114
UScriptStruct* FConfigVariableDescriptor::GetCustomStructType() const {
111115
if (VariableType == EConfigVariableType::ECVT_CustomStruct)
112116
return CustomStructType;

Mods/SML/Source/SML/Private/Configuration/CodeGeneration/ConfigVariableLibrary.cpp

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ FConfigVariableDescriptor UConfigVariableLibrary::MakeConfigVariableMap(const FC
4949
VariableDescriptor.SetupAsMap(KeyType, ValueType);
5050
return VariableDescriptor;
5151
}
52+
53+
FConfigVariableDescriptor UConfigVariableLibrary::MakeConfigVariableRawJsonValue() {
54+
FConfigVariableDescriptor VariableDescriptor{};
55+
VariableDescriptor.SetupAsRawJsonValue();
56+
return VariableDescriptor;
57+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "Configuration/Properties/ConfigPropertyRaw.h"
2+
#include "Configuration/CodeGeneration/ConfigVariableDescriptor.h"
3+
#include "Configuration/CodeGeneration/ConfigVariableLibrary.h"
4+
#include "Configuration/RawFileFormat/RawFormatValueRawJson.h"
5+
#include "Reflection/BlueprintReflectedObject.h"
6+
7+
void UConfigPropertyRaw::SetValue(TSharedPtr<FJsonValue> NewValue) {
8+
Value = NewValue.ToSharedRef();
9+
}
10+
11+
void UConfigPropertyRaw::SetValue(TSharedPtr<FJsonObject> NewValue) {
12+
Value = MakeShared<FJsonValueObject>(NewValue);
13+
}
14+
15+
FString UConfigPropertyRaw::DescribeValue_Implementation() const {
16+
return TEXT("[raw]");
17+
}
18+
19+
URawFormatValue* UConfigPropertyRaw::Serialize_Implementation(UObject* Outer) const {
20+
URawFormatValueRawJson* JsonValue = NewObject<URawFormatValueRawJson>(Outer);
21+
JsonValue->Value = Value;
22+
return JsonValue;
23+
}
24+
25+
void UConfigPropertyRaw::Deserialize_Implementation(const URawFormatValue* RawValue) {
26+
const URawFormatValueRawJson* JsonValue = Cast<URawFormatValueRawJson>(RawValue);
27+
Value = JsonValue->Value;
28+
}
29+
30+
void UConfigPropertyRaw::FillConfigStruct_Implementation(
31+
const FReflectedObject& ReflectedObject, const FString& VariableName) const {
32+
checkf(false, TEXT("UConfigPropertyRaw::FillConfigStruct_Implementation: not supported"));
33+
}
34+
35+
bool UConfigPropertyRaw::ResetToDefault_Implementation() {
36+
return false;
37+
}
38+
39+
bool UConfigPropertyRaw::IsSetToDefaultValue_Implementation() const {
40+
return false;
41+
}
42+
43+
FString UConfigPropertyRaw::GetDefaultValueAsString_Implementation() const {
44+
return TEXT("");
45+
}
46+
47+
FConfigVariableDescriptor UConfigPropertyRaw::CreatePropertyDescriptor_Implementation(
48+
UConfigGenerationContext* Context, const FString& OuterPath) const {
49+
return UConfigVariableLibrary::MakeConfigVariablePrimitive(EConfigVariableType::ECVT_RawJsonValue);
50+
}
51+
52+
void UConfigPropertyRaw::PostInitProperties() {
53+
Super::PostInitProperties();
54+
55+
bHidden = 1;
56+
bAllowUserReset = false;
57+
bRequiresWorldReload = 0;
58+
}
59+
60+
#if WITH_EDITOR
61+
bool UConfigPropertyRaw::CanEditChange(const FProperty* InProperty) const {
62+
auto Name = InProperty->GetFName();
63+
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bHidden)) {
64+
return false;
65+
}
66+
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bAllowUserReset)) {
67+
return false;
68+
}
69+
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bRequiresWorldReload)) {
70+
return false;
71+
}
72+
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, DisplayName)) {
73+
return false;
74+
}
75+
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, Tooltip)) {
76+
return false;
77+
}
78+
79+
return Super::CanEditChange(InProperty);
80+
}
81+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "Configuration/Properties/WidgetExtension/CP_Raw.h"

Mods/SML/Source/SML/Private/Configuration/RawFileFormat/Json/JsonRawFormatConverter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Configuration/RawFileFormat/RawFormatValueNumber.h"
55
#include "Configuration/RawFileFormat/RawFormatValueString.h"
66
#include "Configuration/RawFileFormat/RawFormatValueBool.h"
7+
#include "Configuration/RawFileFormat/RawFormatValueRawJson.h"
78
#include "Dom/JsonObject.h"
89

910
TSharedPtr<FJsonValue> FJsonRawFormatConverter::ConvertToJson(const URawFormatValue* RawFormatValue) {
@@ -22,6 +23,9 @@ TSharedPtr<FJsonValue> FJsonRawFormatConverter::ConvertToJson(const URawFormatVa
2223
if (const URawFormatValueObject* Object = Cast<URawFormatValueObject>(RawFormatValue)) {
2324
return Object->ToJson();
2425
}
26+
if (const URawFormatValueRawJson* RawJson = Cast<URawFormatValueRawJson>(RawFormatValue)) {
27+
return RawJson->ToJson();
28+
}
2529
checkf(false, TEXT("Unreachable code"));
2630
return NULL;
2731
}

Mods/SML/Source/SML/Public/Configuration/CodeGeneration/ConfigVariableDescriptor.h

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ enum class EConfigVariableType : uint8 {
1616
ECVT_Object UMETA(DisplayName = "Object"),
1717
ECVT_Class UMETA(DisplayName = "Class"),
1818
ECVT_CustomStruct UMETA(DisplayName = "Custom Structure"),
19-
ECVT_ConfigGeneratedStruct UMETA(DisplayName = "Config Generated Struct (delayed)")
19+
ECVT_ConfigGeneratedStruct UMETA(DisplayName = "Config Generated Struct (delayed)"),
20+
ECVT_RawJsonValue UMETA(DisplayName = "Raw Json Value")
2021
};
2122

2223
/** Describes variable generated by the config property and associated metadata */
@@ -45,6 +46,8 @@ struct SML_API FConfigVariableDescriptor {
4546

4647
void SetupAsClass(UClass* BaseClassType);
4748

49+
void SetupAsRawJsonValue();
50+
4851
/** Type of the generated variable. Decides which of the settings below are applied */
4952
FORCEINLINE EConfigVariableType GetVariableType() const { return VariableType; }
5053

Mods/SML/Source/SML/Public/Configuration/CodeGeneration/ConfigVariableLibrary.h

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class SML_API UConfigVariableLibrary : public UBlueprintFunctionLibrary {
6868
UFUNCTION(BlueprintPure, Category="ConfigVariables", meta=(DisplayName = "Make Config Variable (Map)", Keywords="construct build", NativeMakeFunc))
6969
static FConfigVariableDescriptor MakeConfigVariableMap(const FConfigVariableDescriptor& KeyType, const FConfigVariableDescriptor& ValueType);
7070

71+
/** Creates new instance of raw json value config variable */
72+
UFUNCTION(BlueprintPure, Category="ConfigVariables", meta=(DisplayName = "Make Config Variable (Raw Json Value)", Keywords="construct build", NativeMakeFunc))
73+
static FConfigVariableDescriptor MakeConfigVariableRawJsonValue();
74+
7175
DECLARE_FUNCTION(execMakeConfigVariableStruct) {
7276
const FDynamicStructInfo StructInfo = FReflectionHelper::CheckStructParameter(Context, Stack);
7377
P_FINISH;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
#include "Configuration/ConfigProperty.h"
3+
#include "Configuration/ConfigValueDirtyHandlerInterface.h"
4+
#include "Configuration/RawFileFormat/RawFormatValueRawJson.h"
5+
#include "ConfigPropertyRaw.generated.h"
6+
7+
/**
8+
* Describes a raw configuration property not designed to be edited by the player.
9+
*
10+
* Note: Changes to this property's value will need to be made through C++ code.
11+
* Blueprint editing of this property is not supported.
12+
*/
13+
UCLASS()
14+
class SML_API UConfigPropertyRaw : public UConfigProperty {
15+
GENERATED_BODY()
16+
public:
17+
TSharedRef<FJsonValue> Value = MakeShared<FJsonValueObject>(MakeShareable(new FJsonObject())); // Default to empty JSON object
18+
19+
void SetValue(TSharedPtr<FJsonValue> NewValue);
20+
void SetValue(TSharedPtr<FJsonObject> NewValue);
21+
22+
// Begin UConfigProperty
23+
public:
24+
virtual FString DescribeValue_Implementation() const override;
25+
virtual URawFormatValue* Serialize_Implementation(UObject* Outer) const override;
26+
virtual void Deserialize_Implementation(const URawFormatValue* Value) override;
27+
virtual FConfigVariableDescriptor CreatePropertyDescriptor_Implementation( UConfigGenerationContext* Context, const FString& OuterPath) const override;
28+
virtual void FillConfigStruct_Implementation(const FReflectedObject& ReflectedObject, const FString& VariableName) const override;
29+
virtual bool ResetToDefault_Implementation() override;
30+
virtual bool IsSetToDefaultValue_Implementation() const override;
31+
virtual FString GetDefaultValueAsString_Implementation() const override;
32+
33+
virtual URawFormatValueRawJson* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
34+
return URawFormatValueRawJson::FromJson(Outer, JsonValue);
35+
}
36+
// End UConfigProperty
37+
38+
// Begin UObject
39+
protected:
40+
virtual void PostInitProperties() override;
41+
42+
public:
43+
#if WITH_EDITOR
44+
virtual bool CanEditChange(const FProperty* InProperty) const override;
45+
#endif
46+
// End UObject
47+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include "Configuration/Properties/ConfigPropertyRaw.h"
3+
#include "CP_Raw.generated.h"
4+
5+
UCLASS(EditInlineNew, Abstract)
6+
class SML_API UCP_Raw : public UConfigPropertyRaw {
7+
GENERATED_BODY()
8+
public:
9+
};

0 commit comments

Comments
 (0)