public void CreateConversationGraph() { List <DialogueLine> allLines = new List <DialogueLine>(this.Elements); Dictionary <DialogueLine, DialogueLine[]> responses = new Dictionary <DialogueLine, DialogueLine[]>(); foreach (DialogueLine line in allLines) { string[] responseIds = line.Responses; List <DialogueLine> matchingResponses = allLines.FindAll(response => ArrayUtil.Contains <string>(responseIds, response.ID)); responses.Add(line, matchingResponses.ToArray()); } Dictionary <DialogueLine, GraphNode <DialogueLine> > dialogueNodes = new Dictionary <DialogueLine, GraphNode <DialogueLine> >(); foreach (DialogueLine line in responses.Keys) { dialogueNodes.Add(line, new GraphNode <DialogueLine>(line)); } foreach (DialogueLine text in responses.Keys) { foreach (DialogueLine response in responses.Keys) { if (text.Responses.Contains(response.ID)) { dialogueNodes[text].AddNeighbour(dialogueNodes[response]); } } } Conversation = new ConversationGraph(dialogueNodes.Values.ToArray()); }
public ConversationViewModel( IManagementService managementService, IEventAggregator eventAggregator) { _managementService = managementService; _eventAggregator = eventAggregator; _nodeMap = new ConcurrentDictionary<string, DiagramNode>(); Graph = new ConversationGraph(); }
private void OnEnable() { var sub = this.target; if (sub is ConversationGraph cg) { this.subject = cg; } else { Debug.LogError("Custom editor used for wrong type!"); } }
public bool TryGetConversation(string conversationID, out ConversationGraph graph) { DialogueGroup group; if (allConversations.TryGetValue(conversationID, out group)) { graph = group.Conversation; return(true); } else { graph = null; return(false); } }
public bool TryStartConversation(string conversationID) { ConversationGraph conversation; if (dialogue.TryGetConversation(conversationID, out conversation)) { currentConversation = conversation; currentLine = currentConversation.GetFirstMessage().Value; ShowLine(currentLine); return(true); } else { return(false); } }
public static void Validate(ConversationGraph graph) { var failCount = 0; //Check that all character ids are distinct var doubledIds = graph.nodes.OfType <CharacterNode>() .Select(cn => cn.id) .GroupBy(id => id) .Where(g => g.Count() > 1) .Select(e => e.Key) .ToList(); if (doubledIds.Count > 0) { failCount += 1; Debug.LogError($"Ids in characters are used double: {string.Join(", ", doubledIds)}"); } //Check that every character is connected to Collection var unconnected = graph.nodes.OfType <CharacterBaseNode>() .Where(n => n.GetOutputPort("character").Connection == null) .ToList(); var unconnCount = unconnected.Count; if (unconnCount > 0) { failCount += unconnCount; var unconnChar = unconnected.Select(n => n.character.id); Debug.LogError($"Some characternodes are not connected: {string.Join(", ", unconnChar)}"); } //Check that every Conversationnode has a previous one var noPrevCount = graph.nodes .OfType <PieceBaseNode>().Except(new [] { graph.textStart }) .Count(n => n.GetInputPort("prev").Connection == null); if (noPrevCount > 0) { failCount += noPrevCount; Debug.LogError($"There are {noPrevCount} conversation-nodes that are not reachable"); } Debug.Log(failCount > 0 ? $"Found {failCount} Error/s in ConversationGraph {graph.name}" : $"{graph.name} validated as correct" ); }
public override void OnOpen() { this.graph = this.target as ConversationGraph; }
public void EndConversation() { currentConversation = null; ui.HideDialogue(); }
public static void ValidateConversationGraph(ConversationGraph graph) { ConversationGraphEditor.Validate(graph); }