private DialogueEntry CreateDialogueEntry(ParsedDialogueEntry node, int conversationID, int conversantID) { if (template == null) { LoadTemplate(); } DialogueEntry newEntry = template.CreateDialogueEntry(node.id, conversationID, ""); newEntry.ActorID = database.GetActor(node.actorName).id; newEntry.DialogueText = node.dialogueText; newEntry.ConversantID = conversantID; newEntry.Sequence = node.sequence; newEntry.MenuText = node.menuText; newEntry.conditionsString = node.conditions; Field.SetValue(newEntry.fields, "Description", node.description); if (!string.IsNullOrEmpty(node.responseMenuSequence)) { //newEntry.ResponseMenuSequence = node.responseMenuSequence; newEntry.fields.Add(new Field("Response Menu Sequence", node.responseMenuSequence, FieldType.Text)); } return(newEntry); }
ParsedDialogueEntry ParseEntry(StringReader reader, int nodeID) { ParsedDialogueEntry node = null; string actor = ParseActorName(reader); string dialogueText = ParseDialogueText(reader); string sequence = ParseSequence(reader); string conditions = ParseConditions(reader); if (!string.IsNullOrEmpty(actor)) { node = new ParsedDialogueEntry(nodeID, actor, dialogueText, sequence, conditions); } return(node); }
public List <ParsedConversation> ParseConversations(string conversationString, ActorAliases abbreviationList) { parsedConversations.Clear(); aliases = abbreviationList; currentConversation = null; try { StringReader documentReader = new StringReader(conversationString); string line; documentRow = 1; lastNodeID = 0; depthLevel = 0; mainBranch = new Branch("Main", 0, 0); bool tieUpLooseEnds = false; string comment = string.Empty; while ((line = documentReader.ReadLine()) != null) { documentRow++; documentColumn = 1; if (IsNullOrWhiteSpace(line)) { continue; } line.Trim(); StringReader lineReader = new StringReader(line); ParseWhitespace(lineReader); if (IsStartOfNewConversation(lineReader)) { int conversationID = ParseConversationID(lineReader); string conversationTitle = ParseConversationTitle(lineReader); currentConversation = new ParsedConversation(conversationID, conversationTitle); parsedConversations.Add(currentConversation); lastNodeID = 0; if (!string.IsNullOrEmpty(comment)) { currentConversation.description = comment; comment = string.Empty; } continue; } if (isCommenting || IsComment(lineReader, line)) { comment += ParseComment(lineReader); if (isCommenting) { comment += "\n"; //retain new line for multi-line comments } //if(lastNodeID == 0) currentConversation.description += comment; //else currentConversation.nodes[currentConversation.NodeCount-1].description += comment; continue; } if (IsSequence(lineReader)) // this is a sequence for the last node that was moved to a new line in the document { string sequence = ParseSequence(lineReader); currentConversation.nodes[currentConversation.NodeCount - 1].sequence = sequence; continue; } if (IsBranchName(lineReader)) { string branchName = ParseBranchName(lineReader); Branch currentBranch = mainBranch.GetActiveBranch(); if (branchName == currentBranch.name) //End of active branch { currentBranch.complete = true; lastNodeID = currentBranch.startNode; tieUpLooseEnds = true; depthLevel--; } else { depthLevel++; Branch b = new Branch(branchName, lastNodeID, depthLevel); currentBranch.children.Add(b); menuText = branchName; if (currentBranch.children.Count == 1) { //Check for response menu sequence string responseMenuSequence = ParseSequence(lineReader); currentConversation.nodes[currentConversation.NodeCount - 1].responseMenuSequence = responseMenuSequence; } tieUpLooseEnds = false; } } else { //PROCESS DIALOGUE ENTRY if (currentConversation == null) { throw new ParserException("No conversation ID/Title found."); } int nodeID = currentConversation.NodeCount + 1; ParsedDialogueEntry node = ParseEntry(lineReader, nodeID); if (node != null) { currentConversation.nodes.Add(node); if (tieUpLooseEnds) { ReconnectBranch(mainBranch, nodeID); if (depthLevel <= 0) { mainBranch.children.Clear(); } tieUpLooseEnds = false; } else { currentConversation.AddLink(lastNodeID, nodeID); if (!string.IsNullOrEmpty(menuText)) { node.menuText = menuText; menuText = string.Empty; } } Branch currentBranch = mainBranch.GetActiveBranch(); currentBranch.endNodeID = nodeID; lastNodeID = nodeID; if (!string.IsNullOrEmpty(comment)) { node.description = comment; comment = string.Empty; } } } } foreach (Branch b in mainBranch.children) { foreach (Branch branch in b.children) { if (!branch.complete) { throw new ParserException("No end tag found for Branch: \"" + branch.name + "\""); } } } foreach (ParsedConversation c in parsedConversations) { c.AutoFillActorNames(); } } catch (ParserException e) { Debug.LogWarning("Syntax error " + e.Message + "at line " + documentRow + ", " + documentColumn); parsedConversations.Clear(); } return(parsedConversations); }