Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
4 changes: 4 additions & 0 deletions Mods/SML/Source/SML/Private/Configuration/CodeGeneration/ConfigVariableDescriptor.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void FConfigVariableDescriptor::SetupAsObject(UClass* NewBaseObjectClass) {
this->BaseObjectClass = NewBaseObjectClass;
}

void FConfigVariableDescriptor::SetupAsRawJsonValue() {
this->VariableType = EConfigVariableType::ECVT_RawJsonValue;
}

UScriptStruct* FConfigVariableDescriptor::GetCustomStructType() const {
if (VariableType == EConfigVariableType::ECVT_CustomStruct)
return CustomStructType;
Expand Down
6 changes: 6 additions & 0 deletions Mods/SML/Source/SML/Private/Configuration/CodeGeneration/ConfigVariableLibrary.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ FConfigVariableDescriptor UConfigVariableLibrary::MakeConfigVariableMap(const FC
VariableDescriptor.SetupAsMap(KeyType, ValueType);
return VariableDescriptor;
}

FConfigVariableDescriptor UConfigVariableLibrary::MakeConfigVariableRawJsonValue() {
FConfigVariableDescriptor VariableDescriptor{};
VariableDescriptor.SetupAsRawJsonValue();
return VariableDescriptor;
}
6 changes: 3 additions & 3 deletions Mods/SML/Source/SML/Private/Configuration/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Util/SemVersion.h"
#include "TimerManager.h"
#include "Configuration/RootConfigValueHolder.h"
#include "Configuration/RawFileFormat/RawFormatValueObject.h"
#include "Configuration/RawFileFormat/Json/JsonRawFormatConverter.h"
#include "Dom/JsonValue.h"
#include "Engine/GameInstance.h"
Expand Down Expand Up @@ -35,7 +36,7 @@ void UConfigManager::SaveConfigurationInternal(const FConfigId& ConfigId) {
checkf(RawFormatValue, TEXT("Root RawFormatValue returned NULL for config %s"), *ConfigId.ModReference);

//Root value should always be JsonObject, since root property is section property
const TSharedPtr<FJsonValue> JsonValue = FJsonRawFormatConverter::ConvertToJson(RawFormatValue);
const TSharedPtr<FJsonValue> JsonValue = RawFormatValue->ToJson();
check(JsonValue->Type == EJson::Object);
TSharedRef<FJsonObject> UnderlyingObject = JsonValue->AsObject().ToSharedRef();

Expand Down Expand Up @@ -95,8 +96,7 @@ void UConfigManager::LoadConfigurationInternal(const FConfigId& ConfigId, URootC

//Convert JSON tree into the raw value tree and feed it to root section value
const TSharedRef<FJsonValue> RootValue = MakeShareable(new FJsonValueObject(JsonObject));
URawFormatValue* RawFormatValue = FJsonRawFormatConverter::ConvertToRawFormat(this, RootValue);
RootConfigValueHolder->GetWrappedValue()->Deserialize(RawFormatValue);
RootConfigValueHolder->GetWrappedValue()->DeserializeFromJson(RootValue);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,8 @@ FConfigVariableDescriptor UConfigPropertyArray::CreatePropertyDescriptor_Impleme
return UConfigVariableLibrary::MakeConfigVariableArray(DefaultValue->CreatePropertyDescriptor(Context, OuterPath));
}

#undef LOCTEXT_NAMESPACE
UConfigProperty* UConfigPropertyArray::GetChildProperty_Implementation(const int32 PropertyIndex) {
return Values[PropertyIndex];
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "Configuration/Properties/ConfigPropertyRaw.h"
#include "Configuration/CodeGeneration/ConfigVariableDescriptor.h"
#include "Configuration/CodeGeneration/ConfigVariableLibrary.h"
#include "Configuration/RawFileFormat/RawFormatValueRawJson.h"
#include "Reflection/BlueprintReflectedObject.h"

void UConfigPropertyRaw::SetValue(TSharedPtr<FJsonValue> NewValue) {
Value = NewValue.ToSharedRef();
}

void UConfigPropertyRaw::SetValue(TSharedPtr<FJsonObject> NewValue) {
Value = MakeShared<FJsonValueObject>(NewValue);
}

FString UConfigPropertyRaw::DescribeValue_Implementation() const {
return TEXT("[raw]");
}

URawFormatValue* UConfigPropertyRaw::Serialize_Implementation(UObject* Outer) const {
URawFormatValueRawJson* JsonValue = NewObject<URawFormatValueRawJson>(Outer);
JsonValue->Value = Value;
return JsonValue;
}

void UConfigPropertyRaw::Deserialize_Implementation(const URawFormatValue* RawValue) {
const URawFormatValueRawJson* JsonValue = Cast<URawFormatValueRawJson>(RawValue);
Value = JsonValue->Value;
}

void UConfigPropertyRaw::FillConfigStruct_Implementation(
const FReflectedObject& ReflectedObject, const FString& VariableName) const {
checkf(false, TEXT("UConfigPropertyRaw::FillConfigStruct_Implementation: not supported"));
}

bool UConfigPropertyRaw::ResetToDefault_Implementation() {
return false;
}

bool UConfigPropertyRaw::IsSetToDefaultValue_Implementation() const {
return false;
}

FString UConfigPropertyRaw::GetDefaultValueAsString_Implementation() const {
return TEXT("");
}

FConfigVariableDescriptor UConfigPropertyRaw::CreatePropertyDescriptor_Implementation(
UConfigGenerationContext* Context, const FString& OuterPath) const {
return UConfigVariableLibrary::MakeConfigVariablePrimitive(EConfigVariableType::ECVT_RawJsonValue);
}

void UConfigPropertyRaw::PostInitProperties() {
Super::PostInitProperties();

bHidden = 1;
bAllowUserReset = false;
bRequiresWorldReload = 0;
}

#if WITH_EDITOR
bool UConfigPropertyRaw::CanEditChange(const FProperty* InProperty) const {
auto Name = InProperty->GetFName();
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bHidden)) {
return false;
}
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bAllowUserReset)) {
return false;
}
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, bRequiresWorldReload)) {
return false;
}
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, DisplayName)) {
return false;
}
if (Name == GET_MEMBER_NAME_CHECKED(UConfigPropertyRaw, Tooltip)) {
return false;
}

return Super::CanEditChange(InProperty);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ FConfigVariableDescriptor UConfigPropertySection::CreatePropertyDescriptor_Imple
return UConfigVariableLibrary::MakeConfigVariableGeneratedStruct(GeneratedStruct);
}

#undef LOCTEXT_NAMESPACE
UConfigProperty* UConfigPropertySection::GetChildProperty_Implementation(const FString& PropertyName) {
return SectionProperties.FindRef(PropertyName);
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Configuration/Properties/WidgetExtension/CP_Raw.h"
66 changes: 25 additions & 41 deletions Mods/SML/Source/SML/Private/Configuration/RawFileFormat/Json/JsonRawFormatConverter.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
#include "Configuration/RawFileFormat/Json/JsonRawFormatConverter.h"
#include "Configuration/RawFileFormat/RawFormatValueObject.h"
#include "Configuration/RawFileFormat/RawFormatValueArray.h"
#include "Configuration/RawFileFormat/RawFormatValueBool.h"
#include "Configuration/RawFileFormat/RawFormatValueNumber.h"
#include "Configuration/RawFileFormat/RawFormatValueObject.h"
#include "Configuration/RawFileFormat/RawFormatValueRawJson.h"
#include "Configuration/RawFileFormat/RawFormatValueString.h"
#include "Configuration/RawFileFormat/RawFormatValueBool.h"
#include "Dom/JsonObject.h"

TSharedPtr<FJsonValue> FJsonRawFormatConverter::ConvertToJson(const URawFormatValue* RawFormatValue) {
if (const URawFormatValueNumber* Number = Cast<URawFormatValueNumber>(RawFormatValue)) {
return MakeShareable(new FJsonValueNumber(Number->Value));
return Number->ToJson();
}
if (const URawFormatValueString* String = Cast<URawFormatValueString>(RawFormatValue)) {
return MakeShareable(new FJsonValueString(String->Value));
return String->ToJson();
}
if (const URawFormatValueBool* Boolean = Cast<URawFormatValueBool>(RawFormatValue)) {
return MakeShareable(new FJsonValueBoolean(Boolean->Value));
return Boolean->ToJson();
}
if (const URawFormatValueArray* Array = Cast<URawFormatValueArray>(RawFormatValue)) {
TArray<TSharedPtr<FJsonValue>> OutJsonArray;
for (const URawFormatValue* ChildValue : Array->GetUnderlyingArrayRef()) {
OutJsonArray.Add(ConvertToJson(ChildValue));
}
return MakeShareable(new FJsonValueArray(OutJsonArray));
return Array->ToJson();
}
if (const URawFormatValueObject* Object = Cast<URawFormatValueObject>(RawFormatValue)) {
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
for (TPair<FString, URawFormatValue*> Pair : Object->Values) {
JsonObject->SetField(Pair.Key, ConvertToJson(Pair.Value));
}
return MakeShareable(new FJsonValueObject(JsonObject));
return Object->ToJson();
}
if (const URawFormatValueRawJson* RawJson = Cast<URawFormatValueRawJson>(RawFormatValue)) {
return RawJson->ToJson();
}
checkf(false, TEXT("Unreachable code"));
return NULL;
Expand All @@ -37,39 +33,27 @@ TSharedPtr<FJsonValue> FJsonRawFormatConverter::ConvertToJson(const URawFormatVa
URawFormatValue* FJsonRawFormatConverter::ConvertToRawFormat(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) {
switch (JsonValue->Type) {
case EJson::Number: {
URawFormatValueNumber* Number = NewObject<URawFormatValueNumber>(Outer);
Number->Value = JsonValue->AsNumber();
return Number;
}
return URawFormatValueNumber::FromJson(Outer, JsonValue);
}
case EJson::String: {
URawFormatValueString* String = NewObject<URawFormatValueString>(Outer);
String->Value = JsonValue->AsString();
return String;
}
return URawFormatValueString::FromJson(Outer, JsonValue);
}
case EJson::Boolean: {
URawFormatValueBool* Boolean = NewObject<URawFormatValueBool>(Outer);
Boolean->Value = JsonValue->AsBool();
return Boolean;
}
return URawFormatValueBool::FromJson(Outer, JsonValue);
}
case EJson::Array: {
URawFormatValueArray* Array = NewObject<URawFormatValueArray>(Outer);
for (const TSharedPtr<FJsonValue>& ChildValue : JsonValue->AsArray()) {
Array->AddValue(ConvertToRawFormat(Array, ChildValue));
}
return Array;
}
return URawFormatValueArray::FromJson(Outer, JsonValue);
}
case EJson::Object: {
URawFormatValueObject* Object = NewObject<URawFormatValueObject>(Outer);
for (const TPair<FString, TSharedPtr<FJsonValue>>& Pair : JsonValue->AsObject()->Values) {
Object->AddValue(Pair.Key, ConvertToRawFormat(Object, Pair.Value));
}
return Object;
}
case EJson::Null:
return URawFormatValueObject::FromJson(Outer, JsonValue);
}
case EJson::Null: {
checkf(false, TEXT("JSON Null value is not supported"));
return NULL;
default:
}
default: {
checkf(false, TEXT("Unreachable code"));
return NULL;
}
}
}
5 changes: 4 additions & 1 deletion Mods/SML/Source/SML/Public/Configuration/CodeGeneration/ConfigVariableDescriptor.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum class EConfigVariableType : uint8 {
ECVT_Object UMETA(DisplayName = "Object"),
ECVT_Class UMETA(DisplayName = "Class"),
ECVT_CustomStruct UMETA(DisplayName = "Custom Structure"),
ECVT_ConfigGeneratedStruct UMETA(DisplayName = "Config Generated Struct (delayed)")
ECVT_ConfigGeneratedStruct UMETA(DisplayName = "Config Generated Struct (delayed)"),
ECVT_RawJsonValue UMETA(DisplayName = "Raw Json Value")
};

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

void SetupAsClass(UClass* BaseClassType);

void SetupAsRawJsonValue();

/** Type of the generated variable. Decides which of the settings below are applied */
FORCEINLINE EConfigVariableType GetVariableType() const { return VariableType; }

Expand Down
4 changes: 4 additions & 0 deletions Mods/SML/Source/SML/Public/Configuration/CodeGeneration/ConfigVariableLibrary.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class SML_API UConfigVariableLibrary : public UBlueprintFunctionLibrary {
UFUNCTION(BlueprintPure, Category="ConfigVariables", meta=(DisplayName = "Make Config Variable (Map)", Keywords="construct build", NativeMakeFunc))
static FConfigVariableDescriptor MakeConfigVariableMap(const FConfigVariableDescriptor& KeyType, const FConfigVariableDescriptor& ValueType);

/** Creates new instance of raw json value config variable */
UFUNCTION(BlueprintPure, Category="ConfigVariables", meta=(DisplayName = "Make Config Variable (Raw Json Value)", Keywords="construct build", NativeMakeFunc))
static FConfigVariableDescriptor MakeConfigVariableRawJsonValue();

DECLARE_FUNCTION(execMakeConfigVariableStruct) {
const FDynamicStructInfo StructInfo = FReflectionHelper::CheckStructParameter(Context, Stack);
P_FINISH;
Expand Down
15 changes: 15 additions & 0 deletions Mods/SML/Source/SML/Public/Configuration/ConfigProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "FGGameMode.h"
#include "UObject/Object.h"
#include "Configuration/CodeGeneration/ConfigVariableDescriptor.h"
#include "Configuration/RawFileFormat/Json/JsonRawFormatConverter.h"
#include "Reflection/BlueprintReflectedObject.h"
#include "SatisfactoryModLoader.h"
#include "ConfigProperty.generated.h"

class URawFormatValue;
Expand Down Expand Up @@ -59,6 +61,19 @@ class SML_API UConfigProperty : public UObject {
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void Deserialize(const URawFormatValue* Value);

/** Deserializes passed json value into this property state */
void DeserializeFromJson(const TSharedPtr<FJsonValue>& JsonValue) {
Deserialize(CreateRawFormatValue(this, JsonValue));
}

/** Creates a raw format value from the passed json value */
virtual URawFormatValue* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) {
// This is a fallback. Derived classes should create a specific raw format value based on the expected type.
UE_LOG(LogSatisfactoryModLoader, Warning, TEXT("Creating raw format value for property %s with fallback implementation."), *GetName());
#pragma warning(suppress : 4996)
return FJsonRawFormatConverter::ConvertToRawFormat(Outer, JsonValue);
}

/** Marks this property directly, forcing file system synchronization to happen afterwards */
UFUNCTION(BlueprintCallable)
virtual void MarkDirty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "CoreMinimal.h"
#include "Configuration/ConfigProperty.h"
#include "ConfigValueArrayInterface.generated.h"

UINTERFACE(Blueprintable, BlueprintType)
class SML_API UConfigValueArrayInterface : public UInterface {
GENERATED_BODY()
};

class SML_API IConfigValueArrayInterface {
GENERATED_BODY()
public:
/** Returns the child property of this property at the specified index */
UFUNCTION(BlueprintNativeEvent)
UConfigProperty* GetChildProperty(const int32 PropertyIndex);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "CoreMinimal.h"
#include "Configuration/ConfigProperty.h"
#include "ConfigValueObjectInterface.generated.h"

UINTERFACE(Blueprintable, BlueprintType)
class SML_API UConfigValueObjectInterface : public UInterface {
GENERATED_BODY()
};

class SML_API IConfigValueObjectInterface {
GENERATED_BODY()
public:
/** Returns the child property of this property with the specified key */
UFUNCTION(BlueprintNativeEvent)
UConfigProperty* GetChildProperty(const FString& PropertyKey);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once
#include "Configuration/ConfigProperty.h"
#include "Configuration/ConfigValueArrayInterface.h"
#include "Configuration/ConfigValueDirtyHandlerInterface.h"
#include "Configuration/RawFileFormat/RawFormatValueArray.h"
#include "ConfigPropertyArray.generated.h"

/** Describes array configuration property with single nested element type */
UCLASS()
class SML_API UConfigPropertyArray : public UConfigProperty, public IConfigValueDirtyHandlerInterface {
class SML_API UConfigPropertyArray : public UConfigProperty, public IConfigValueDirtyHandlerInterface, public IConfigValueArrayInterface {
GENERATED_BODY()
public:
/** Defines the "template" default value used for allocating other values in the array */
Expand Down Expand Up @@ -57,9 +59,19 @@ class SML_API UConfigPropertyArray : public UConfigProperty, public IConfigValue
virtual bool ResetToDefault_Implementation() override;
virtual bool IsSetToDefaultValue_Implementation() const override;
virtual FString GetDefaultValueAsString_Implementation() const override;

virtual URawFormatValueArray* CreateRawFormatValue(UObject* Outer, const TSharedPtr<FJsonValue>& JsonValue) override {
return URawFormatValueArray::FromJson(Outer, JsonValue);
}
//End UConfigProperty

//Begin IConfigValueDirtyHandlerInterface
virtual void HandleMarkDirty_Implementation() override;
//End IConfigValueDirtyHandlerInterface
};

//Begin IConfigPropertyArrayInterface
/** Returns the child property of this property at the specified index */
UFUNCTION(BlueprintCallable, BlueprintPure, meta = (DisplayName = "Get Child By Index", CompactNodeTitle = ".", BlueprintAutocast), Category = "SML | Configuration")
virtual UConfigProperty* GetChildProperty_Implementation(const int32 PropertyIndex) override;
//End IConfigPropertyArrayInterface
};
Loading