/// <summary> /// Obtain the text from current node in the story. /// Then create a response using the current node and return it. /// Finally, transition to the next node in the story. /// </summary> /// <returns></returns> public SkillResponse ProcessRequest() { Speech speech = new Speech(); speech.Elements.Add(new Sentence(CurrentNode.Text)); SkillResponse response = ResponseBuilder.Tell(speech); Dictionary <string, object> sessionAttributes = RequestContext.Session.Attributes ?? new Dictionary <string, object>(); SpeechNode nextNode = CurrentNode.GetNextNode(); string nextNodeName = nextNode != null ? nextNode.Name : ""; response.Response.ShouldEndSession = nextNode == null; if (!sessionAttributes.ContainsKey(CurrentNodeKey)) { // Add the name of the next node to update our progression through the story sessionAttributes.Add(CurrentNodeKey, nextNodeName); } else { // Update the name of the next node to update our progression through the story sessionAttributes[CurrentNodeKey] = nextNodeName; } response.SessionAttributes = sessionAttributes; return(response); }
private void __ProcessSpeechNodeSet(IDNodeBase _node) { SpeechNode node = (SpeechNode)_node; m_textbox.SetSpeakerName(node.SpeakerName); m_textbox.SetText(node.Text); }
public void ProcessRequest_CurrentNodeKeyDoesExistInSessionAttributes_SetsNextNodeName() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); SpeechNode speechNode2 = story.CreateNode("Test2"); speechNode.CreateTransition(speechNode2); Assert.IsNotNull(speechNode.GetNextNode()); SkillRequest request = new SkillRequest(); request.Request = new IntentRequest(); request.Session = new Session(); request.Session.Attributes = new Dictionary <string, object>() { { StoryRuntime.CurrentNodeKey, "Test" } }; RequestContext requestContext = new RequestContext(request, null, null); StoryRuntime storyRuntime = new StoryRuntime(requestContext, story); storyRuntime.TrySetCurrentNode(0); Assert.IsTrue(request.Session.Attributes.ContainsKey(StoryRuntime.CurrentNodeKey)); Assert.AreEqual("Test", request.Session.Attributes[StoryRuntime.CurrentNodeKey]); SkillResponse response = storyRuntime.ProcessRequest(); Assert.IsNotNull(response.SessionAttributes); Assert.AreSame(request.Session.Attributes, response.SessionAttributes); Assert.IsTrue(response.SessionAttributes.ContainsKey(StoryRuntime.CurrentNodeKey)); Assert.AreEqual("Test2", response.SessionAttributes[StoryRuntime.CurrentNodeKey]); }
public void AddNode_ReturnsInputtedNode() { Story story = new Story(); SpeechNode speechNode = new SpeechNode(); Assert.AreSame(speechNode, story.AddNode(speechNode)); }
public void InputtingNonNullTwineStory_SetsUpTransitionsCorrectly() { TwineStory twineStory = new TwineStory(); TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); twineSpeechNode.Name = "TestName"; twineStory.Nodes.Add(twineSpeechNode); TwineSpeechNode twineSpeechNode2 = new TwineSpeechNode(); twineSpeechNode2.Name = "TestName2"; twineStory.Nodes.Add(twineSpeechNode2); TwineLink twineLink = new TwineLink("Link", "Text|TestName2"); twineSpeechNode.TwineLinks.Add(twineLink); Story story = Story.Load(twineStory); Assert.IsNotNull(story); Assert.AreEqual(2, story.NodeCount); SpeechNode speechNode = story.GetNodeAt(0); Assert.AreEqual(1, speechNode.TransitionCount); Transition transition = speechNode.GetTransitionAt(0); Assert.AreSame(speechNode, transition.Source); Assert.AreSame(story.GetNodeAt(1), transition.Destination); }
public void Save_Overwrite_FileExists_OverwritesFileCorrectly_ReturnsTrue() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); SpeechNode speechNode2 = story.CreateNode("Test2"); speechNode.CreateTransition(speechNode2); string filePath = Path.Combine(Resources.TempDir, "Test.data"); File.WriteAllText(filePath, "Test"); FileAssert.FileExists(filePath); Assert.IsTrue(story.Save(filePath, true)); FileAssert.FileExists(filePath); Story loadedStory = Story.Load(filePath); Assert.IsNotNull(loadedStory); Assert.AreEqual(2, loadedStory.NodeCount); Assert.IsNotNull(loadedStory.FindNode("Test")); Assert.IsNotNull(loadedStory.FindNode("Test2")); Assert.AreEqual(1, loadedStory.FindNode("Test").TransitionCount); Assert.AreSame(loadedStory.FindNode("Test"), loadedStory.FindNode("Test").GetTransitionAt(0).Source); Assert.AreSame(loadedStory.FindNode("Test2"), loadedStory.FindNode("Test").GetTransitionAt(0).Destination); }
public void InputtingExistentValidFile_SetsUpNodesCorrectly() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("TestNode"); speechNode.Text = "Test Text"; speechNode.Tags.Add("Tag1"); string filePath = Path.Combine(Resources.TempDir, "Test.txt"); SaveStoryBinary(story, filePath); FileAssert.FileExists(filePath); Story loadedStory = Story.Load(filePath); Assert.IsNotNull(loadedStory); Assert.AreEqual(1, loadedStory.NodeCount); SpeechNode loadedNode = loadedStory.GetNodeAt(0); Assert.IsNotNull(loadedNode); Assert.AreEqual("TestNode", loadedNode.Name); Assert.AreEqual("Test Text", loadedNode.Text); Assert.AreEqual(1, loadedNode.Tags.Count); Assert.AreEqual("Tag1", loadedNode.Tags[0]); Assert.AreEqual(0, loadedNode.TransitionCount); Assert.AreSame(loadedStory, loadedNode.ParentStory); }
public void ConditionPasses_WithCurrentRuntimeSetToSameIntent_ReturnsTrue() { SkillRequest request = new SkillRequest(); request.Request = new IntentRequest() { Intent = new Intent() { Name = "Test" } }; RequestContext requestContext = new RequestContext(request, null, null); StoryRuntime runtime = new StoryRuntime(requestContext); Story story = new Story(); story.Runtime = runtime; SpeechNode speechNode = story.CreateNode("TestNode"); Transition transition = speechNode.CreateTransition(new SpeechNode()); IntentCondition intentCondition = transition.CreateCondition <IntentCondition>(); intentCondition.IntentName = "Test"; Assert.IsTrue(intentCondition.ConditionPasses()); }
public void Constructor_TwineSpeechNode_SetsParentStory_ToNull() { TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); SpeechNode speechNode = new SpeechNode(twineSpeechNode); Assert.IsNull(speechNode.ParentStory); }
public void GetNextNode_NoTransitions_ReturnsNull() { SpeechNode speechNode = new SpeechNode(); Assert.AreEqual(0, speechNode.TransitionCount); Assert.IsNull(speechNode.GetNextNode()); }
/// <summary> /// Create node UIs for all the nodes in the story when we set it for the Story Editor. /// </summary> protected override void OnTargetObjectChanged() { base.OnTargetObjectChanged(); Network.Nodes.Clear(); Dictionary <SpeechNode, NodeViewModel> nodeLookup = new Dictionary <SpeechNode, NodeViewModel>(); Story story = TargetObject as Story; for (int i = 0; i < story.NodeCount; ++i) { SpeechNode node = story.GetNodeAt((uint)i); NodeViewModel nodeViewModel = CreateNodeViewModel(node); nodeLookup.Add(node, nodeViewModel); } for (int node_index = 0; node_index < story.NodeCount; ++node_index) { SpeechNode node = story.GetNodeAt((uint)node_index); NodeViewModel nodeViewModel = nodeLookup[node]; foreach (Transition transition in node) { Network.Connections.Add(new ConnectionViewModel(Network, nodeLookup[transition.Destination].Inputs[0], nodeViewModel.Outputs[0])); } } }
public void GetTransitionAt_InputtingOutOfBoundsIndex_ReturnsNull() { SpeechNode speechNode = new SpeechNode(); Assert.AreEqual(0, speechNode.TransitionCount); Assert.IsNull(speechNode.GetTransitionAt(1)); }
public void Constructor_SetsDestinationNode_ToInputtedValue() { SpeechNode destinationNode = new SpeechNode(); Transition transition = new Transition(new SpeechNode(), destinationNode); Assert.AreSame(destinationNode, transition.Destination); }
public void CreateNode_String_SetsNodeParentStory_ToStory() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); Assert.AreSame(story, speechNode.ParentStory); }
public void Constructor_SetsSourceNode_ToInputtedValue() { SpeechNode speechNode = new SpeechNode(); Transition transition = new Transition(speechNode, new SpeechNode()); Assert.AreSame(speechNode, transition.Source); }
/* Reads data in from a text file. */ void Init(string fileName) { nodes = new List <SpeechNode>(); active = null; try{ string path = Application.dataPath + "/Resources/Speech/" + fileName + ".txt"; if (!File.Exists(path)) { MonoBehaviour.print("File doesn't exist at " + path); return; } using (StreamReader sr = new StreamReader(path)){ string line = sr.ReadLine(); lineCount = 1; while (line != null && line.ToUpper() != "END") { if (line.ToUpper() == "NODE") { SpeechNode sn = ParseNode(sr); if (sn == null) { MonoBehaviour.print("Node null"); return; } nodes.Add(sn); } line = sr.ReadLine(); lineCount++; } } }catch (Exception e) { MonoBehaviour.print("Exception: " + e); } MonoBehaviour.print(ToString()); if (nodes.Count > 0) { active = nodes[0]; } }
public void CreateNode_TwineSpeechNode_ReturnsCreatedNode() { TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); Story story = new Story(); SpeechNode speechNode = story.CreateNode(twineSpeechNode); Assert.AreSame(speechNode, story.GetNodeAt(0)); }
public void GetTransitionAt_InputtingInBoundsIndex_ReturnsCorrectTransition() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); Assert.AreSame(transition, speechNode.GetTransitionAt(0)); }
public void CreateTransition_InputtingNullDestinationNode_ReturnsNull() { SpeechNode speechNode = new SpeechNode(); Assert.AreEqual(0, speechNode.TransitionCount); Assert.IsNull(speechNode.CreateTransition(null)); Assert.AreEqual(0, speechNode.TransitionCount); }
public void FindNode_InputtingExistentName_ReturnsCorrectNode() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("TestNode"); Assert.AreEqual(1, story.NodeCount); Assert.AreSame(speechNode, story.FindNode("TestNode")); }
/* Changes the active node, if the selection is valid. */ void ChangeActive(int node) { if (node < 0 || node >= nodes.Count) { return; } active = nodes[node]; }
public void CreateNode_String_ReturnsCreatedNode() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); Assert.AreEqual(1, story.NodeCount); Assert.AreSame(speechNode, story.GetNodeAt(0)); }
public void GetNodeAt_InputtingValidIndex_ReturnsCorrectNode() { Story story = new Story(); SpeechNode speechNode = story.CreateNode("Test"); Assert.AreEqual(1, story.NodeCount); Assert.AreSame(speechNode, story.GetNodeAt(0)); }
public void CreateTransition_ReturnsCreatedTransition() { SpeechNode speechNode = new SpeechNode(); SpeechNode destinationNode = new SpeechNode(); Transition transition = speechNode.CreateTransition(destinationNode); Assert.AreSame(transition, speechNode.GetTransitionAt(0)); }
/// <summary> /// Creates a new SpeechNode and adds it to this story. /// </summary> /// <param name="twineSpeechNode"></param> /// <returns></returns> public SpeechNode CreateNode(string nodeName) { SpeechNode speechNode = new SpeechNode { Name = nodeName }; return(AddNode(speechNode)); }
public void Constructor_TwineSpeechNode_SetsText_ToNodeText() { TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); twineSpeechNode.Text = "Text"; SpeechNode speechNode = new SpeechNode(twineSpeechNode); Assert.AreEqual("Text", speechNode.Text); }
/// <summary> /// Create a node of the inputted type and add it to the story. /// Will then create an appropriate GUI for the node in the story editor. /// </summary> /// <param name="type"></param> /// <param name="name"></param> /// <returns></returns> public NodeViewModel CreateNode(string name, Point position) { SpeechNode node = Story.CreateNode(name); NodeViewModel nodeViewModel = CreateNodeViewModel(node); nodeViewModel.Position = position; return(nodeViewModel); }
public void Constructor_TwineSpeechNode_SetsName_ToNodeName() { TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); twineSpeechNode.Name = "Test"; SpeechNode speechNode = new SpeechNode(twineSpeechNode); Assert.AreEqual("Test", speechNode.Name); }
public void Constructor_TwineSpeechNode_SetsNodeIndex_ToCorrectValue() { TwineSpeechNode twineSpeechNode = new TwineSpeechNode(); twineSpeechNode.OneBasedIndex = 13; SpeechNode speechNode = new SpeechNode(twineSpeechNode); Assert.AreEqual(12, speechNode.NodeIndex); }
/// START: Speech Node private void __ProcessSpeechNode(IDNodeBase _node) { SpeechNode node = (SpeechNode)_node; m_textbox.SetSpeakerName(node.SpeakerName); m_textbox.SetTextType(node.Text); state = State.DisplayingSpeech; }