-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spell check): evaluate all nodes at the dialogue level
- Loading branch information
Showing
2 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Assets/com.fluid.dialogue/Editor/Inspectors/DialogueGraphInspector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,68 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Choices; | ||
using CleverCrow.Fluid.Dialogues.Graphs; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using CleverCrow.Fluid.SimpleSpellcheck; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
[CustomEditor(typeof(DialogueGraph))] | ||
public class DialogueGraphInspector : Editor { | ||
private SerializedProperty _nodes; | ||
|
||
private void OnEnable () { | ||
_nodes = serializedObject.FindProperty("_nodes"); | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
DrawDefaultInspector(); | ||
|
||
if (GUILayout.Button("Spell Check")) { | ||
RunSpellCheck(); | ||
} | ||
|
||
if (GUILayout.Button("Edit Dialogue")) { | ||
DialogueWindow.ShowGraph(target as DialogueGraph); | ||
} | ||
} | ||
|
||
private void RunSpellCheck () { | ||
var logList = new List<LogEntry>(); | ||
|
||
for (var i = 0; i < _nodes.arraySize; i++) { | ||
var node = new SerializedObject(_nodes.GetArrayElementAtIndex(i).objectReferenceValue); | ||
CreateLog(node, logList); | ||
} | ||
|
||
SpellCheck.Instance.ShowLogs($"Dialogue: {target.name}", logList); | ||
} | ||
|
||
private void CreateLog (SerializedObject node, List<LogEntry> logList) { | ||
var textProp = node.FindProperty("dialogue"); | ||
var choiceProp = node.FindProperty("choices"); | ||
|
||
if (textProp == null && choiceProp == null) return; | ||
|
||
var textIsInvalid = textProp != null && SpellCheck.Instance.IsInvalid(textProp.stringValue); | ||
|
||
var choiceIsInvalid = false; | ||
if (choiceProp != null) { | ||
for (var j = 0; j < choiceProp.arraySize; j++) { | ||
var choice = choiceProp.GetArrayElementAtIndex(j).objectReferenceValue as ChoiceData; | ||
choiceIsInvalid = SpellCheck.Instance.IsInvalid(choice.text); | ||
if (choiceIsInvalid) break; | ||
} | ||
} | ||
|
||
if (textIsInvalid || choiceIsInvalid) { | ||
var log = new LogEntry(textProp.stringValue, () => { | ||
NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase); | ||
Selection.activeObject = node.targetObject; | ||
}); | ||
|
||
logList.Add(log); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters