ArticyXImporter
ArticyXImporter for Unreal Engine
Loading...
Searching...
No Matches
StringTableGenerator.h
1//
2// Copyright (c) 2023 articy Software GmbH & Co. KG. All rights reserved.
3//
4
5#pragma once
6
7#include "Containers/UnrealString.h"
8#include "Misc/Paths.h"
9
19{
20public:
21
31 template<typename Lambda>
32 void SafeExecute(Lambda Lamb);
33
45 template<typename Lambda>
46 StringTableGenerator(const FString& TableName, const FString& Culture, Lambda ContentGenerator);
47
54 void Line(const FString& Key = "", const FString& SourceString = "");
55
56private:
57
59 FString Path;
60
62 FString FileContent = "";
63
69 void WriteToFile() const;
70};
71
72//---------------------------------------------------------------------------//
73//---------------------------------------------------------------------------//
74
75template<typename Lambda>
77{
78 Lamb();
79}
80
81template<>
82inline void StringTableGenerator::SafeExecute(nullptr_t Lamb)
83{
84 // Do nothing for nullptr lambdas
85}
86
87template <typename Lambda>
88StringTableGenerator::StringTableGenerator(const FString& TableName, const FString& Culture, Lambda ContentGenerator)
89{
90 const FString FilePath = TEXT("ArticyContent/Generated") / TableName;
91 if (Culture.IsEmpty())
92 {
93 Path = FPaths::ProjectContentDir() / FilePath;
94 }
95 else
96 {
97 Path = FPaths::ProjectContentDir() / TEXT("L10N") / Culture / FilePath;
98 }
99 Path += TEXT(".csv");
100
101 Line("Key", "SourceString");
102 bool bContentWritten = false;
103 if (ensure(!std::is_null_pointer<Lambda>::value))
104 bContentWritten = ContentGenerator(this) != 0;
105
106 if (bContentWritten)
107 WriteToFile();
108}
void SafeExecute(Lambda Lamb)
Executes a lambda safely.
Definition StringTableGenerator.h:76
void Line(const FString &Key="", const FString &SourceString="")
Adds a line to the content string.
Definition StringTableGenerator.cpp:13
StringTableGenerator(const FString &TableName, const FString &Culture, Lambda ContentGenerator)
Constructs a StringTableGenerator and executes a content generator lambda.
Definition StringTableGenerator.h:88