diff --git a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs index 67f9c1dc..1d5403ff 100644 --- a/Assets/Fungus/Flowchart/Editor/BlockEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/BlockEditor.cs @@ -5,8 +5,10 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using Rotorz.ReorderableList; using System.IO; +using System.Reflection; namespace Fungus { @@ -499,41 +501,138 @@ namespace Fungus return compare; } - [MenuItem("Tools/Fungus/Utilities/Export Class Info")] - protected static void DumpFungusClassInfo() + [MenuItem("Tools/Fungus/Utilities/Export Reference Docs")] + protected static void ExportReferenceDocs() { - string path = EditorUtility.SaveFilePanel("Export strings", "", - "FungusClasses.csv", ""); - + string path = EditorUtility.SaveFolderPanel("Export Reference Docs", "", ""); if(path.Length == 0) { return; } - string classInfo = ""; + ExportCommandInfo(path); + ExportEventHandlerInfo(path); + + FlowchartWindow.ShowNotification("Exported Reference Documentation"); + } + protected static void ExportCommandInfo(string path) + { // Dump command info List menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); List> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes); filteredAttributes.Sort( CompareCommandAttributes ); + + // Build list of command categories + List commandCategories = new List(); foreach(var keyPair in filteredAttributes) { CommandInfoAttribute info = keyPair.Value; - classInfo += ("Command," + info.CommandName + "," + info.Category + ",\"" + info.HelpText + "\"\n"); + if (info.Category != "" && + !commandCategories.Contains(info.Category)) + { + commandCategories.Add (info.Category); + } + } + commandCategories.Sort(); + + // Output the commands in each category + foreach (string category in commandCategories) + { + string markdown = ""; + foreach(var keyPair in filteredAttributes) + { + CommandInfoAttribute info = keyPair.Value; + + if (info.Category == category || + info.Category == "" && category == "Scripting") + { + markdown += "## " + info.CommandName + "\n"; + markdown += info.HelpText + "\n"; + markdown += GetPropertyInfo(keyPair.Key); + } + } + + string filePath = path + "/commands/" + category + ".md"; + + Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + File.WriteAllText(filePath, markdown); } + } - // Dump event handler info + protected static void ExportEventHandlerInfo(string path) + { List eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList(); + List eventHandlerCategories = new List(); + eventHandlerCategories.Add("Core"); foreach (System.Type type in eventHandlerTypes) { EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); - classInfo += ("EventHandler," + info.EventHandlerName + "," + info.Category + ",\"" + info.HelpText + "\"\n"); + if (info.Category != "" && + !eventHandlerCategories.Contains(info.Category)) + { + eventHandlerCategories.Add(info.Category); + } + } + eventHandlerCategories.Sort(); + + // Output the commands in each category + foreach (string category in eventHandlerCategories) + { + string markdown = ""; + + foreach (System.Type type in eventHandlerTypes) + { + EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type); + + if (info.Category == category || + info.Category == "" && category == "Core") + { + markdown += "## " + info.EventHandlerName + "\n"; + markdown += info.HelpText + "\n"; + markdown += GetPropertyInfo(type); + } + } + + string filePath = path + "/event_handlers/" + category + ".md"; + + Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + File.WriteAllText(filePath, markdown); + } + } + + protected static string GetPropertyInfo(System.Type type) + { + string markdown = ""; + foreach(FieldInfo field in type.GetFields() ) + { + TooltipAttribute attribute = (TooltipAttribute)Attribute.GetCustomAttribute(field, typeof(TooltipAttribute)); + if( attribute != null ) + { + // Change field name to how it's displayed in the inspector + string propertyName = Regex.Replace(field.Name, "(\\B[A-Z])", " $1"); + if (propertyName.Length > 1) + { + propertyName = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1); + } + else + { + propertyName = propertyName.ToUpper(); + } + + markdown += propertyName + " | " + field.FieldType + " | " + attribute.tooltip + "\n"; + } + } + + if (markdown.Length > 0) + { + markdown = "\nProperty | Type | Description\n --- | --- | ---\n" + markdown + "\n"; } - File.WriteAllText(path, classInfo); + return markdown; } - void ShowCommandMenu() + protected virtual void ShowCommandMenu() { Block block = target as Block; diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs index fa042d09..f71117f7 100755 --- a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs @@ -770,5 +770,17 @@ namespace Fungus EditorUtility.SetDirty(blockInspector); } + + /** + * Displays a temporary text alert in the center of the Flowchart window. + */ + public static void ShowNotification(string notificationText) + { + EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart"); + if (window != null) + { + window.ShowNotification(new GUIContent(notificationText)); + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Narrative/Editor/LocalizationEditor.cs b/Assets/Fungus/Narrative/Editor/LocalizationEditor.cs index ffd8c456..87af5c94 100644 --- a/Assets/Fungus/Narrative/Editor/LocalizationEditor.cs +++ b/Assets/Fungus/Narrative/Editor/LocalizationEditor.cs @@ -102,12 +102,8 @@ namespace Fungus protected virtual void ShowNotification(Localization localization) { - EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart"); - if (window != null) - { - window.ShowNotification(new GUIContent(localization.notificationText)); - localization.notificationText = ""; - } + FlowchartWindow.ShowNotification(localization.notificationText); + localization.notificationText = ""; } }