Skip to content

Commit

Permalink
allow to specify compiled json destination folder
Browse files Browse the repository at this point in the history
  • Loading branch information
gboulard committed Dec 11, 2017
1 parent 07a666a commit 0c65763
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/Ink/Editor/Compiler/InkCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public enum State {
Debug.LogWarning("Inklecate path should not contain a space. This might lead to compilation failing. Path is '"+inklecatePath+"'. If you don't see any compilation errors, you can ignore this warning.");
}*/
string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath));
string outputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json";
string outputPath = InkEditorUtils.UnityRelativeToAbsolutePath(inkFile.jsonPath);
string inkArguments = InkSettings.Instance.customInklecateOptions.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\"";

CompilationStackItem pendingFile = new CompilationStackItem();
Expand Down
32 changes: 30 additions & 2 deletions Assets/Plugins/Ink/Editor/Ink Library/InkFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public sealed class InkFile {
// A reference to the ink file
public DefaultAsset inkAsset;

//specify json destination folder (if None, default to same folder as ink file)
public DefaultAsset jsonAssetPath;

// The compiled json file. Use this to start a story.
public TextAsset jsonAsset;

Expand Down Expand Up @@ -52,14 +55,39 @@ public sealed class InkFile {
}
}

public string jsonPath {
get {
DefaultAsset jsonFolder = jsonAssetPath;
if (jsonFolder == null) // no path specified for this specific file
{
if(InkSettings.Instance.defaultJsonAssetPath != null)
{
// use default path in InkSettings
jsonFolder = InkSettings.Instance.defaultJsonAssetPath;
}

if (jsonFolder == null)
{
//fallback to same folder as .ink file
jsonFolder = AssetDatabase.LoadAssetAtPath<DefaultAsset>(Path.GetDirectoryName(filePath));
}
}

string jsonPath = AssetDatabase.GetAssetPath(jsonFolder);
string strJsonAssetPath = InkEditorUtils.CombinePaths(jsonPath, Path.GetFileNameWithoutExtension(filePath)) + ".json";

return InkEditorUtils.SanitizePathString(strJsonAssetPath);
}
}

public InkFile (DefaultAsset inkAsset) {
Debug.Assert(inkAsset != null);
this.inkAsset = inkAsset;
}

public void FindCompiledJSONAsset () {
string jsonAssetPath = InkEditorUtils.CombinePaths(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)) + ".json";
jsonAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(jsonAssetPath);
Debug.Assert(inkAsset != null);
jsonAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(jsonPath);
}

public override string ToString () {
Expand Down
4 changes: 3 additions & 1 deletion Assets/Plugins/Ink/Editor/Ink Settings/InkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class InkSettings : ScriptableObject {
}
}

public bool compileAutomatically = true;
public DefaultAsset defaultJsonAssetPath;

public bool compileAutomatically = true;
public bool delayInPlayMode = true;
public bool handleJSONFilesAutomatically = true;

Expand Down
4 changes: 3 additions & 1 deletion Assets/Plugins/Ink/Editor/Ink Settings/InkSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public class InkSettingsEditor : Editor {
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("templateFile"));

data.compileAutomatically = EditorGUILayout.Toggle(new GUIContent("Compile Ink Automatically", "When disabled, automatic compilation can be enabled on a per-story basis via the inspector for a master story file."), data.compileAutomatically);
EditorGUILayout.PropertyField(serializedObject.FindProperty("defaultJsonAssetPath"));

data.compileAutomatically = EditorGUILayout.Toggle(new GUIContent("Compile Ink Automatically", "When disabled, automatic compilation can be enabled on a per-story basis via the inspector for a master story file."), data.compileAutomatically);
data.delayInPlayMode = EditorGUILayout.Toggle(new GUIContent("Delay compilation if in Play Mode", "When enabled, ink compilation is delayed if in play mode."), data.delayInPlayMode);

data.handleJSONFilesAutomatically = EditorGUILayout.Toggle(new GUIContent("Handle JSON Automatically", "Whether JSON files are moved, renamed and deleted along with their ink files."), data.handleJSONFilesAutomatically);
Expand Down

0 comments on commit 0c65763

Please sign in to comment.