DataConfig icon indicating copy to clipboard operation
DataConfig copied to clipboard

Possible Opt in instead of opt out meta tag?

Open namrog84 opened this issue 3 years ago • 1 comments

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.

namrog84 avatar Sep 03 '22 23:09 namrog84

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:

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!

jagt avatar Sep 12 '22 11:09 jagt

I've documented it here with 1.4.0

jagt avatar Nov 17 '22 05:11 jagt