50    UE_LOG(LogDlgExportTwineCommandlet, Display, TEXT(
"Starting"));
 
   55    TArray<FString> Tokens;
 
   56    TArray<FString> Switches;
 
   57    TMap<FString, FString> ParamVals;
 
   58    UCommandlet::ParseCommandLine(*Params, Tokens, Switches, ParamVals);
 
   60    if (Switches.Contains(TEXT(
"Flatten")))
 
   66    const FString* OutputDirectoryVal = ParamVals.Find(FString(TEXT(
"OutputDirectory")));
 
   67    if (OutputDirectoryVal == 
nullptr)
 
   69        UE_LOG(LogDlgExportTwineCommandlet, 
Error, TEXT(
"Did not provide argument -OutputDirectory=<Path>"));
 
   76        UE_LOG(LogDlgExportTwineCommandlet, 
Error, TEXT(
"OutputDirectory is empty, please provide a non empty one with -OutputDirectory=<Path>"));
 
   87    IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
 
   90        UE_LOG(LogDlgExportTwineCommandlet, Display, TEXT(
"Creating OutputDirectory = `%s`"), *
OutputDirectory);
 
   94    UE_LOG(LogDlgExportTwineCommandlet, Display, TEXT(
"Exporting to = `%s`"), *
OutputDirectory);
 
  100    TSet<FString> CreateFiles;
 
  106        UPackage* Package = 
Dialogue->GetOutermost();
 
  108        const FString OriginalDialoguePath = Package->GetPathName();
 
  109        FString DialoguePath = OriginalDialoguePath;
 
  114            UE_LOG(LogDlgExportTwineCommandlet, 
Warning, TEXT(
"Dialogue = `%s` is not in the game directory, ignoring"), *DialoguePath);
 
  118        verify(DialoguePath.RemoveFromStart(TEXT(
"/Game")));
 
  119        const FString FileName = FPaths::GetBaseFilename(DialoguePath);
 
  120        const FString Directory = FPaths::GetPath(DialoguePath);
 
  122        FString FileSystemFilePath;
 
  128            FString FlattenedFileName = FileName;
 
  129            int32 CurrentTryIndex = 1;
 
  130            while (CreateFiles.Contains(FlattenedFileName) && CurrentTryIndex < 100)
 
  132                FlattenedFileName = FString::Printf(TEXT(
"%s-%d"), *FileName, CurrentTryIndex);
 
  137            if (CreateFiles.Contains(FlattenedFileName))
 
  139                UE_LOG(LogDlgExportTwineCommandlet, 
Warning, TEXT(
"Dialogue = `%s` could not generate unique flattened file, ignoring"), *DialoguePath);
 
  143            CreateFiles.Add(FlattenedFileName);
 
  144            FileSystemFilePath = 
OutputDirectory / FlattenedFileName + TEXT(
".html");
 
  150            if (!PlatformFile.DirectoryExists(*FileSystemDirectoryPath) && PlatformFile.CreateDirectoryTree(*FileSystemDirectoryPath))
 
  152                UE_LOG(LogDlgExportTwineCommandlet, Display, TEXT(
"Creating directory = `%s`"), *FileSystemDirectoryPath);
 
  154            FileSystemFilePath = FileSystemDirectoryPath / FileName + TEXT(
".html");
 
  158        const TArray<UDlgNode*>& Nodes = 
Dialogue->GetNodes();
 
  168            const UDialogueGraphNode* DialogueGraphNode = Cast<UDialogueGraphNode>(Node->GetGraphNode());
 
  169            if (DialogueGraphNode == 
nullptr)
 
  181        FString PassagesData;
 
  185        for (int32 NodeIndex = 0; NodeIndex < Nodes.Num(); NodeIndex++)
 
  192        if (FFileHelper::SaveStringToFile(TwineFileContent, *FileSystemFilePath, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM))
 
  194            UE_LOG(LogDlgExportTwineCommandlet, Display, TEXT(
"Writing file = `%s` for Dialogue = `%s` "), *FileSystemFilePath, *OriginalDialoguePath);
 
  198            UE_LOG(LogDlgExportTwineCommandlet, 
Error, TEXT(
"FAILED to write file = `%s` for Dialogue = `%s`"), *FileSystemFilePath, *OriginalDialoguePath);
 
 
  278    const UDialogueGraphNode* DialogueGraphNode = Cast<UDialogueGraphNode>(Node.GetGraphNode());
 
  279    if (DialogueGraphNode == 
nullptr)
 
  281        UE_LOG(LogDlgExportTwineCommandlet, 
Warning, TEXT(
"Invalid UDialogueGraphNode for Node index = %d in Dialogue = `%s`. Ignoring."), NodeIndex, *
Dialogue.GetPathName());
 
  284    const bool bIsRootNode = DialogueGraphNode->
IsRootNode();
 
  291    TSharedPtr<SGraphNode> NodeWidget = DialogueGraphNode->
GetNodeWidget();
 
  293    if (NodeWidget.IsValid())
 
  295        Size = FIntPoint(NodeWidget->GetDesiredSize().X, NodeWidget->GetDesiredSize().Y);
 
  299    const FIntPoint Padding(20, 20);
 
  302        verify(NodeIndex == INDEX_NONE);
 
  311    verify(NodeIndex >= 0);
 
  343        NodeContent += TEXT(
"END");
 
  360        NodeContent += TEXT(
"SELECTOR\n");
 
  373        for (int32 EntryIndex = 0; EntryIndex < Sequence.Num(); EntryIndex++)
 
  376            NodeContent += FString::Printf(
 
  377                TEXT(
"``Speaker:`` //%s//\n")
 
  378                TEXT(
"``Text:`` //%s//\n")
 
  379                TEXT(
"``EdgeText:`` //%s//\n"),
 
  385            if (EntryIndex != Sequence.Num() - 1)
 
  387                NodeContent += TEXT(
"---\n");
 
  395    UE_LOG(LogDlgExportTwineCommandlet, 
Warning, TEXT(
"Node index = %d not handled in Dialogue = `%s`. Ignoring."), NodeIndex, *
Dialogue.GetPathName());
 
 
FText Text
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Node", Meta = (MultiLine = true))
FName Speaker
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Node", Meta = (DisplayName = "Partic...
FText EdgeText
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Node", Meta = (MultiLine = true))