// Use this for initialization
    void Start()
    {
        LinkTemplate.gameObject.SetActive(false);
        TextTemplate.gameObject.SetActive(false);
        ((RectTransform)LinkTemplate.transform).SetParent(null);
        TextTemplate.rectTransform.SetParent(null);

        if (this.Story == null)
        {
            this.Story = this.GetComponent <TwineStory>();
        }
        if (this.Story == null)
        {
            Debug.LogError("Text player does not have a story to play. Add a story script to the text player game object, or assign the Story variable of the text player.");
            return;
        }

        this.Story.OnStateChanged += Story_OnStateChanged;
        this.Story.OnOutput       += Story_OnOutput;

        if (StartStory)
        {
            this.Story.Begin();
        }
    }
Esempio n. 2
0
        public void Story_Load_InputtingNonExistentFilePath_ReturnsNull()
        {
            string path = "WubbaLubbaDubDub";

            Assert.IsFalse(File.Exists(path));
            Assert.IsNull(TwineStory.Load(path));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            const int    iterationCount = 10000;
            const string jsonPath       = @"C:\Repos\Dispatcher\RealTalkEngine\Resources\Json Stories\FragmentsOfSkullMaster.json";
            const string binPath        = @"C:\Repos\Dispatcher\RealTalkEngine\Resources\Binary Stories\FragmentsOfSkullMaster.data";

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < iterationCount; ++i)
            {
                TwineStory twineStory = TwineStory.Load(jsonPath);
                Story      story      = Story.Load(twineStory);
            }
            stopwatch.Stop();

            Console.WriteLine("Json total milliseconds for " + iterationCount + " iterations: " + stopwatch.ElapsedMilliseconds);
            Console.WriteLine("Json average milliseconds: " + (stopwatch.ElapsedMilliseconds / (float)iterationCount));

            stopwatch = Stopwatch.StartNew();
            for (int i = 0; i < iterationCount; ++i)
            {
                Story story = Story.Load(binPath);
            }
            stopwatch.Stop();

            Console.WriteLine("Bin total milliseconds for " + iterationCount + " iterations: " + stopwatch.ElapsedMilliseconds);
            Console.WriteLine("Bin average milliseconds: " + (stopwatch.ElapsedMilliseconds / (float)iterationCount));
            //Console.ReadKey();
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 //Need to put common functions that occur all the time here (like changing rooms, displaying dialog, etc.)
 public static void StartConversation(TwineStory story)
 {
     dialogControls.StartConversation(story);
     mapControls.hideControls();
     diaryControls.hideControls();
     loveInterestControls.hideLoveInterests();
 }
Esempio n. 7
0
        public void InputtingNonNullTwineStory_ReturnsStory()
        {
            TwineStory twineStory = new TwineStory();

            twineStory.Name = "Test";
            Story story = Story.Load(twineStory);

            Assert.IsNotNull(story);
            Assert.AreEqual("Test", story.Name);
        }
Esempio n. 8
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);
        }
    public override void OnImportAsset(AssetImportContext ctx)
    {
        TwineStory   so_story = ScriptableObject.CreateInstance <TwineStory> ();
        HtmlDocument document = new HtmlDocument();
        string       path     = ctx.assetPath;

        document.Load(path);
        //Debug.Log (path + "HTML Document: " + document.Text);

        HtmlNode       html_storydata = document.DocumentNode.SelectNodes("//tw-storydata").First();
        TwineStorydata storyData      = new TwineStorydata();

        storyData.name           = html_storydata.Attributes["name"].Value;
        storyData.ifid           = html_storydata.Attributes["ifid"].Value;
        storyData.startNode      = Int32.Parse(html_storydata.Attributes["startnode"].Value);
        storyData.creator        = html_storydata.Attributes["creator"].Value;
        storyData.creatorVersion = html_storydata.Attributes["creator-version"].Value;
        storyData.format         = html_storydata.Attributes["format"].Value;
        storyData.formatVersion  = html_storydata.Attributes["format-version"].Value;
        storyData.zoom           = Int32.Parse(html_storydata.Attributes["zoom"].Value);

        HtmlNode html_style = document.DocumentNode.SelectNodes("//tw-storydata//style").First();

        storyData.style      = new TwineStyle();
        storyData.style.id   = html_style.Attributes["id"].Value;
        storyData.style.role = html_style.Attributes["role"].Value;
        storyData.style.type = html_style.Attributes["type"].Value;

        HtmlNodeCollection  html_passages = document.DocumentNode.SelectNodes("//tw-storydata//tw-passagedata");
        List <TwinePassage> twinePassages = new List <TwinePassage> ();

        foreach (var item in html_passages)
        {
            TwinePassage p = new TwinePassage();
            p.position = StringsToVector2Int(item.Attributes["position"].Value.Split(','));
            p.size     = StringsToVector2Int(item.Attributes["size"].Value.Split(','));
            p.name     = item.Attributes["name"].Value;
            p.pid      = Int32.Parse(item.Attributes["pid"].Value);
            p.lines    = item.InnerHtml.Split('\n');
            for (int i = 0; i < p.lines.Length; i++)
            {
                p.lines[i] = System.Net.WebUtility.HtmlDecode(p.lines[i]);
            }
            p.tags = item.Attributes["tags"].Value.Split(' ');
            twinePassages.Add(p);
        }
        storyData.passages = twinePassages.ToArray();

        so_story.storyData = storyData;
        ctx.AddObjectToAsset("TwineStory", so_story);
        ctx.SetMainObject(so_story);
        //ScriptableObjectUtility.CreateAsset<TwineStory>(ctx.assetPath, ctx.);
    }
Esempio n. 10
0
    public void StartConversation(TwineStory story)
    {
        Debug.Log("Starting story: " + story);

        currentLine       = 0;
        this.currentStory = story;

        closed         = false;
        storyCompleted = false;

        /* Register UnityTwine callback functions */
        this.currentStory.OnOutput       += Story_OnOutput;
        this.currentStory.OnStateChanged += Story_OnStateChanged;

        this.currentStory.Begin();
    }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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));
        }
Esempio n. 14
0
    public static IEnumerator BeginDinner(Room room, TwineStory dinnerStory)
    {
        sfxManager.play("DinnerChime");
        loveInterestControls.hideLoveInterests();

        screenFader.setFadeTime(0.75f);
        screenFader.FadeToBlack();

        while (!screenFader.finishedFade)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        GameManager.StartConversation(dinnerStory);
        screenFader.FadeToClear();

        LoadRoom(room);

        dayControls.endOfDay = true;
    }
Esempio n. 15
0
    public static IEnumerator BeginMarriage(TwineStory marriageStory)
    {
        mapControls.hideControls();
        diaryControls.hideControls();
        loveInterestControls.hideLoveInterests();

        screenFader.setFadeTime(3.0f);
        screenFader.FadeToBlack();

        while (!screenFader.finishedFade)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        /*Do this later I'm really done right now*/
        timeUI.gameObject.SetActive(false);
        loveInterestControls.clearLoveInterests();
        backgroundControls.displayRoom(mansion.Rooms[(int)GameManager.RoomName.GreatHall].background);
        bgmManager.changeAudioSource("Marriage", 1.0f);
        GameManager.StartConversation(marriageStory);
        screenFader.FadeToClear();

        while (!dialogControls.closed)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        screenFader.setFadeTime(3.0f);
        screenFader.FadeToBlack();

        while (!screenFader.finishedFade)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        foregroundControls.displayScreen(dayControls.daySprites[8]);
        screenFader.FadeToClear();
        gameOver = true;
    }
Esempio n. 16
0
        public void Story_Load_EmptyStory_DeserializesCorrectly()
        {
            /*
             * {
             * "name": "EmptyStory",
             * "startnode": "1",
             * "creator": "Twine",
             * "creator-version": "2.2.1",
             * "ifid": "AB8A0633-93B4-4221-8F93-CD9E268C3211"
             * }
             */
            TwineStory story = TwineStory.Load(JsonStoryResources.EmptyStory);

            Assert.IsNotNull(story);
            Assert.AreEqual("EmptyStory", story.Name);
            Assert.AreEqual(1, story.OneBasedStartNodeIndex);
            Assert.AreEqual("Twine", story.Creator);
            Assert.AreEqual("2.2.1", story.CreatorVersion);
            Assert.AreEqual(new Guid("AB8A0633-93B4-4221-8F93-CD9E268C3211"), story.IfID);
            Assert.IsNotNull(story.Nodes);
            AssertExt.IsEmpty(story.Nodes);
        }
Esempio n. 17
0
        /// <summary>
        /// Set up all the transitions between all the nodes in the story.
        /// The node lookup must be initialized before calling this function.
        /// </summary>
        private void InitializeNodeTransitions(TwineStory twineStory)
        {
            Debug.Assert(Nodes.Count == m_nodeLookup.Count);

            // For each twine node in the story
            foreach (TwineSpeechNode twineNode in twineStory.Nodes)
            {
                // Attempt to find the corresponding node in this story
                if (m_nodeLookup.TryGetValue(twineNode.Name, out SpeechNode speechNode))
                {
                    // If we have found it, we go through each twine link in the original node
                    foreach (TwineLink twineLink in twineNode.TwineLinks)
                    {
                        // And try and find the corresponding destination node in this story that it was pointing to
                        if (m_nodeLookup.TryGetValue(twineLink.DestinationName, out SpeechNode destinationNode))
                        {
                            // If we find it, we create a transition in this story
                            speechNode.CreateTransition(destinationNode);
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            bool completed = false;

            while (!completed)
            {
                Console.WriteLine("Input story file...");

                string input = Console.ReadLine();
                if (input == "q" || input == "Q")
                {
                    completed = true;
                }
                else if (File.Exists(input))
                {
                    // Process story file
                    TwineStory twineStory = TwineStory.Load(input);
                    Story      story      = Story.Load(twineStory);

                    string outputPath = Path.ChangeExtension(input, "bst");

                    if (story.Save(outputPath, true))
                    {
                        Console.WriteLine("Story saved to " + outputPath);
                    }
                    else
                    {
                        Console.WriteLine("Story failed to save correctly");
                    }
                }
                else
                {
                    Console.WriteLine("Unrecognized input...");
                }
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 20
0
 void Awake()
 {
     this.story      = GetComponent <TwineStory>();
     alarm_sfxVolume = alarm_sfx.volume;
 }
Esempio n. 21
0
 public void Story_Load_InputtingInvalidStoryFilePath_ReturnsNull()
 {
     Assert.IsTrue(File.Exists(JsonStoryResources.InvalidStory));
     Assert.IsNull(TwineStory.Load(JsonStoryResources.InvalidStory));
 }