A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgStatsCommandlet.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2
4#include "DlgManager.h"
5#include "DlgDialogue.h"
9#include "DlgHelper.h"
10
11
12DEFINE_LOG_CATEGORY(LogDlgStatsCommandlet);
13
14
16{
17 IsClient = false;
18 IsEditor = true;
19 IsServer = false;
20 LogToConsole = false;
21 ShowErrorCount = false;
22}
23
24int32 UDlgStatsCommandlet::Main(const FString& Params)
25{
26 UE_LOG(LogDlgStatsCommandlet, Display, TEXT("Starting"));
27
28 // Parse command line - we're interested in the param vals
29 TArray<FString> Tokens;
30 TArray<FString> Switches;
31 TMap<FString, FString> ParamVals;
32 UCommandlet::ParseCommandLine(*Params, Tokens, Switches, ParamVals);
33
35 const TArray<UDlgDialogue*> AllDialogues = UDlgManager::GetAllDialoguesFromMemory();
36
37 FDlgStatsDialogue TotalStats;
38 for (const UDlgDialogue* Dialogue : AllDialogues)
39 {
40 UPackage* Package = Dialogue->GetOutermost();
41 check(Package);
42 const FString OriginalDialoguePath = Package->GetPathName();
43
44 // Only count game dialogues
45 if (!FDlgHelper::IsPathInProjectDirectory(OriginalDialoguePath))
46 {
47 UE_LOG(LogDlgStatsCommandlet, Warning, TEXT("Dialogue = `%s` is not in the game directory, ignoring"), *OriginalDialoguePath);
48 continue;
49 }
50
51 FDlgStatsDialogue DialogueStats;
52 GetStatsForDialogue(*Dialogue, DialogueStats);
53 TotalStats += DialogueStats;
54 UE_LOG(LogDlgStatsCommandlet, Display, TEXT("Dialogue = %s. Total Text Word count = %d"), *OriginalDialoguePath, DialogueStats.WordCount);
55 }
56
57 UE_LOG(LogDlgStatsCommandlet, Display,
58 LINE_TERMINATOR TEXT("Stats:") LINE_TERMINATOR
59 TEXT("Total Text Word Count = %d"),
60 TotalStats.WordCount);
61
62 return 0;
63}
64
65
67{
68 // Root
69 OutStats.WordCount += GetNodeWordCount(Dialogue.GetStartNode());
70
71 // Nodes
72 const TArray<UDlgNode*>& Nodes = Dialogue.GetNodes();
73 for (int32 NodeIndex = 0; NodeIndex < Nodes.Num(); NodeIndex++)
74 {
75 OutStats.WordCount += GetNodeWordCount(*Nodes[NodeIndex]);
76 }
77
78 return true;
79}
80
82{
83 const UDlgNode* NodePtr = &Node;
84 int32 WordCount = 0;
85
86 if (const UDlgNode_Speech* NodeSpeech = Cast<UDlgNode_Speech>(NodePtr))
87 {
88 WordCount += GetTextWordCount(NodeSpeech->GetNodeUnformattedText());
89 }
90 else if (const UDlgNode_SpeechSequence* NodeSpeechSequence = Cast<UDlgNode_SpeechSequence>(NodePtr))
91 {
92 // Speech Sequence
93 for (const FDlgSpeechSequenceEntry& Entry : NodeSpeechSequence->GetNodeSpeechSequence())
94 {
95 WordCount += GetTextWordCount(Entry.Text);
96 }
97 }
98 else
99 {
100 // not supported
101 }
102
103 // Edges
104 for (const FDlgEdge& Edge : Node.GetNodeChildren())
105 {
106 WordCount += GetTextWordCount(Edge.GetUnformattedText());
107 }
108
109 return WordCount;
110}
111
113{
114 TArray<FString> Out;
115 String.ParseIntoArray(Out, TEXT(" "), true);
116 return Out.Num();
117}
DEFINE_LOG_CATEGORY(LogDlgStatsCommandlet)
static FORCEINLINE bool IsPathInProjectDirectory(const FString &Path)
Definition DlgHelper.h:224
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
static int32 LoadAllDialoguesIntoMemory(bool bAsync=false)
static TArray< UDlgDialogue * > GetAllDialoguesFromMemory()
UCLASS(BlueprintType, ClassGroup = "Dialogue")
UCLASS(BlueprintType, ClassGroup = "Dialogue")
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
virtual const TArray< FDlgEdge > & GetNodeChildren() const
Gets this nodes children (edges) as a const/mutable array.
Definition DlgNode.h:184
int32 GetTextWordCount(const FText &Text) const
int32 GetStringWordCount(const FString &String) const
int32 Main(const FString &Params) override
int32 GetNodeWordCount(const UDlgNode &Node) const
bool GetStatsForDialogue(const UDlgDialogue &Dialogue, FDlgStatsDialogue &OutStats)
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
USTRUCT(BlueprintType)