Skip to content

Commit

Permalink
feat(spell check): evaluate all nodes at the dialogue level
Browse files Browse the repository at this point in the history
  • Loading branch information
ashblue committed Feb 15, 2020
1 parent bcbcb0d commit 4d3c779
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,34 @@ private void OnEnable () {

public override void OnInspectorGUI () {
base.OnInspectorGUI();
SpellCheckText();

_conditions.Update();
_enterActions?.Update();
_exitActions?.Update();

SpellCheckText();
}

private void SpellCheckText () {
if ((_dialogue != null || _choices != null) && GUILayout.Button("Spell Check")) {
SpellCheck.Instance.ClearValidation();
} else {
return;
}
if (_dialogue == null && _choices == null) return;
if (!GUILayout.Button("Spell Check")) return;

ShowValidation(target as NodeDataBase);
}

public static void ShowValidation (NodeDataBase target) {
var serializedObject = new SerializedObject(target);
var dialogue = serializedObject.FindProperty("dialogue");
var choices = serializedObject.FindProperty("choices");

SpellCheck.Instance.ClearValidation();

if (_dialogue != null) {
SpellCheck.Instance.AddValidation(_dialogue.displayName, _dialogue.stringValue);
if (dialogue != null) {
SpellCheck.Instance.AddValidation(dialogue.displayName, dialogue.stringValue);
}

if (_choices != null) {
for (var i = 0; i < _choices.arraySize; i++) {
var choice = _choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData;
if (choices != null) {
for (var i = 0; i < choices.arraySize; i++) {
var choice = choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData;
SpellCheck.Instance.AddValidation($"Choice {i}", choice.text);
}
}
Expand Down

0 comments on commit 4d3c779

Please sign in to comment.