public void Constructor_TwineSpeechNode_SetsParentStory_ToNull()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();
            SpeechNode      speechNode      = new SpeechNode(twineSpeechNode);

            Assert.IsNull(speechNode.ParentStory);
        }
示例#2
0
        /// <summary>
        /// Attempt to load a story from the inputted twinary story.
        /// Returns null if there was a problem converting the story.
        /// </summary>
        /// <returns></returns>
        public static Story Load(TwineStory twineStory)
        {
            if (twineStory == null)
            {
                return(null);
            }

            Story story = new Story();

            story.Name = twineStory.Name;
            story.Guid = twineStory.IfID;

            TwineSpeechNode firstNode = twineStory.Nodes.Find(x => x.OneBasedIndex == twineStory.OneBasedStartNodeIndex);

            story.StartNodeName = firstNode != null ? firstNode.Name : "";

            foreach (TwineSpeechNode twineSpeechNode in twineStory.Nodes)
            {
                story.CreateNode(twineSpeechNode);
            }

            // Only need to initialize transitions here - story.CreateNode will initialize the lookup
            story.InitializeNodeTransitions(twineStory);

            return(story);
        }
示例#3
0
        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);
        }
示例#4
0
 public SpeechNode(TwineSpeechNode twineSpeechNode)
 {
     Name      = twineSpeechNode.Name;
     NodeIndex = twineSpeechNode.OneBasedIndex - 1;
     Text      = twineSpeechNode.Text;
     Tags.AddRange(twineSpeechNode.Tags);
     Position = new Vector2(twineSpeechNode.Position.X, twineSpeechNode.Position.Y);
 }
示例#5
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 Constructor_TwineSpeechNode_SetsNodeIndex_ToCorrectValue()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.OneBasedIndex = 13;
            SpeechNode speechNode = new SpeechNode(twineSpeechNode);

            Assert.AreEqual(12, speechNode.NodeIndex);
        }
        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_SetsText_ToNodeText()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Text = "Text";
            SpeechNode speechNode = new SpeechNode(twineSpeechNode);

            Assert.AreEqual("Text", speechNode.Text);
        }
        public void Constructor_TwineSpeechNode_SetsTransitions_ToEmptyList()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.TwineLinks.Add(new TwineLink());
            SpeechNode speechNode = new SpeechNode(twineSpeechNode);

            Assert.AreEqual(1, twineSpeechNode.TwineLinks.Count);
            Assert.AreEqual(0, speechNode.TransitionCount);
        }
示例#10
0
        public void CreateNode_TwineSpeechNode_AddsNodeToStory()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();
            Story           story           = new Story();

            Assert.AreEqual(0, story.NodeCount);

            story.CreateNode(twineSpeechNode);

            Assert.AreEqual(1, story.NodeCount);
        }
示例#11
0
        public void Constructor_TwineSpeechNode_SetsTags_ToNodeTags()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Tags.Add("Tag1");
            twineSpeechNode.Tags.Add("Tag2");
            SpeechNode speechNode = new SpeechNode(twineSpeechNode);

            Assert.AreEqual(2, speechNode.Tags.Count);
            Assert.AreEqual("Tag1", speechNode.Tags[0]);
            Assert.AreEqual("Tag2", speechNode.Tags[1]);
        }
示例#12
0
        public void InputtingNonNullTwineStory_SetsUpNodesCorrectly()
        {
            TwineStory      twineStory      = new TwineStory();
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Name = "TestName";
            twineStory.Nodes.Add(twineSpeechNode);
            Story story = Story.Load(twineStory);

            Assert.IsNotNull(story);
            Assert.AreEqual("TestName", twineSpeechNode.Name);
        }
示例#13
0
        public void InputtingNonNullTwineStory_WithNonExistentStartNode_SetsStartNode_ToNull()
        {
            TwineStory      twineStory      = new TwineStory();
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Name = "TestName";
            twineStory.Nodes.Add(twineSpeechNode);
            twineStory.OneBasedStartNodeIndex = 100;

            Assert.IsNull(twineStory.Nodes.Find(x => x.OneBasedIndex == 100));

            Story story = Story.Load(twineStory);

            Assert.IsNotNull(story);
            Assert.IsNull(story.StartNode);
        }
示例#14
0
        public void Story_Load_StoryWithSingleNode_DeserializesCorrectly()
        {
            /*
             * {
             * "passages": [
             *  {
             *    "text": "Single Node Text",
             *    "name": "Single Node",
             *    "pid": "1",
             *    "position": {
             *      "x": "412",
             *      "y": "187.5"
             *    },
             *    "tags": [
             *      "Node"
             *    ]
             *  }
             * ],
             * "name": "SingleNodeStory",
             * "startnode": "1",
             * "creator": "Twine",
             * "creator-version": "2.2.1",
             * "ifid": "E496B74E-C387-4E7F-B66E-9FB8927FE229"
             * }
             */

            TwineStory story = TwineStory.Load(JsonStoryResources.SingleNodeStory);

            Assert.IsNotNull(story);
            Assert.AreEqual("SingleNodeStory", story.Name);
            Assert.AreEqual(1, story.OneBasedStartNodeIndex);
            Assert.AreEqual("Twine", story.Creator);
            Assert.AreEqual("2.2.1", story.CreatorVersion);
            Assert.AreEqual(new Guid("E496B74E-C387-4E7F-B66E-9FB8927FE229"), story.IfID);
            Assert.IsNotNull(story.Nodes);
            Assert.AreEqual(1, story.Nodes.Count);

            TwineSpeechNode speechNode = story.Nodes[0];

            Assert.IsNotNull(speechNode);
            Assert.AreEqual("Single Node", speechNode.Name);
            Assert.AreEqual("Single Node Text", speechNode.Text);
            Assert.IsNotNull(speechNode.Tags);
            Assert.AreEqual(1, speechNode.Tags.Count);
            Assert.AreEqual("Node", speechNode.Tags[0]);
            AssertExt.IsEmpty(speechNode.TwineLinks);
        }
示例#15
0
        public void InputtingNonNullTwineStory_WithExistentStartNode_SetsUpStartNodeCorrectly()
        {
            TwineStory      twineStory      = new TwineStory();
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Name          = "TestName";
            twineSpeechNode.OneBasedIndex = 100;
            twineStory.Nodes.Add(twineSpeechNode);
            twineStory.OneBasedStartNodeIndex = 100;

            Assert.AreSame(twineSpeechNode, twineStory.Nodes.Find(x => x.OneBasedIndex == 100));

            Story story = Story.Load(twineStory);

            Assert.IsNotNull(story);
            Assert.IsNotNull(story.StartNode);
            Assert.AreSame(story.StartNode, story.GetNodeAt(0));
        }
示例#16
0
        public void CreateNode_TwineSpeechNode_CreatesNodeWithCorrectValues()
        {
            TwineSpeechNode twineSpeechNode = new TwineSpeechNode();

            twineSpeechNode.Name = "Test";
            twineSpeechNode.Text = "Text Here";
            twineSpeechNode.Tags.Add("Tag1");
            Story story = new Story();

            Assert.AreEqual(0, story.NodeCount);

            SpeechNode speechNode = story.CreateNode(twineSpeechNode);

            Assert.IsNotNull(speechNode);
            Assert.AreEqual("Test", speechNode.Name);
            Assert.AreEqual("Text Here", speechNode.Text);
            Assert.AreEqual(1, speechNode.Tags.Count);
            Assert.AreEqual("Tag1", speechNode.Tags[0]);
        }
示例#17
0
 /// <summary>
 /// Creates a new node in this story using the inputted twine speech node format.
 /// Will add the newly created node to this story.
 /// </summary>
 /// <param name="twineSpeechNode"></param>
 /// <returns></returns>
 public SpeechNode CreateNode(TwineSpeechNode twineSpeechNode)
 {
     return(twineSpeechNode != null?AddNode(new SpeechNode(twineSpeechNode)) : null);
 }
示例#18
0
        public void Constructor_SetsText_ToEmptyString()
        {
            TwineSpeechNode speechNode = new TwineSpeechNode();

            Assert.AreEqual("", speechNode.Text);
        }
示例#19
0
        public void Story_Load_StoryWithSingleLink_DeserializesCorrectly()
        {
            /*
             * {
             * "passages": [
             *  {
             *    "text": "[[Source Node Text|Destination Node]]",
             *    "links": [
             *      {
             *        "name": "Source Node Text|Destination Node",
             *        "link": "Source Node Text|Destination Node"
             *      }
             *    ],
             *    "name": "Source Node",
             *    "pid": "1",
             *    "position": {
             *      "x": "412",
             *      "y": "187.5"
             *    }
             *  },
             *  {
             *    "text": "Destination Node Text",
             *    "name": "Destination Node",
             *    "pid": "2",
             *    "position": {
             *      "x": "412",
             *      "y": "337.5"
             *    }
             *  }
             * ],
             * "name": "SingleLinkStory",
             * "startnode": "1",
             * "creator": "Twine",
             * "creator-version": "2.2.1",
             * "ifid": "09337916-8C97-456D-B4BC-93182ECA4911"
             * }
             */

            TwineStory story = TwineStory.Load(JsonStoryResources.SingleLinkStory);

            Assert.IsNotNull(story);
            Assert.AreEqual("SingleLinkStory", story.Name);
            Assert.AreEqual(1, story.OneBasedStartNodeIndex);
            Assert.AreEqual("Twine", story.Creator);
            Assert.AreEqual("2.2.1", story.CreatorVersion);
            Assert.AreEqual(new Guid("09337916-8C97-456D-B4BC-93182ECA4911"), story.IfID);
            Assert.IsNotNull(story.Nodes);
            Assert.AreEqual(2, story.Nodes.Count);

            // First node
            {
                TwineSpeechNode speechNode = story.Nodes[0];

                Assert.IsNotNull(speechNode);
                Assert.AreEqual("Source Node", speechNode.Name);
                Assert.AreEqual("[[Source Node Text|Destination Node]]", speechNode.Text);
                Assert.IsNotNull(speechNode.Tags);
                AssertExt.IsEmpty(speechNode.Tags);
                Assert.AreEqual(1, speechNode.TwineLinks.Count);
            }

            // Second node
            {
                TwineSpeechNode speechNode = story.Nodes[1];

                Assert.IsNotNull(speechNode);
                Assert.AreEqual("Destination Node", speechNode.Name);
                Assert.AreEqual("Destination Node Text", speechNode.Text);
                Assert.IsNotNull(speechNode.Tags);
                AssertExt.IsEmpty(speechNode.Tags);
                AssertExt.IsEmpty(speechNode.TwineLinks);
            }
        }
示例#20
0
        public void Constructor_SetsOneBasedIndex_ToOne()
        {
            TwineSpeechNode speechNode = new TwineSpeechNode();

            Assert.AreEqual(1, speechNode.OneBasedIndex);
        }
示例#21
0
        public void Constructor_SetsTwineLinks_ToEmptyList()
        {
            TwineSpeechNode speechNode = new TwineSpeechNode();

            AssertExt.IsEmpty(speechNode.TwineLinks);
        }