DataConfig
DataConfig copied to clipboard
Possible Opt in instead of opt out meta tag?
I know we can add DcSkip to disable being considered for serialize/deserialize but it would be great if instead we could 'flip' the behavior.
UCLASS(DcOptIn)
UPROPERTY(meta = (Dc)) int OptInField1;
I'm sure I could easily switch it to always be opt in here. https://github.com/slowburn-dev/DataConfig/blob/release/DataConfig/Source/DataConfigCore/Private/DataConfig/Property/DcPropertyTypes.cpp#L13
To just switch the logic there. But it would be great if it could be switched on a uclass or ustruct basis instead. Would require a little more effort.
Also just wanted to say I only recently discovered this plugin and bought the premium plugin. It is also one of the most useful pieces of code I have ever found for unreal and for data. It's an incredible shame that it's not talked about more. Having the text based configs for various assets is something that I think unreal should have integrated earlier on.
HI! Thanks a lot for your compliments and support! I was on vacation last week and wasn't accessible to my PC 😉
DcSkip behavior is implemented in FDcPropertyConfig and it's totally configurable. Here's a more complete example implementing the behavior you described:
USTRUCT()
struct FDcTestSerializeMeta1
{
GENERATED_BODY()
UPROPERTY(meta = (DcTestSerialize)) int SerializedField;
UPROPERTY() int IgnoredField;
};
FDcTestSerializeMeta1 Src;
Src.SerializedField = 123;
Src.IgnoredField = 456;
FDcJsonWriter Writer;
UTEST_OK("PropertyConfig", DcAutomationUtils::SerializeInto(&Writer, FDcPropertyDatum(&Src), [](FDcSerializeContext& Ctx)
{
FDcPropertyConfig Config;
// only process fields that has `DcTestSerialize` meta
Config.ProcessPropertyPredicate = FDcProcessPropertyPredicateDelegate::CreateLambda([](FProperty* Property)
{
const static FName TestSerializeMeta = FName(TEXT("DcTestSerialize"));
return DcPropertyUtils::IsEffectiveProperty(Property)
&& Property->HasMetaData(TestSerializeMeta);
});
Config.ExpandObjectPredicate = FDcExpandObjectPredicateDelegate::CreateStatic(DcPropertyUtils::IsSubObjectProperty);
Ctx.Reader->SetConfig(Config);
}));
Writer.Sb << TCHAR('\n');
UTEST_EQUAL("PropertyConfig", Writer.Sb.ToString(), DcAutomationUtils::DcReindentStringLiteral(TEXT(R"(
{
"SerializedField" : 123
}
)")));
You can also look at these links below for more example:
- https://github.com/slowburn-dev/DataConfig/blob/100e6dd805d8eaf21cd98ab853431a360485e3f6/DataConfig/Source/DataConfigCore/Private/DataConfig/Property/DcPropertyTypes.cpp#L10-L14
- https://github.com/slowburn-dev/DataConfig/blob/100e6dd805d8eaf21cd98ab853431a360485e3f6/DataConfig/Source/DataConfigTests/Private/DcTestProperty2.cpp#L68-L71
For DcJsonAsset you might need to edit the source for this behavior.
I'll integrate this test and update the docs in the next release.
Cheers!
I've documented it here with 1.4.0