Skip to content

Commit

Permalink
release 1.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jagt committed Nov 27, 2024
1 parent e1bf09a commit 283e1f9
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ FDcResult _ExpectEqual<EDcDataEntry>(const EDcDataEntry& Lhs, const EDcDataEntry
}
}

template<>
FDcResult _ExpectEqual<FText>(const FText& Lhs, const FText& Rhs)
{
auto _DeepTextCheck = [](const FText& Lhs, const FText& Rhs) -> bool
{
if (FTextInspector::GetNamespace(Lhs) != FTextInspector::GetNamespace(Rhs))
return false;

if (FTextInspector::GetKey(Lhs) != FTextInspector::GetKey(Rhs))
return false;

const FString* LhsSource = FTextInspector::GetSourceString(Lhs);
const FString* RhsSource = FTextInspector::GetSourceString(Rhs);

if ((LhsSource == nullptr && RhsSource != nullptr)
|| (LhsSource != nullptr && RhsSource == nullptr))
return false;

if (LhsSource == nullptr && RhsSource == nullptr)
return true;

return *LhsSource == *RhsSource;
};

return _DeepTextCheck(Lhs, Rhs)
? DcOk()
: DC_FAIL(DcDReadWrite, DataTypeUnequalLhsRhs)
<< "FText" << Lhs << Rhs;
}

FDcResult TestReadDatumEqual(const FDcPropertyDatum& LhsDatum, const FDcPropertyDatum& RhsDatum, EReadDatumEqualType Type)
{
FDcPropertyReader LhsReader(LhsDatum);
Expand Down Expand Up @@ -124,7 +154,7 @@ FDcResult TestReadDatumEqual(const FDcPropertyDatum& LhsDatum, const FDcProperty
FText Rhs;
DC_TRY(RhsReader.ReadText(&Rhs));

DC_TRY(_ExpectEqual(Lhs.ToString(), Rhs.ToString()));
DC_TRY(_ExpectEqual(Lhs, Rhs));
break;
}
case EDcDataEntry::Enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ void DcSetupCoreTypesDeserializeHandlers(FDcDeserializer& Deserializer)
Deserializer.AddStructHandler(TBaseStructure<FDateTime>::Get(), FDcDeserializeDelegate::CreateStatic(HandlerDateTimeDeserialize));
Deserializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("Timespan"), true), FDcDeserializeDelegate::CreateStatic(HandlerTimespanDeserialize));

Deserializer.FieldClassDeserializerMap[FTextProperty::StaticClass()] = FDcDeserializeDelegate::CreateStatic(HandlerTextDeserialize);

Deserializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("IntPoint"), true), FDcDeserializeDelegate::CreateStatic(HandlerIntPointDeserialize));
Deserializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("IntVector"), true), FDcDeserializeDelegate::CreateStatic(HandlerIntVectorDeserialize));
#if !UE_VERSION_OLDER_THAN(5, 1, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "DataConfig/SerDe/DcSerDeCoreTypesCommon.h"
#include "DataConfig/Diagnostic/DcDiagnosticSerDe.h"

#include "Misc/EngineVersionComparison.h"

namespace DcCoreTypesHandlers {

struct FDcScopedSkipStructHandler
Expand Down Expand Up @@ -230,6 +232,61 @@ FDcResult HandlerTimespanDeserialize(FDcDeserializeContext& Ctx)
}
}

FDcResult HandlerTextDeserialize(FDcDeserializeContext& Ctx)
{
EDcDataEntry Next;
DC_TRY(Ctx.Reader->PeekRead(&Next));
if (Next == EDcDataEntry::String)
{
FText Value;
DC_TRY(Ctx.Reader->ReadText(&Value));
DC_TRY(Ctx.Writer->WriteText(Value));
return DcOk();
}
else if (Next == EDcDataEntry::ArrayRoot)
{
DC_TRY(Ctx.Reader->ReadArrayRoot());

FString Value1;
FString Value2;
DC_TRY(Ctx.Reader->ReadString(&Value1));
DC_TRY(Ctx.Reader->ReadString(&Value2));

DC_TRY(Ctx.Reader->PeekRead(&Next));
if (Next == EDcDataEntry::ArrayEnd)
{
// [<string-table-id>, <text-id>]
FText Result = FText::FromStringTable(FName(*Value1), Value2);
DC_TRY(Ctx.Writer->WriteText(Result));
DC_TRY(Ctx.Reader->ReadArrayEnd());
}
else
{
// [<namespace>, <text-id>, <source>]
FString Value3;
DC_TRY(Ctx.Reader->ReadString(&Value3));

#if UE_VERSION_OLDER_THAN(5, 5, 0)
FText Result = Value3.IsEmpty()
? FText::GetEmpty()
: FInternationalization::ForUseOnlyByLocMacroAndGraphNodeTextLiterals_CreateText(*Value3, *Value1, *Value2);
#else
FText Result = FText::AsLocalizable_Advanced(Value1, Value2, MoveTemp(Value3));
#endif // UE_VERSION_OLDER_THAN(5, 5, 0)

DC_TRY(Ctx.Writer->WriteText(Result));
DC_TRY(Ctx.Reader->ReadArrayEnd());
}

return DcOk();
}
else
{
return DC_FAIL(DcDSerDe, DataEntryMismatch2)
<< EDcDataEntry::String << EDcDataEntry::ArrayRoot << Next;
}
}

FDcResult HandlerIntPointDeserialize(FDcDeserializeContext& Ctx)
{
_DC_READ_MAP_FALLBACK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ FDcResult TDcJsonReader<CharType>::ReadText(FText* OutPtr)
if (IsAtObjectKey())
DC_TRY(CheckObjectDuplicatedKey(ParsedStr));

ReadOut(OutPtr, FText::FromString(MoveTemp(ParsedStr)));
ReadOut(OutPtr, FTextStringHelper::CreateFromBuffer(*ParsedStr));
DC_TRY(EndTopRead());
return DcOk();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ FDcResult FDcMsgPackReader::ReadText(FText* OutPtr)
DC_TRY(ReadString(&Str));

if (OutPtr)
*OutPtr = FText::FromString(Str);
*OutPtr = FTextStringHelper::CreateFromBuffer(*Str);

return DcOk();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ void DcSetupCoreTypesSerializeHandlers(FDcSerializer& Serializer)
Serializer.AddStructHandler(TBaseStructure<FDateTime>::Get(), FDcSerializeDelegate::CreateStatic(HandlerDateTimeSerialize));
Serializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("Timespan"), true), FDcSerializeDelegate::CreateStatic(HandlerTimespanSerialize));

Serializer.FieldClassSerializerMap[FTextProperty::StaticClass()] = FDcSerializeDelegate::CreateStatic(HandlerTextSerialize);

Serializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("IntPoint"), true), FDcSerializeDelegate::CreateStatic(HandlerIntPointSerialize));
Serializer.AddStructHandler(DcSerDeUtils::FindFirstObject<UScriptStruct>(TEXT("IntVector"), true), FDcSerializeDelegate::CreateStatic(HandlerIntVectorSerialize));
#if !UE_VERSION_OLDER_THAN(5, 1, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,45 @@ FDcResult HandlerTimespanSerialize(FDcSerializeContext& Ctx)
return DcOk();
}

FDcResult HandlerTextSerialize(FDcSerializeContext& Ctx)
{
FText Value;
DC_TRY(Ctx.Reader->ReadText(&Value));

if (Value.IsFromStringTable())
{
FName TableId;
FString TextKey;

verify(FTextInspector::GetTableIdAndKey(Value, TableId, TextKey));

DC_TRY(Ctx.Writer->WriteArrayRoot());

DC_TRY(Ctx.Writer->WriteString(TableId.ToString()));
DC_TRY(Ctx.Writer->WriteString(TextKey));

DC_TRY(Ctx.Writer->WriteArrayEnd());
}
else
{
DC_TRY(Ctx.Writer->WriteArrayRoot());

TOptional<FString> Namespace = FTextInspector::GetNamespace(Value);
DC_TRY(Ctx.Writer->WriteString(Namespace.IsSet() ? *Namespace : ""));

TOptional<FString> TextKey = FTextInspector::GetKey(Value);
DC_TRY(Ctx.Writer->WriteString(TextKey.IsSet() ? *TextKey : ""));

const FString* SourceString = FTextInspector::GetSourceString(Value);
DC_TRY(Ctx.Writer->WriteString(SourceString ? *SourceString : ""));

DC_TRY(Ctx.Writer->WriteArrayEnd());
}

return DcOk();
}


FDcResult HandlerIntPointSerialize(FDcSerializeContext& Ctx)
{
DcSerializeUtils::FDcScopedTryUseJSONOverrideConfig ScopedOverrideConfig(Ctx.Writer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define DATA_CONFIG_CORE_VERSION "1.7.1"
#define DATA_CONFIG_CORE_VERSION_NUMBER 10701
#define DATA_CONFIG_CORE_VERSION "1.7.2"
#define DATA_CONFIG_CORE_VERSION_NUMBER 10702
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DATACONFIGCORE_API FDcResult HandlerIntVectorDeserialize(FDcDeserializeContext&
DATACONFIGCORE_API FDcResult HandlerColorDeserialize(FDcDeserializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerDateTimeDeserialize(FDcDeserializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerTimespanDeserialize(FDcDeserializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerTextDeserialize(FDcDeserializeContext& Ctx);

#if ENGINE_MAJOR_VERSION == 5
DATACONFIGCORE_API FDcResult HandlerVector2dDeserialize(FDcDeserializeContext& Ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ DATACONFIGCORE_API FDcResult HandlerIntVectorSerialize(FDcSerializeContext& Ctx)
DATACONFIGCORE_API FDcResult HandlerColorSerialize(FDcSerializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerDateTimeSerialize(FDcSerializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerTimespanSerialize(FDcSerializeContext& Ctx);
DATACONFIGCORE_API FDcResult HandlerTextSerialize(FDcSerializeContext& Ctx);

#if ENGINE_MAJOR_VERSION == 5
DATACONFIGCORE_API FDcResult HandlerVector2dSerialize(FDcSerializeContext& Ctx);
Expand Down
33 changes: 33 additions & 0 deletions DataConfig/Source/DataConfigTests/Private/DcTestDeserialize.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "DcTestProperty2.h"
#include "DcTestProperty4.h"
#include "DcTestProperty5.h"
#include "DcTestSerDe.h"
#include "DataConfig/Json/DcJsonReader.h"
#include "DataConfig/Diagnostic/DcDiagnosticSerDe.h"
Expand Down Expand Up @@ -318,6 +319,38 @@ DC_TEST("DataConfig.Core.Deserialize.ClassRefs")
return true;
}


DC_TEST("DataConfig.Core.Deserialize.Text")
{
{
FString Str = TEXT(R"-(
{
"TextFieldAlpha" : "NSLOCTEXT(\"DataConfig.Tests\", \"BAR_TEST\", \"Localize String Bar\")",
"TextFieldBeta" : "LOCTABLE(\"/Bogus/Path/To/Table\", \"FOO_TEST\")"
}
)-");

FDcJsonReader Reader(Str);
FDcTestStructWithText Dest;

FDcTestStructWithText Expect;
Expect.MakeFixture();

UTEST_OK("Deserialize Text", DcAutomationUtils::DeserializeFrom(&Reader, FDcPropertyDatum(&Dest),
[](FDcDeserializeContext& Ctx)
{
DcSetupCoreTypesDeserializeHandlers(*Ctx.Deserializer);
}));

UTEST_OK("Deserialize Text", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Dest), FDcPropertyDatum(&Expect)));
}


return true;
}

DC_TEST("DataConfig.Core.Deserialize.Fails1")
{

Expand Down
70 changes: 70 additions & 0 deletions DataConfig/Source/DataConfigTests/Private/DcTestProperty5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
#include "DataConfig/Automation/DcAutomationUtils.h"
#include "DataConfig/Extra/Misc/DcTestCommon.h"
#include "DataConfig/Json/DcJsonReader.h"
#include "DataConfig/Diagnostic/DcDiagnosticReadWrite.h"

#include "Internationalization/StringTableRegistry.h"

void FDcTestStructWithText::MakeFixture()
{
// text test fixtures
if (!FStringTableRegistry::Get().FindStringTable("/Bogus/Path/To/Table"))
{
LOCTABLE_NEW("/Bogus/Path/To/Table", "DataConfig.Tests");
LOCTABLE_SETSTRING("/Bogus/Path/To/Table", "FOO_TEST", "Localize String Foo");
}

TextFieldAlpha = NSLOCTEXT("DataConfig.Tests", "BAR_TEST", "Localize String Bar");
TextFieldBeta = FText::FromStringTable(FName(TEXT("/Bogus/Path/To/Table")), TEXT("FOO_TEST"));
}

DC_TEST("DataConfig.Core.Property.Defaults")
{
Expand Down Expand Up @@ -41,3 +57,57 @@ DC_TEST("DataConfig.Core.Property.Defaults")

return true;
}

DC_TEST("DataConfig.Core.Property.Text")
{
FString Str = TEXT(R"-(
{
"TextFieldAlpha" : "NSLOCTEXT(\"DataConfig.Tests\", \"BAR_TEST\", \"Localize String Bar\")",
"TextFieldBeta" : "LOCTABLE(\"/Bogus/Path/To/Table\", \"FOO_TEST\")"
}
)-");


FDcJsonReader Reader(Str);
FDcTestStructWithText Dest;

FDcTestStructWithText Expect;
Expect.MakeFixture();

UTEST_OK("Deserialize Text", DcAutomationUtils::DeserializeFrom(&Reader, FDcPropertyDatum(&Dest)));
UTEST_OK("Deserialize Text", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Dest), FDcPropertyDatum(&Expect)));

return true;
}

DC_TEST("DataConfig.Core.Property.TextEqualCheck")
{
FDcTestStructWithText Foo;
FDcTestStructWithText Bar;

UTEST_OK("Text Equal Check", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Foo), FDcPropertyDatum(&Bar)));

Foo.TextFieldAlpha = NSLOCTEXT("DataConfig.Tests", "FOO_ALT", "Foo Alt");
Bar.TextFieldAlpha = NSLOCTEXT("DataConfig.Tests", "BAR_ALT", "Foo Alt");

UTEST_DIAG("Text Equal Check", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Foo), FDcPropertyDatum(&Bar)),
DcDReadWrite, DataTypeUnequalLhsRhs);

Bar.TextFieldAlpha = NSLOCTEXT("DataConfig.Tests.Alt", "FOO_ALT", "Foo Alt");

UTEST_DIAG("Text Equal Check", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Foo), FDcPropertyDatum(&Bar)),
DcDReadWrite, DataTypeUnequalLhsRhs);

Bar.TextFieldAlpha = FText();

UTEST_DIAG("Text Equal Check", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Foo), FDcPropertyDatum(&Bar)),
DcDReadWrite, DataTypeUnequalLhsRhs);

Bar.TextFieldAlpha = NSLOCTEXT("DataConfig.Tests", "FOO_ALT", "Foo Alt");

UTEST_OK("Text Equal Check", DcAutomationUtils::TestReadDatumEqual(FDcPropertyDatum(&Foo), FDcPropertyDatum(&Bar)));

return true;
}
10 changes: 10 additions & 0 deletions DataConfig/Source/DataConfigTests/Private/DcTestProperty5.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ struct FDcTestStructWithDefaults
};
};

USTRUCT()
struct FDcTestStructWithText
{
GENERATED_BODY()

UPROPERTY() FText TextFieldAlpha;
UPROPERTY() FText TextFieldBeta;

void MakeFixture();
};
Loading

0 comments on commit 283e1f9

Please sign in to comment.