Skip to content

Commit 4d3c779

Browse files
committed
feat(spell check): evaluate all nodes at the dialogue level
1 parent bcbcb0d commit 4d3c779

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,68 @@
1+
using System.Collections.Generic;
2+
using CleverCrow.Fluid.Dialogues.Choices;
13
using CleverCrow.Fluid.Dialogues.Graphs;
4+
using CleverCrow.Fluid.Dialogues.Nodes;
5+
using CleverCrow.Fluid.SimpleSpellcheck;
26
using UnityEditor;
37
using UnityEngine;
48

59
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors {
610
[CustomEditor(typeof(DialogueGraph))]
711
public class DialogueGraphInspector : Editor {
12+
private SerializedProperty _nodes;
13+
14+
private void OnEnable () {
15+
_nodes = serializedObject.FindProperty("_nodes");
16+
}
17+
818
public override void OnInspectorGUI () {
919
DrawDefaultInspector();
1020

21+
if (GUILayout.Button("Spell Check")) {
22+
RunSpellCheck();
23+
}
24+
1125
if (GUILayout.Button("Edit Dialogue")) {
1226
DialogueWindow.ShowGraph(target as DialogueGraph);
1327
}
1428
}
29+
30+
private void RunSpellCheck () {
31+
var logList = new List<LogEntry>();
32+
33+
for (var i = 0; i < _nodes.arraySize; i++) {
34+
var node = new SerializedObject(_nodes.GetArrayElementAtIndex(i).objectReferenceValue);
35+
CreateLog(node, logList);
36+
}
37+
38+
SpellCheck.Instance.ShowLogs($"Dialogue: {target.name}", logList);
39+
}
40+
41+
private void CreateLog (SerializedObject node, List<LogEntry> logList) {
42+
var textProp = node.FindProperty("dialogue");
43+
var choiceProp = node.FindProperty("choices");
44+
45+
if (textProp == null && choiceProp == null) return;
46+
47+
var textIsInvalid = textProp != null && SpellCheck.Instance.IsInvalid(textProp.stringValue);
48+
49+
var choiceIsInvalid = false;
50+
if (choiceProp != null) {
51+
for (var j = 0; j < choiceProp.arraySize; j++) {
52+
var choice = choiceProp.GetArrayElementAtIndex(j).objectReferenceValue as ChoiceData;
53+
choiceIsInvalid = SpellCheck.Instance.IsInvalid(choice.text);
54+
if (choiceIsInvalid) break;
55+
}
56+
}
57+
58+
if (textIsInvalid || choiceIsInvalid) {
59+
var log = new LogEntry(textProp.stringValue, () => {
60+
NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase);
61+
Selection.activeObject = node.targetObject;
62+
});
63+
64+
logList.Add(log);
65+
}
66+
}
1567
}
1668
}

Assets/com.fluid.dialogue/Editor/Inspectors/NodeDataBase/NodeDataBaseEditor.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,34 @@ private void OnEnable () {
2929

3030
public override void OnInspectorGUI () {
3131
base.OnInspectorGUI();
32+
SpellCheckText();
3233

3334
_conditions.Update();
3435
_enterActions?.Update();
3536
_exitActions?.Update();
36-
37-
SpellCheckText();
3837
}
3938

4039
private void SpellCheckText () {
41-
if ((_dialogue != null || _choices != null) && GUILayout.Button("Spell Check")) {
42-
SpellCheck.Instance.ClearValidation();
43-
} else {
44-
return;
45-
}
40+
if (_dialogue == null && _choices == null) return;
41+
if (!GUILayout.Button("Spell Check")) return;
42+
43+
ShowValidation(target as NodeDataBase);
44+
}
45+
46+
public static void ShowValidation (NodeDataBase target) {
47+
var serializedObject = new SerializedObject(target);
48+
var dialogue = serializedObject.FindProperty("dialogue");
49+
var choices = serializedObject.FindProperty("choices");
50+
51+
SpellCheck.Instance.ClearValidation();
4652

47-
if (_dialogue != null) {
48-
SpellCheck.Instance.AddValidation(_dialogue.displayName, _dialogue.stringValue);
53+
if (dialogue != null) {
54+
SpellCheck.Instance.AddValidation(dialogue.displayName, dialogue.stringValue);
4955
}
5056

51-
if (_choices != null) {
52-
for (var i = 0; i < _choices.arraySize; i++) {
53-
var choice = _choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData;
57+
if (choices != null) {
58+
for (var i = 0; i < choices.arraySize; i++) {
59+
var choice = choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData;
5460
SpellCheck.Instance.AddValidation($"Choice {i}", choice.text);
5561
}
5662
}

0 commit comments

Comments
 (0)