diff --git a/InkpotDemo/Plugins/Inkpot/README.md b/InkpotDemo/Plugins/Inkpot/README.md
index 40d3b72..858daa3 100644
--- a/InkpotDemo/Plugins/Inkpot/README.md
+++ b/InkpotDemo/Plugins/Inkpot/README.md
@@ -48,6 +48,10 @@ https://github.com/The-Chinese-Room/InkpotDemo
### My Ink files will not import.
+* Make sure you have **.Net framework 3.1** installed.
+Inkpot uses Inklecate to compile the Ink files and it needs .net 3.1.
+Without this the Ink files will not import.
+
* Inkpot has only been tested as an application plugin and not an engine plugin.
It needs to be located in the project's plugins folder and not the engine plugin folder.
@@ -62,7 +66,7 @@ https://github.com/The-Chinese-Room/InkpotDemo
### My Ink file changes will not update on reimport.
* Inky, the Ink script editor, will silently fail when saving to read only files.
Some version control systems will make the file read only when you check them out, eg perforce.
-This can lead to some conusion when running Inky alongside Unreal & Inkpot.
+This can lead to some confusion when running Inky alongside Unreal & Inkpot.
## Module Structure
diff --git a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/Inkpot.cpp b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/Inkpot.cpp
index 7f65b7b..08a39e0 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/Inkpot.cpp
+++ b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/Inkpot.cpp
@@ -2,6 +2,7 @@
#include "Inkpot/InkpotStories.h"
#include "Utility/InkpotLog.h"
#include "Settings/InkpotCVars.h"
+#include "Asset/InkpotStoryAsset.h"
static FDelayedAutoRegisterHelper DelayedAutoRegister(
EDelayedRegisterRunPhase::EndOfEngineInit,
@@ -47,10 +48,13 @@ void UInkpot::Register()
void UInkpot::BindPostImport()
{
#if WITH_EDITOR
- UImportSubsystem *imports = GEditor->GetEditorSubsystem();
- if(!imports)
- return;
- imports->OnAssetPostImport.AddUObject( this, &UInkpot::OnAssetPostImport );
+ if (IsValid(GEditor))
+ {
+ UImportSubsystem* imports = GEditor->GetEditorSubsystem();
+ if (!imports)
+ return;
+ imports->OnAssetPostImport.AddUObject(this, &UInkpot::OnAssetPostImport);
+ }
#endif
}
diff --git a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotChoice.cpp b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotChoice.cpp
index 18f45e8..6d252e8 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotChoice.cpp
+++ b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotChoice.cpp
@@ -8,7 +8,7 @@ UInkpotChoice::UInkpotChoice()
void UInkpotChoice::Initialise( int32 InIndex, const FString &InString)
{
- UInkpotLine::Initialise(InString);
+ UInkpotLine::Initialise( InString );
Index = InIndex;
}
diff --git a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotStory.cpp b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotStory.cpp
index aaafdba..3256724 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotStory.cpp
+++ b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Private/Inkpot/InkpotStory.cpp
@@ -7,8 +7,6 @@
#include "Ink/Path.h"
#include "Utility/InkpotLog.h"
-static const int32 dbgIndent{12};
-#define INKPOT_DBG( section, msg, ... ) INKPOT_LOG( "%- *s: " msg, dbgIndent, TEXT(section), ##__VA_ARGS__ )
void UInkpotStory::Initialise( TSharedPtr InInkpotStory )
{
@@ -383,7 +381,7 @@ void UInkpotStory::OnChoosePathStringInternal(const FString& InPath, const TArra
void UInkpotStory::DumpDebug()
{
FString currentFlow = GetCurrentFlowName();
- INKPOT_DBG("Flow", "%s", *currentFlow);
+ INKPOT_LOG("Flow : %s", *currentFlow);
if( GetAliveFlowCount() > 0 )
{
@@ -396,12 +394,12 @@ void UInkpotStory::DumpDebug()
flowsAlive.Append( flow );
flowsAlive.Append( ", " );
}
- INKPOT_DBG( "Flows alive", "%s", *flowsAlive );
+ INKPOT_LOG("Flows alive : %s", *flowsAlive );
}
}
FString currentText = GetCurrentText();
- INKPOT_DBG("Text", "%s", *currentText);
+ INKPOT_LOG("Text : %s", *currentText);
const TArray& tags = GetCurrentTags();
if( tags.Num() > 0 )
@@ -413,7 +411,7 @@ void UInkpotStory::DumpDebug()
tagsSet.Append( tag );
tagsSet.Append( "' " );
}
- INKPOT_DBG( "CTags", "%s", *tagsSet );
+ INKPOT_LOG("CTags : %s", *tagsSet);
}
TArray gtags = GlobalTags();
@@ -426,7 +424,7 @@ void UInkpotStory::DumpDebug()
tagsSet.Append( tag );
tagsSet.Append( "' " );
}
- INKPOT_DBG( "GTags", "%s", *tagsSet );
+ INKPOT_LOG("GTags : %s", *tagsSet);
}
TArray keys;
@@ -439,21 +437,21 @@ void UInkpotStory::DumpDebug()
const FString& value = obj->ToString();
if(i==0)
{
- INKPOT_DBG( "Variables", "%s = %s", *key, *value );
+ INKPOT_LOG("Variables : %s = %s", *key, *value);
}
else
{
- INKPOT_DBG( " ", "%s = %s", *key, *value );
+ INKPOT_LOG(" : %s = %s", *key, *value);
}
}
}
if(Choices.Num() > 0)
{
- INKPOT_DBG( "Choice", "%d - %s", Choices[0]->GetIndex(), *Choices[0]->GetString() );
+ INKPOT_LOG("Choice : %d - %s", Choices[0]->GetIndex(), *Choices[0]->GetString());
for( int32 i=1; iGetIndex(), *Choices[i]->GetString() );
+ INKPOT_LOG(" : %d - %s", Choices[i]->GetIndex(), *Choices[i]->GetString());
}
}
}
@@ -462,7 +460,7 @@ void UInkpotStory::DumpDebug(UInkpotChoice *InChoice)
{
if(!InChoice)
return;
- INKPOT_DBG( "Chose", "%d - %s", InChoice->GetIndex(), *InChoice->GetString() );
+ INKPOT_LOG("Chose : %d - %s", InChoice->GetIndex(), *InChoice->GetString());
}
@@ -533,6 +531,60 @@ void UInkpotStory::DumpContentAtKnot( const FString& InName )
DumpContainer(InName, knotContainer );
}
+void UInkpotStory::GatherAllStrings( TMap &OutStrings )
+{
+ TSharedPtr main = StoryInternal->GetMainContentContainer();
+ GatherAllStrings( "", main, OutStrings);
+}
+
+void UInkpotStory::GatherAllStrings( const FString &InRootName, TSharedPtr InContainer, TMap &OutStrings )
+{
+ if(!InContainer)
+ return;
+
+ FString rootName = InRootName;
+ FString containerName = InContainer->GetName();
+ if (rootName.IsEmpty())
+ rootName = containerName;
+ else if (containerName.Len() > 0)
+ rootName += TEXT(".") + containerName;
+
+ TArray> *contents = InContainer->GetContent().Get();
+ int contentIndex = 1;
+ for( TSharedPtr obj : *contents)
+ {
+ TSharedPtr container = Ink::FObject::DynamicCastTo(obj);
+ if( container )
+ {
+ GatherAllStrings( rootName, container, OutStrings );
+ }
+ else
+ {
+ if(obj->CanCastTo(Ink::EInkObjectClass::FValueString))
+ {
+ FString entry = obj->ToString();
+ entry.TrimEndInline();
+ if ( entry.Len() )
+ {
+ FString key = FString::Printf(TEXT("%s.%02d"), *rootName, contentIndex);
+ OutStrings.Add( key, entry );
+ INKPOT_LOG( "%s : %s", *key, *entry );
+ contentIndex++;
+ }
+ }
+ }
+ }
+
+ TSharedPtr>> namedContentPtr = InContainer->GetNamedContent();
+ for( auto pair : *namedContentPtr )
+ {
+ TSharedPtr container = Ink::FObject::DynamicCastTo( pair.Value );
+ if(!container)
+ continue;
+ GatherAllStrings( rootName, container, OutStrings );
+ }
+}
+
TArray UInkpotStory::GetNamedContent()
{
TSharedPtr container = StoryInternal->GetMainContentContainer();
@@ -616,6 +668,11 @@ FOnSwitchFlow& UInkpotStory::OnSwitchFlow()
return EventOnSwitchFlow;
}
+FOnStoryLoadJSON& UInkpotStory::OnStoryLoadJSON()
+{
+ return EventOnStoryLoadJSON;
+}
+
UInkpotLine *UInkpotStory::GetCurrentLine()
{
UInkpotLine* line = NewObject( this );
diff --git a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Public/Inkpot/InkpotStory.h b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Public/Inkpot/InkpotStory.h
index aa057ae..9b0d87d 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Public/Inkpot/InkpotStory.h
+++ b/InkpotDemo/Plugins/Inkpot/Source/Inkpot/Public/Inkpot/InkpotStory.h
@@ -169,7 +169,7 @@ class INKPOT_API UInkpotStory : public UObject
FOnMakeChoice& OnMakeChoice();
FOnChoosePath& OnChoosePath();
FOnSwitchFlow& OnSwitchFlow();
- FOnStoryLoadJSON OnStoryLoadJSON();
+ FOnStoryLoadJSON& OnStoryLoadJSON();
void ResetContent( TSharedPtr InNewStoryContent );
void ResetState();
@@ -182,8 +182,11 @@ class INKPOT_API UInkpotStory : public UObject
void DumpMainContent();
void DumpContentAtPath( const FString& InName );
void DumpContentAtKnot( const FString& InName );
+ void DumpContainer(const FString& InName, TSharedPtr InContainer, int Indent = 0);
-private:
+ void GatherAllStrings( TMap &OutStrings );
+
+protected:
void OnContinueInternal();
void OnMakeChoiceInternal(TSharedPtr InChoice);
void OnEvaluateFunctionInternal(const FString& InFunctionName, const TArray>& InFunctionParms);
@@ -195,11 +198,11 @@ class INKPOT_API UInkpotStory : public UObject
void DumpDebug();
void DumpDebug(UInkpotChoice *Choice);
-
- void DumpContainer( const FString& InName, TSharedPtr InContainer, int Indent = 0 );
TArray GetNamedContent( TSharedPtr Container );
+ void GatherAllStrings(const FString &InRootName, TSharedPtr InContainer, TMap& OutStrings);
+
protected:
TSharedPtr StoryInternal;
diff --git a/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Private/Asset/InkpotStoryAssetFactory.cpp b/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Private/Asset/InkpotStoryAssetFactory.cpp
index 2e1f3a1..68ce747 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Private/Asset/InkpotStoryAssetFactory.cpp
+++ b/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Private/Asset/InkpotStoryAssetFactory.cpp
@@ -4,6 +4,8 @@
#include "Compiler/InkCompiler.h"
#include "Logging/MessageLog.h"
#include "EditorFramework/AssetImportData.h"
+#include "Inkpot/Inkpot.h"
+#include "Inkpot/InkpotStory.h"
#define LOCTEXT_NAMESPACE "InkpotStoryAssetFactory"
@@ -21,20 +23,22 @@ bool UInkpotStoryAssetFactory::FactoryCanImport( const FString& Filename )
return Filename.EndsWith("ink");
}
-UObject* UInkpotStoryAssetFactory::FactoryCreateFile( UClass* InClass, UObject* InParent, FName InName, EObjectFlags InFlags, const FString& InFilename, const TCHAR* InParms, FFeedbackContext* InWarn, bool& bOutOperationCanceled )
+UObject* UInkpotStoryAssetFactory::FactoryCreateFile( UClass* InClass, UObject* InParent, FName InName, EObjectFlags InFlags, const FString& InFullFilePath, const TCHAR* InParms, FFeedbackContext* InWarn, bool& bOutOperationCanceled )
{
- const FString fileExtension = FPaths::GetExtension(InFilename);
+ const FString fileExtension = FPaths::GetExtension(InFullFilePath);
GEditor->GetEditorSubsystem()->BroadcastAssetPreImport(this, InClass, InParent, InName, *fileExtension);
UInkpotStoryAsset *newObject = nullptr;
FString inkStory;
FString inkJSON;
- if( LoadAndCompileStory( InFilename, inkStory, inkJSON ) )
+ if( LoadAndCompileStory(InFullFilePath, inkStory, inkJSON ) )
{
newObject = NewObject( InParent, InClass, InName, InFlags );
newObject->SetSource( inkStory );
newObject->SetCompiledJSON( inkJSON );
- newObject->UpdateAssetInfo( InFilename );
+ newObject->UpdateAssetInfo(InFullFilePath);
+
+ //DumpStrings(newObject);
}
if(!newObject)
@@ -45,6 +49,32 @@ UObject* UInkpotStoryAssetFactory::FactoryCreateFile( UClass* InClass, UObject*
return newObject;
}
+void UInkpotStoryAssetFactory::DumpStrings(UInkpotStoryAsset* InStoryAsset) const
+{
+ UInkpot* inkpot = GEngine->GetEngineSubsystem();
+ UInkpotStory *story = inkpot->BeginStory(InStoryAsset);
+ TMap strings;
+ story->GatherAllStrings(strings);
+
+ FString filecontent = FString::Printf(TEXT("\"Name\",\"InkText\",\"LocText\"\n"));
+
+ for (auto entry : strings)
+ {
+ const FString& key = entry.Key;
+ const FString& val = entry.Value;
+ FString line = FString::Printf(TEXT("%s,\"%s\",\"%s\"\n"), *key, *val, *val );
+ filecontent += line;
+ }
+
+ FString fullPathAndName = InStoryAsset->GetAssetImportData()->GetFirstFilename();
+ FString path = FPaths::GetPath(fullPathAndName);
+ FString inkname = FPaths::GetBaseFilename(fullPathAndName);
+ inkname += TEXT("_");
+ FString newPathAndName = FPaths::CreateTempFilename(*path, *inkname, TEXT(".csv"));
+
+ FFileHelper::SaveStringToFile( filecontent, *newPathAndName);
+}
+
bool UInkpotStoryAssetFactory::LoadAndCompileStory( const FString& InFilename, FString &OutStory, FString &OutCompiledStory) const
{
if ( !FFileHelper::LoadFileToString( OutStory, *InFilename ) )
diff --git a/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Public/Asset/InkpotStoryAssetFactory.h b/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Public/Asset/InkpotStoryAssetFactory.h
index f6ebe9b..5253bc3 100644
--- a/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Public/Asset/InkpotStoryAssetFactory.h
+++ b/InkpotDemo/Plugins/Inkpot/Source/InkpotEditor/Public/Asset/InkpotStoryAssetFactory.h
@@ -26,5 +26,6 @@ class INKPOTEDITOR_API UInkpotStoryAssetFactory : public UFactory, public FReimp
//~ End FReimportHandler Interface
private:
- bool LoadAndCompileStory( const FString& InFilename, FString &OutStory, FString &OutCompiledStory) const;
+ bool LoadAndCompileStory(const FString& InFilename, FString& OutStory, FString& OutCompiledStory) const;
+ void DumpStrings(UInkpotStoryAsset *InStoryAsset) const;
};
\ No newline at end of file