Skip to content

Commit

Permalink
[C] Replace Guid with GUID
Browse files Browse the repository at this point in the history
  • Loading branch information
vampy committed Jul 14, 2020
1 parent 1905d61 commit b48561f
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 82 deletions.
4 changes: 2 additions & 2 deletions Source/DlgSystem/Private/DlgDialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void UDlgDialogue::PostInitProperties()

// Used when creating new Dialogues
// Initialize with a valid GUID
if (DialogueVersion >= FDlgDialogueObjectVersion::AddGuid && !GUID.IsValid())
if (DialogueVersion >= FDlgDialogueObjectVersion::AddGUID && !GUID.IsValid())
{
RegenerateGUID();
FDlgLogger::Get().Debugf(
Expand Down Expand Up @@ -433,7 +433,7 @@ void UDlgDialogue::ImportFromFileFormat(EDlgDialogueTextFormat TextFormat)

// TODO(vampy): validate if data is legit, indicies exist and that sort.
// Check if Guid is not a duplicate
const TArray<UDlgDialogue*> DuplicateDialogues = UDlgManager::GetDialoguesWithDuplicateGuid();
const TArray<UDlgDialogue*> DuplicateDialogues = UDlgManager::GetDialoguesWithDuplicateGUIDs();
if (DuplicateDialogues.Num() > 0)
{
if (DuplicateDialogues.Contains(this))
Expand Down
12 changes: 6 additions & 6 deletions Source/DlgSystem/Private/DlgManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,19 @@ TArray<UObject*> UDlgManager::GetAllObjectsWithDialogueParticipantInterface(UObj
return Array;
}

TArray<UDlgDialogue*> UDlgManager::GetDialoguesWithDuplicateGuid()
TArray<UDlgDialogue*> UDlgManager::GetDialoguesWithDuplicateGUIDs()
{
TArray<UDlgDialogue*> Dialogues = GetAllDialoguesFromMemory();
TArray<UDlgDialogue*> DuplicateDialogues;

TSet<FGuid> DialogueGuids;
TSet<FGuid> DialogueGUIDs;
for (UDlgDialogue* Dialogue : Dialogues)
{
const FGuid ID = Dialogue->GetDialogueGUID();
if (DialogueGuids.Find(ID) == nullptr)
if (DialogueGUIDs.Find(ID) == nullptr)
{
// does not exist, good
DialogueGuids.Add(ID);
DialogueGUIDs.Add(ID);
}
else
{
Expand All @@ -295,7 +295,7 @@ TArray<UDlgDialogue*> UDlgManager::GetDialoguesWithDuplicateGuid()
return DuplicateDialogues;
}

TMap<FGuid, UDlgDialogue*> UDlgManager::GetAllDialoguesGuidMap()
TMap<FGuid, UDlgDialogue*> UDlgManager::GetAllDialoguesGUIDsMap()
{
TArray<UDlgDialogue*> Dialogues = GetAllDialoguesFromMemory();
TMap<FGuid, UDlgDialogue*> DialoguesMap;
Expand All @@ -306,7 +306,7 @@ TMap<FGuid, UDlgDialogue*> UDlgManager::GetAllDialoguesGuidMap()
if (DialoguesMap.Contains(ID))
{
FDlgLogger::Get().Errorf(
TEXT("GetAllDialoguesGuidMap - ID = `%s` for Dialogue = `%s` already exists"),
TEXT("GetAllDialoguesGUIDsMap - ID = `%s` for Dialogue = `%s` already exists"),
*ID.ToString(), *Dialogue->GetPathName()
);
}
Expand Down
6 changes: 0 additions & 6 deletions Source/DlgSystem/Private/DlgMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "DlgMemory.h"
#include "DlgHelper.h"


bool FDlgHistory::operator==(const FDlgHistory& Other) const
{
return FDlgHelper::IsSetEqual(VisitedNodeIndices, Other.VisitedNodeIndices);
Expand Down Expand Up @@ -45,8 +44,3 @@ bool FDlgMemory::IsNodeVisited(const FGuid& DialogueGUID, int32 NodeIndex) const
const int32* FoundIndex = History->VisitedNodeIndices.Find(NodeIndex);
return FoundIndex != nullptr;
}

void FDlgMemory::Serialize(FArchive& Ar)
{
Ar << HistoryMap;
}
8 changes: 4 additions & 4 deletions Source/DlgSystem/Private/Tests/DlgIOTesterTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void FDlgTestStructPrimitives::GenerateRandomData(const FDlgIOTesterOptions& InO
Rotator = FRotator(FMath::SRand(), FMath::SRand(), FMath::SRand());
Matrix = FMatrix(Vector3, FVector(IntPoint), FVector(Vector4), Vector3);
Transform = FTransform(Vector3);
Guid = FGuid::NewGuid();
GUID = FGuid::NewGuid();

const TArray<UClass*> ClassesPool = {
UField::StaticClass(), UStruct::StaticClass(), nullptr, UObject::StaticClass(),
Expand Down Expand Up @@ -355,10 +355,10 @@ bool FDlgTestStructPrimitives::IsEqual(const Self& Other, FString& OutError) con
OutError += FString::Printf(TEXT("\tThis.Transform (%s) != Other.Transform (%s)\n"), *Transform.ToString(), *Other.Transform.ToString());
}

if (Guid != Other.Guid)
if (GUID != Other.GUID)
{
bIsEqual = false;
OutError += FString::Printf(TEXT("\tThis.Guid (%s) != Other.Guid (%s)\n"), *Guid.ToString(), *Other.Guid.ToString());
OutError += FString::Printf(TEXT("\tThis.Guid (%s) != Other.Guid (%s)\n"), *GUID.ToString(), *Other.GUID.ToString());
}

if (Class != Other.Class)
Expand Down Expand Up @@ -456,7 +456,7 @@ void FDlgTestStructPrimitives::SetToDefaults()
Rotator = FRotator(ForceInitToZero);
Matrix = FMatrix(ForceInitToZero);
Transform = FTransform();
Guid = FGuid();
GUID = FGuid();
Class = nullptr;
EmptyObjectInitialized = nullptr;
EmptyObjectInitializedReference = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/DlgSystem/Public/DlgDialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct DLGSYSTEM_API FDlgDialogueObjectVersion
UseOnlyOneOutputAndInputPin,
MergeVirtualParentAndSelectorTypes,
ConvertDialogueDataArraysToSets,
AddGuid,
AddGUID,
AddComparisonWithOtherParticipant,
AddTextFormatArguments,
AddLocalizationOverwrittenNamespacesAndKeys,
Expand Down
4 changes: 2 additions & 2 deletions Source/DlgSystem/Public/DlgManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ class DLGSYSTEM_API UDlgManager : public UBlueprintFunctionLibrary
static TArray<UObject*> GetAllObjectsWithDialogueParticipantInterface(UObject* WorldContextObject);

// Gets all the dialogues that have a duplicate GUID, should not happen, like ever.
static TArray<UDlgDialogue*> GetDialoguesWithDuplicateGuid();
static TArray<UDlgDialogue*> GetDialoguesWithDuplicateGUIDs();

// Helper methods that gets all the dialogues in a map by guid.
static TMap<FGuid, UDlgDialogue*> GetAllDialoguesGuidMap();
static TMap<FGuid, UDlgDialogue*> GetAllDialoguesGUIDsMap();

// Gets all the loaded dialogues from memory that have the ParticipantName included inside them.
static TArray<UDlgDialogue*> GetAllDialoguesForParticipantName(FName ParticipantName);
Expand Down
17 changes: 11 additions & 6 deletions Source/DlgSystem/Public/DlgMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ struct DLGSYSTEM_API FDlgHistory

// Singleton to store Dialogue history
// TODO: investigate if this is multiplayer friendly, it does not seem so as there exists only a single global dialogue memory
class DLGSYSTEM_API FDlgMemory
USTRUCT()
struct DLGSYSTEM_API FDlgMemory
{
GENERATED_USTRUCT_BODY()
public:
static FDlgMemory* GetInstance()
{
Expand Down Expand Up @@ -56,12 +58,15 @@ class DLGSYSTEM_API FDlgMemory
private:
// Key: Dialogue unique identifier Guid
// Value: set of already visited nodes
UPROPERTY()
TMap<FGuid, FDlgHistory> HistoryMap;
};

// operator overloads for serialization
FORCEINLINE FArchive& operator<<(FArchive &Ar, FDlgHistory& History)
template<>
struct TStructOpsTypeTraits<FDlgHistory> : public TStructOpsTypeTraitsBase2<FDlgHistory>
{
Ar << History.VisitedNodeIndices;
return Ar;
}
enum
{
WithIdenticalViaEquality = true
};
};
4 changes: 2 additions & 2 deletions Source/DlgSystem/Public/Tests/DlgIOTesterTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct DLGSYSTEM_API FDlgTestStructPrimitives
KeyHash = HashCombine(KeyHash, GetTypeHash(This.Color));
KeyHash = HashCombine(KeyHash, GetTypeHash(This.DateTime));
KeyHash = HashCombine(KeyHash, GetTypeHash(This.IntPoint));
KeyHash = HashCombine(KeyHash, GetTypeHash(This.Guid));
KeyHash = HashCombine(KeyHash, GetTypeHash(This.GUID));
KeyHash = HashCombine(KeyHash, GetTypeHash(This.Texture2DReference));
return KeyHash;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ struct DLGSYSTEM_API FDlgTestStructPrimitives
FTransform Transform;

UPROPERTY()
FGuid Guid;
FGuid GUID;

UPROPERTY()
UClass* Class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int32 UDlgExportTwineCommandlet::Main(const FString& Params)
}


FString UDlgExportTwineCommandlet::CreateTwineStoryData(const FString& Name, const FGuid& DialogueGuid, int32 StartNodeIndex, const FString& PassagesData)
FString UDlgExportTwineCommandlet::CreateTwineStoryData(const FString& Name, const FGuid& DialogueGUID, int32 StartNodeIndex, const FString& PassagesData)
{
static const FString Creator = TEXT("UE-NotYetDlgSystem");
static const FString CreatorVersion = TEXT("5.0"); // TODO
Expand All @@ -222,13 +222,13 @@ FString UDlgExportTwineCommandlet::CreateTwineStoryData(const FString& Name, con
// tags colors data
TEXT("\n%s\n")
// Special tag to identify the dialogue id
//TEXT("<tw-passagedata pid=\"-1\" tags=\"\" name=\"DialogueGuid\" position=\"0,0\" size=\"10,10\">%s</tw-passagedata>\n")
//TEXT("<tw-passagedata pid=\"-1\" tags=\"\" name=\"DialogueGUID\" position=\"0,0\" size=\"10,10\">%s</tw-passagedata>\n")

TEXT("%s\n")

TEXT("</tw-storydata>"),
*Name, StartNodeIndex + 2, *Creator, *CreatorVersion,
*DialogueGuid.ToString(EGuidFormats::DigitsWithHyphens), Zoom, *Format, *FormatVersion,
*DialogueGUID.ToString(EGuidFormats::DigitsWithHyphens), Zoom, *Format, *FormatVersion,
*CreateTwineCustomCss(),
*CreateTwineTagColorsData(),
*PassagesData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int32 UDlgHumanReadableTextCommandlet::Import()
UE_LOG(LogDlgHumanReadableTextCommandlet, Display, TEXT("Importing from = `%s`"), *OutputInputDirectory);

PackagesToSave.Empty();
TMap<FGuid, UDlgDialogue*> DialoguesMap = UDlgManager::GetAllDialoguesGuidMap();
TMap<FGuid, UDlgDialogue*> DialoguesMap = UDlgManager::GetAllDialoguesGUIDsMap();
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();

// Find all files
Expand Down Expand Up @@ -201,13 +201,13 @@ int32 UDlgHumanReadableTextCommandlet::Import()


// Find Dialogue
UDlgDialogue** DialoguePtr = DialoguesMap.Find(HumanFormat.DialogueGuid);
UDlgDialogue** DialoguePtr = DialoguesMap.Find(HumanFormat.DialogueGUID);
if (DialoguePtr == nullptr)
{
UE_LOG(LogDlgHumanReadableTextCommandlet,
Error,
TEXT("Can't find Dialogue for GUID = `%s`, DialogueName = `%s` from File = `%s`"),
*HumanFormat.DialogueGuid.ToString(), *HumanFormat.DialogueName.ToString(), *File);
*HumanFormat.DialogueGUID.ToString(), *HumanFormat.DialogueName.ToString(), *File);
continue;
}

Expand All @@ -225,7 +225,7 @@ int32 UDlgHumanReadableTextCommandlet::Import()
bool UDlgHumanReadableTextCommandlet::ExportDialogueToHumanReadableFormat(const UDlgDialogue& Dialogue, FDlgDialogue_FormatHumanReadable& OutFormat)
{
OutFormat.DialogueName = Dialogue.GetDialogueFName();
OutFormat.DialogueGuid = Dialogue.GetDialogueGUID();
OutFormat.DialogueGUID = Dialogue.GetDialogueGUID();

// Root Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct FDlgDialogue_FormatHumanReadable
FName DialogueName;

UPROPERTY()
FGuid DialogueGuid;
FGuid DialogueGUID;

UPROPERTY()
TArray<FDlgNodeSpeech_FormatHumanReadable> SpeechNodes;
Expand Down Expand Up @@ -187,7 +187,7 @@ class UDlgHumanReadableTextCommandlet : public UCommandlet

TArray<UPackage*> PackagesToSave;
const UDlgSystemSettings* Settings = nullptr;

bool bSaveAllDialogues = false;
bool bExport = false;
bool bImport = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ class FDialogueBrowserTreeVariableProperties : public FDlgTreeViewVariableProper
void AddDialogue(TWeakObjectPtr<const UDlgDialogue> Dialogue) override;

// GraphNodes:
bool HasGraphNodeSet(const FGuid& DialogueGuid) { return GraphNodes.Find(DialogueGuid) != nullptr; }
TSet<TWeakObjectPtr<const UDialogueGraphNode>>* GetMutableGraphNodeSet(const FGuid& DialogueGuid)
bool HasGraphNodeSet(const FGuid& DialogueGUID) { return GraphNodes.Find(DialogueGUID) != nullptr; }
TSet<TWeakObjectPtr<const UDialogueGraphNode>>* GetMutableGraphNodeSet(const FGuid& DialogueGUID)
{
return GraphNodes.Find(DialogueGuid);
return GraphNodes.Find(DialogueGUID);
}
const TSet<TWeakObjectPtr<const UDialogueGraphNode>>& GetGraphNodeSet(const FGuid& DialogueGuid) const
const TSet<TWeakObjectPtr<const UDialogueGraphNode>>& GetGraphNodeSet(const FGuid& DialogueGUID) const
{
auto* SetPtr = GraphNodes.Find(DialogueGuid);
auto* SetPtr = GraphNodes.Find(DialogueGUID);
check(SetPtr);
return *SetPtr;
}

// EdgeNodes:
bool HasEdgeNodeSet(const FGuid& DialogueGuid) { return EdgeNodes.Find(DialogueGuid) != nullptr; }
TSet<TWeakObjectPtr<const UDialogueGraphNode_Edge>>* GetMutableEdgeNodeSet(const FGuid& DialogueGuid)
bool HasEdgeNodeSet(const FGuid& DialogueGUID) { return EdgeNodes.Find(DialogueGUID) != nullptr; }
TSet<TWeakObjectPtr<const UDialogueGraphNode_Edge>>* GetMutableEdgeNodeSet(const FGuid& DialogueGUID)
{
return EdgeNodes.Find(DialogueGuid);
return EdgeNodes.Find(DialogueGUID);
}
const TSet<TWeakObjectPtr<const UDialogueGraphNode_Edge>>& GetEdgeNodeSet(const FGuid& DialogueGuid) const
const TSet<TWeakObjectPtr<const UDialogueGraphNode_Edge>>& GetEdgeNodeSet(const FGuid& DialogueGUID) const
{
auto* SetPtr = EdgeNodes.Find(DialogueGuid);
auto* SetPtr = EdgeNodes.Find(DialogueGUID);
check(SetPtr);
return *SetPtr;
}
Expand Down
Loading

0 comments on commit b48561f

Please sign in to comment.