Exemple #1
0
        // When all files in stack have been compiled. This is called via update because Process events run in another thread.
        private static void DelayedComplete()
        {
            if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0)
            {
                Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning.");
                return;
            }

            float         longestTimeTaken = 0;
            bool          errorsFound      = false;
            StringBuilder filesCompiledLog = new StringBuilder("Files compiled:");

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                longestTimeTaken = Mathf.Max(compilingFile.timeTaken);
                filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath);
                if (compilingFile.errorOutput.Count > 0)
                {
                    filesCompiledLog.Append(" (With unhandled error)");
                    StringBuilder errorLog = new StringBuilder();
                    errorLog.Append("Unhandled error(s) occurred compiling Ink file ");
                    errorLog.Append("'");
                    errorLog.Append(compilingFile.inkFile.filePath);
                    errorLog.Append("'");
                    errorLog.AppendLine("! Please report following error(s) as a bug:");
                    foreach (var error in compilingFile.errorOutput)
                    {
                        errorLog.AppendLine(error);
                    }
                    Debug.LogError(errorLog);
                    compilingFile.inkFile.metaInfo.compileErrors = compilingFile.errorOutput;
                    errorsFound = true;
                }
                else
                {
                    SetOutputLog(compilingFile);
                    bool errorsInEntireStory   = false;
                    bool warningsInEntireStory = false;
                    foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy)
                    {
                        if (inkFile.metaInfo.hasErrors)
                        {
                            errorsInEntireStory = true;
                        }

                        if (inkFile.metaInfo.hasWarnings)
                        {
                            warningsInEntireStory = true;
                        }
                    }

                    if (errorsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With error)");
                        errorsFound = true;
                    }
                    else
                    {
                        string localJSONAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(compilingFile.jsonAbsoluteFilePath);
                        AssetDatabase.ImportAsset(localJSONAssetPath);
                        compilingFile.inkFile.jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(localJSONAssetPath);
                    }

                    if (warningsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With warning)");
                    }
                }
            }

            if (longestTimeTaken > InkSettings.Instance.compileTimeout * 0.6f)
            {
                Debug.LogWarning(
                    "Compilation took over 60% of the time required to timeout the compiler. Consider increasing the compile timeout on the InkSettings file.");
            }

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                if (OnCompileInk != null)
                {
                    OnCompileInk(compilingFile.inkFile);
                }
            }

            StringBuilder outputLog = new StringBuilder();

            if (errorsFound)
            {
                outputLog.Append("Ink compilation completed with errors at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.LogWarning(outputLog);
            }
            else
            {
                outputLog.Append("Ink compilation completed at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.Log(outputLog);
            }

            InkLibrary.Instance.compilationStack.Clear();
            InkLibrary.Save();
            InkMetaLibrary.Save();

#if !UNITY_EDITOR_LINUX
            EditorUtility.ClearProgressBar();
#endif
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                Debug.LogWarning("Ink just finished recompiling while in play mode. Your runtime story may not be up to date.");
            }

            if (playModeBlocked)
            {
                if (!errorsFound)
                {
                    // Delaying gives the editor a frame to clear the progress bar.
                    EditorApplication.delayCall += () =>
                    {
                        Debug.Log("Compilation completed, entering play mode.");
                        EditorApplication.isPlaying = true;
                    };
                }
                else
                {
                    Debug.LogWarning("Play mode not entered after ink compilation because ink had errors.");
                }
            }
        }
Exemple #2
0
        // When all files in stack have been compiled. This is called via update because Process events run in another thread.
        private static void DelayedComplete()
        {
            if (InkLibrary.NumFilesInCompilingStackInState(CompilationStackItem.State.Compiling) > 0)
            {
                Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning.");
                return;
            }
            bool          errorsFound      = false;
            StringBuilder filesCompiledLog = new StringBuilder("Files compiled:");

            // Create and import compiled files
            AssetDatabase.StartAssetEditing();
            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                // Complete status is also set when an error occured, in these cases 'compiledJson' will be null so there's no import to process
                if (compilingFile.compiledJson == null)
                {
                    continue;
                }

                // Write new compiled data to the file system
                File.WriteAllText(compilingFile.jsonAbsoluteFilePath, compilingFile.compiledJson, Encoding.UTF8);
                AssetDatabase.ImportAsset(compilingFile.inkFile.jsonPath);
            }
            AssetDatabase.StopAssetEditing();

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                // Load and store a reference to the compiled file
                compilingFile.inkFile.FindCompiledJSONAsset();

                filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath);
                filesCompiledLog.Append(string.Format(" ({0}s)", compilingFile.timeTaken));
                if (compilingFile.unhandledErrorOutput.Count > 0)
                {
                    filesCompiledLog.Append(" (With unhandled error)");
                    StringBuilder errorLog = new StringBuilder();
                    errorLog.Append("Unhandled error(s) occurred compiling Ink file ");
                    errorLog.Append("'");
                    errorLog.Append(compilingFile.inkFile.filePath);
                    errorLog.Append("'");
                    errorLog.AppendLine("! Please report following error(s) as a bug:");
                    foreach (var error in compilingFile.unhandledErrorOutput)
                    {
                        errorLog.AppendLine(error);
                    }
                    Debug.LogError(errorLog);
                    compilingFile.inkFile.metaInfo.unhandledCompileErrors = compilingFile.unhandledErrorOutput;
                    errorsFound = true;
                }
                else
                {
                    SetOutputLog(compilingFile);
                    bool errorsInEntireStory   = false;
                    bool warningsInEntireStory = false;
                    foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy)
                    {
                        if (inkFile.metaInfo.hasErrors)
                        {
                            errorsInEntireStory = true;
                        }
                        if (inkFile.metaInfo.hasWarnings)
                        {
                            warningsInEntireStory = true;
                        }
                    }
                    if (errorsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With error)");
                        errorsFound = true;
                    }
                    if (warningsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With warning)");
                    }
                }
            }


            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                if (OnCompileInk != null)
                {
                    OnCompileInk(compilingFile.inkFile);
                }
            }

            StringBuilder outputLog = new StringBuilder();

            if (errorsFound)
            {
                outputLog.Append("Ink compilation completed with errors at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.LogError(outputLog);
            }
            else
            {
                outputLog.Append("Ink compilation completed at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.Log(outputLog);
            }

            InkLibrary.Instance.compilationStack.Clear();
            InkLibrary.SaveToFile();
            InkMetaLibrary.Save();

                        #if !UNITY_EDITOR_LINUX
            EditorUtility.ClearProgressBar();
                        #endif

                        #if UNITY_2019_4_OR_NEWER
            if (InkLibrary.Instance.disallowedAutoRefresh)
            {
                InkLibrary.Instance.disallowedAutoRefresh = false;
                InkLibrary.SaveToFile();
                try {
                    AssetDatabase.AllowAutoRefresh();
                } catch (Exception e) {
                    Debug.LogWarning("Failed AllowAutoRefresh " + e);
                }
            }
                        #endif

            // This is now allowed, if compiled manually. I've left this code commented out because at some point we might want to track what caused a file to compile.
            // if(EditorApplication.isPlayingOrWillChangePlaymode && InkSettings.Instance.delayInPlayMode) {
            //  Debug.LogError("Ink just finished recompiling while in play mode. This should never happen when InkSettings.Instance.delayInPlayMode is true!");
            // }

            buildBlocked = false;

            if (playModeBlocked)
            {
                playModeBlocked = false;
                if (!errorsFound)
                {
                    // Delaying gives the editor a frame to clear the progress bar.
                    EditorApplication.delayCall += () => {
                        Debug.Log("Compilation completed, entering play mode.");
                        EditorApplication.isPlaying = true;
                    };
                }
                else
                {
                    Debug.LogWarning("Play mode not entered after ink compilation because ink had errors.");
                }
            }

            foreach (var onCompleteAction in onCompleteActions)
            {
                if (onCompleteAction != null)
                {
                    onCompleteAction();
                }
            }
            onCompleteActions.Clear();
        }
        /// <summary>
        /// Rebuilds which files are master files and the connections between the files.
        /// </summary>
        public static void RebuildInkFileConnections()
        {
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                inkFile.metaInfo.parent         = null;
                inkFile.metaInfo.masterInkAsset = null;
                inkFile.metaInfo.ParseContent();
                inkFile.metaInfo.FindIncludedFiles();
            }
            // We now set the master file for ink files. As a file can be in an include hierarchy, we need to do this in two passes.
            // First, we set the master file to the file that includes an ink file.
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                if (inkFile.metaInfo.includes.Count == 0)
                {
                    continue;
                }
                foreach (InkFile otherInkFile in InkLibrary.Instance.inkLibrary)
                {
                    if (inkFile == otherInkFile)
                    {
                        continue;
                    }
                    if (inkFile.metaInfo.includes.Contains(otherInkFile.inkAsset))
                    {
                        otherInkFile.metaInfo.parent = inkFile.inkAsset;
                    }
                }
            }
            // Next, we create a list of all the files owned by the actual master file, which we obtain by travelling up the parent tree from each file.
            Dictionary <InkFile, List <InkFile> > masterChildRelationships = new Dictionary <InkFile, List <InkFile> >();

            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                if (inkFile.metaInfo.parent == null)
                {
                    continue;
                }
                InkFile parent = inkFile.metaInfo.parentInkFile;
                while (parent.metaInfo.parent != null)
                {
                    parent = parent.metaInfo.parentInkFile;
                }
                if (!masterChildRelationships.ContainsKey(parent))
                {
                    masterChildRelationships.Add(parent, new List <InkFile>());
                }
                masterChildRelationships[parent].Add(inkFile);
            }
            // Finally, we set the master file of the children
            foreach (var inkFileRelationship in masterChildRelationships)
            {
                foreach (InkFile childInkFile in inkFileRelationship.Value)
                {
                    childInkFile.metaInfo.masterInkAsset = inkFileRelationship.Key.inkAsset;
                    if (InkSettings.Instance.handleJSONFilesAutomatically && childInkFile.jsonAsset != null)
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(childInkFile.jsonAsset));
                        childInkFile.jsonAsset = null;
                    }
                }
            }
            InkMetaLibrary.Save();
        }
Exemple #4
0
        /// <summary>
        /// Rebuilds which files are master files and the connections between the files.
        /// </summary>
        public static void RebuildInkFileConnections()
        {
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                inkFile.metaInfo.parents         = new List <DefaultAsset>();
                inkFile.metaInfo.masterInkAssets = new List <DefaultAsset>();
                inkFile.metaInfo.ParseContent();
                inkFile.metaInfo.FindIncludedFiles();
            }
            // We now set the master file for ink files. As a file can be in an include hierarchy, we need to do this in two passes.
            // First, we set the master file to the file that includes an ink file.
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                if (inkFile.metaInfo.includes.Count == 0)
                {
                    continue;
                }
                foreach (InkFile otherInkFile in InkLibrary.Instance.inkLibrary)
                {
                    if (inkFile == otherInkFile)
                    {
                        continue;
                    }
                    if (inkFile.metaInfo.includes.Contains(otherInkFile.inkAsset))
                    {
                        if (!otherInkFile.metaInfo.parents.Contains(inkFile.inkAsset))
                        {
                            otherInkFile.metaInfo.parents.Add(inkFile.inkAsset);
                        }
                    }
                }
            }
            // Next, we create a list of all the files owned by the actual master file, which we obtain by travelling up the parent tree from each file.
            Dictionary <InkFile, List <InkFile> > masterChildRelationships = new Dictionary <InkFile, List <InkFile> >();

            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                foreach (var parentInkFile in inkFile.metaInfo.parentInkFiles)
                {
                    InkFile lastMasterInkFile = parentInkFile;
                    InkFile masterInkFile     = parentInkFile;
                    while (masterInkFile.metaInfo.parents.Count != 0)
                    {
                        // This shouldn't just pick first, but iterate the whole lot!
                        // I didn't feel like writing a recursive algorithm until it's actually needed though - a file included by several parents is already a rare enough case!
                        masterInkFile     = masterInkFile.metaInfo.parentInkFiles.First();
                        lastMasterInkFile = masterInkFile;
                    }
                    if (lastMasterInkFile.metaInfo.parents.Count > 1)
                    {
                        Debug.LogError("The ink ownership tree has another master file that is not discovered! This is an oversight of the current implementation. If you requres this feature, please take a look at the comment in the code above - if you solve it let us know and we'll merge it in!");
                    }
                    if (!masterChildRelationships.ContainsKey(masterInkFile))
                    {
                        masterChildRelationships.Add(masterInkFile, new List <InkFile>());
                    }
                    masterChildRelationships[masterInkFile].Add(inkFile);
                }

                // if(inkFile.metaInfo.parent == null)
                //  continue;
                // InkFile parent = inkFile.metaInfo.parentInkFile;
                // while (parent.metaInfo.parent != null) {
                //  parent = parent.metaInfo.parentInkFile;
                // }
                // if(!masterChildRelationships.ContainsKey(parent)) {
                //  masterChildRelationships.Add(parent, new List<InkFile>());
                // }
                // masterChildRelationships[parent].Add(inkFile);
            }
            // Finally, we set the master file of the children
            foreach (var inkFileRelationship in masterChildRelationships)
            {
                foreach (InkFile childInkFile in inkFileRelationship.Value)
                {
                    if (!childInkFile.metaInfo.masterInkAssets.Contains(inkFileRelationship.Key.inkAsset))
                    {
                        childInkFile.metaInfo.masterInkAssets.Add(inkFileRelationship.Key.inkAsset);
                    }
                    else
                    {
                        Debug.LogWarning("Child file already contained master file reference! This is weird!");
                    }
                    if (InkSettings.Instance.handleJSONFilesAutomatically && childInkFile.jsonAsset != null)
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(childInkFile.jsonAsset));
                        childInkFile.jsonAsset = null;
                    }
                }
            }
            InkMetaLibrary.Save();
        }
Exemple #5
0
        private static void Delay()
        {
            if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0)
            {
                Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning.");
                return;
            }
            bool   errorsFound = false;
            string listOfFiles = "\nFiles compiled:";

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                listOfFiles += "\n";
                listOfFiles += compilingFile.inkFile.filePath;
                if (compilingFile.errorOutput != "")
                {
                    listOfFiles += " (With unhandled error)";
                    Debug.LogError("Unhandled error occurred compiling Ink file " + compilingFile.inkFile + "! Please report following error as a bug:\n" + compilingFile.errorOutput);
                    compilingFile.inkFile.metaInfo.compileErrors.Clear();
                    compilingFile.inkFile.metaInfo.compileErrors.Add(compilingFile.errorOutput);
                    errorsFound = true;
                }
                else
                {
                    SetOutputLog(compilingFile);
                    bool errorsInEntireStory   = false;
                    bool warningsInEntireStory = false;
                    foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy)
                    {
                        if (inkFile.metaInfo.hasErrors)
                        {
                            errorsInEntireStory = true;
                        }
                        if (inkFile.metaInfo.hasWarnings)
                        {
                            warningsInEntireStory = true;
                        }
                    }
                    if (errorsInEntireStory)
                    {
                        listOfFiles += " (With error)";
                        errorsFound  = true;
                    }
                    else
                    {
                        string localJSONAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(compilingFile.jsonAbsoluteFilePath);
                        AssetDatabase.ImportAsset(localJSONAssetPath);
                        compilingFile.inkFile.jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset> (localJSONAssetPath);
                    }
                    if (warningsInEntireStory)
                    {
                        listOfFiles += " (With warning)";
                    }
                }
            }

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                if (OnCompileInk != null)
                {
                    OnCompileInk(compilingFile.inkFile);
                }
            }

            if (errorsFound)
            {
                Debug.LogWarning("Ink compilation completed with errors at " + DateTime.Now.ToLongTimeString() + listOfFiles);
            }
            else
            {
                Debug.Log("Ink compilation completed at " + DateTime.Now.ToLongTimeString() + listOfFiles);
            }
            InkLibrary.Instance.compilationStack.Clear();

            InkLibrary.Save();
            InkMetaLibrary.Save();

            EditorUtility.ClearProgressBar();
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                Debug.LogWarning("Ink just finished recompiling while in play mode. Your runtime story may not be up to date.");
            }
        }
Exemple #6
0
        // When all files in stack have been compiled. This is called via update because Process events run in another thread.
        private static void DelayedComplete()
        {
            if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0)
            {
                Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning.");
                return;
            }
            float         longestTimeTaken = 0;
            bool          errorsFound      = false;
            StringBuilder filesCompiledLog = new StringBuilder("Files compiled:");

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                // Complete status is also set when an error occured, in these cases 'compiledJson' will be null so there's no import to process
                if (compilingFile.compiledJson != null)
                {
                    // Write new compiled data to the file system
                    File.WriteAllText(compilingFile.jsonAbsoluteFilePath, compilingFile.compiledJson, Encoding.UTF8);
                    AssetDatabase.ImportAsset(compilingFile.jsonAbsoluteFilePath);
                    var jsonObject = AssetDatabase.LoadAssetAtPath <TextAsset>(compilingFile.inkFile.jsonPath);

                    // Update the jsonAsset reference
                    compilingFile.inkFile.jsonAsset = jsonObject;
                }

                longestTimeTaken = Mathf.Max(compilingFile.timeTaken);
                filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath);
                filesCompiledLog.Append(string.Format(" ({0}s)", compilingFile.timeTaken));
                if (compilingFile.errorOutput.Count > 0)
                {
                    filesCompiledLog.Append(" (With unhandled error)");
                    StringBuilder errorLog = new StringBuilder();
                    errorLog.Append("Unhandled error(s) occurred compiling Ink file ");
                    errorLog.Append("'");
                    errorLog.Append(compilingFile.inkFile.filePath);
                    errorLog.Append("'");
                    errorLog.AppendLine("! Please report following error(s) as a bug:");
                    foreach (var error in compilingFile.errorOutput)
                    {
                        errorLog.AppendLine(error);
                    }
                    Debug.LogError(errorLog);
                    compilingFile.inkFile.metaInfo.compileErrors = compilingFile.errorOutput;
                    errorsFound = true;
                }
                else
                {
                    SetOutputLog(compilingFile);
                    bool errorsInEntireStory   = false;
                    bool warningsInEntireStory = false;
                    foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy)
                    {
                        if (inkFile.metaInfo.hasErrors)
                        {
                            errorsInEntireStory = true;
                        }
                        if (inkFile.metaInfo.hasWarnings)
                        {
                            warningsInEntireStory = true;
                        }
                    }
                    if (errorsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With error)");
                        errorsFound = true;
                    }
                    if (warningsInEntireStory)
                    {
                        filesCompiledLog.Append(" (With warning)");
                    }
                }
            }

            if (longestTimeTaken > InkSettings.Instance.compileTimeout * 0.6f)
            {
                Debug.LogWarning("Compilation took over 60% of the time required to timeout the compiler. Consider increasing the compile timeout on the InkSettings file.");
            }

            foreach (var compilingFile in InkLibrary.Instance.compilationStack)
            {
                if (OnCompileInk != null)
                {
                    OnCompileInk(compilingFile.inkFile);
                }
            }

            StringBuilder outputLog = new StringBuilder();

            if (errorsFound)
            {
                outputLog.Append("Ink compilation completed with errors at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.LogError(outputLog);
            }
            else
            {
                outputLog.Append("Ink compilation completed at ");
                outputLog.AppendLine(DateTime.Now.ToLongTimeString());
                outputLog.Append(filesCompiledLog.ToString());
                Debug.Log(outputLog);
            }

            InkLibrary.Instance.compilationStack.Clear();
            InkLibrary.Save();
            InkMetaLibrary.Save();

                        #if !UNITY_EDITOR_LINUX
            EditorUtility.ClearProgressBar();
                        #endif
            if (EditorApplication.isPlayingOrWillChangePlaymode && InkSettings.Instance.delayInPlayMode)
            {
                Debug.LogError("Ink just finished recompiling while in play mode. This should never happen when InkSettings.Instance.delayInPlayMode is true!");
            }

            buildBlocked = false;

            if (playModeBlocked)
            {
                playModeBlocked = false;
                if (!errorsFound)
                {
                    // Delaying gives the editor a frame to clear the progress bar.
                    EditorApplication.delayCall += () => {
                        Debug.Log("Compilation completed, entering play mode.");
                        EditorApplication.isPlaying = true;
                    };
                }
                else
                {
                    Debug.LogWarning("Play mode not entered after ink compilation because ink had errors.");
                }
            }
        }