Exemplo n.º 1
0
        void InitializeSilk()
        {
            tagFactory = new TagFactory();
            importer   = GetComponent <Silk.Importer>();
            List <string> filenames = new List <string>();

            mother = new SilkMotherStory();

            foreach (TextAsset currentTweeFile in importer.rawTweeFiles)
            {
                SilkStory newSilkStory = new SilkStory();
                TextAsset tweeFile     = currentTweeFile;
                string    fileName     = currentTweeFile.name;
                //this works for single file
                //textToParse = testText.text;

                textToParse          = tweeFile.text;
                tweeNodesToInterpret = textToParse.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < tweeNodesToInterpret.Length; i++)
                {
                    string        storyTitle      = "";
                    StringBuilder promptContainer = new StringBuilder(tweeNodesToInterpret[i]);

                    if (tweeNodesToInterpret[i].Contains("|"))
                    {
                        promptContainer.Replace("|", string.Empty);
                    }
                    if (tweeNodesToInterpret[i].Contains(ReturnTitle(tweeNodesToInterpret[i])))
                    {
                        string storyTitleCheck = ReturnTitle(tweeNodesToInterpret[i]).TrimStart().TrimEnd();
                        if (storyTitleCheck == "StoryTitle")
                        {
                            newSilkStory.SetStoryName(ReturnStoryTitle(tweeNodesToInterpret[i]));
                        }
                        else
                        {
                            promptContainer.Replace(ReturnTitle(tweeNodesToInterpret[i]), string.Empty, 0, ReturnTitle(tweeNodesToInterpret[i]).Length);
                        }
                    }
                    foreach (KeyValuePair <string, string> entry in ReturnLinks(tweeNodesToInterpret[i]))
                    {
                        if (tweeNodesToInterpret[i].Contains("[[" + entry.Key) || tweeNodesToInterpret[i].Contains("[[" + entry.Value))
                        {
                            promptContainer.Replace("[[" + entry.Key, string.Empty).Replace(entry.Value + "]]", string.Empty);
                            promptContainer.Replace("]]", string.Empty);
                        }
                    }
                    SilkNode newNode = new SilkNode();
                    //TODO Switch type from SilkG--- to SilkStory in AssignDataToNodes
                    AssignDataToNodes(newSilkStory, newNode, tweeNodesToInterpret[i], promptContainer.ToString(), fileName);
                    //Debug.Log(newNode.nodeName);
                }
                mother.AddToMother(fileName, newSilkStory);
                foreach (KeyValuePair <string, SilkStory> story in mother.MotherStory)
                {
                    foreach (KeyValuePair <string, SilkNode> node in story.Value.Story)
                    {
                        //for testing
                        //Debug.Log("ON NODE: " + node.)
                    }
                }
            }
            //TODO Break This Out into its own method
            foreach (KeyValuePair <string, SilkStory> silkStory in mother.MotherStory)
            {
                filenames.Add(silkStory.Key);
            }
            //


            //have to search the mother to do it to ALL the gr---???
            //TODO in mother or in story, make a method that allows for easier searching
            //TODO Make this its own method
            foreach (KeyValuePair <string, SilkStory> story in mother.MotherStory)
            {
                foreach (KeyValuePair <string, SilkNode> node in story.Value.Story)
                {
                    foreach (KeyValuePair <string, string> link in node.Value.links)
                    {
                        StringBuilder linkNameBuilder = new StringBuilder();
                        string        linkName;
                        linkNameBuilder.Append(link.Value);
                        linkName = linkNameBuilder.ToString().TrimStart().TrimEnd();
                        foreach (KeyValuePair <string, SilkNode> linkedNode in story.Value.Story)
                        {
                            string        nodeName        = "";
                            StringBuilder nodeNameBuilder = new StringBuilder();
                            for (int a = 0; a < filenames.Count; a++)
                            {
                                if (linkedNode.Value.nodeName.Contains(filenames[a]))
                                {
                                    nodeNameBuilder.Append(linkedNode.Value.nodeName.Remove(0, filenames[a].Length + 1));
                                    nodeName = nodeNameBuilder.ToString().TrimEnd();
                                }
                            }

                            if (linkName.ToString() == nodeName)
                            {
                                SilkLink newSilkLink = new SilkLink(node.Value, linkedNode.Value, link.Key);
                                node.Value.silkLinks.Add(newSilkLink);
                                Debug.Log("SilkLink " + newSilkLink.LinkText);
                            }
                        }
                    }
                }
            }
            //TODO break this into its own method (TESTING)
            foreach (KeyValuePair <string, SilkStory> story in mother.MotherStory)
            {
                //for testing
                foreach (KeyValuePair <string, SilkNode> node in story.Value.Story)
                {
                    //for testing
                    Debug.Log("NODE IS CALLED " + node.Value.nodeName);
                    //Debug.Log(node.Value.silkTags[0]);
                    //Debug.Log(node.Value.silkTags.Count);
                    foreach (KeyValuePair <string, string[]> tagName in node.Value.tags)
                    {
                        //Debug.Log(tagName.Key);
                    }
                    foreach (SilkTagBase _tag in node.Value.silkTags)
                    {
                        Debug.Log(_tag.TagName);
                    }
                    foreach (SilkLink _link in node.Value.silkLinks)
                    {
                        Debug.Log(node.Value.nodeName + " " + " " + _link.LinkText);
                    }
                }
            }
        }
Exemplo n.º 2
0
        //TODO extract new methods from all of this
        void InitializeSilk()
        {
            tagFactory = new TagFactory();
            importer   = GetComponent <Silk.Importer>();
            List <string> filenames = new List <string>();

            mother = new SilkMotherStory();

            foreach (TextAsset currentTweeFile in importer.rawTweeFiles)
            {
                SilkStory newSilkStory = new SilkStory();
                TextAsset tweeFile     = currentTweeFile;
                string    fileName     = currentTweeFile.name;
                //Debug.LogWarning(currentTweeFile.name);
                //this works for single file
                //textToParse = testText.text;

                textToParse          = tweeFile.text;
                tweeNodesToInterpret = textToParse.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < tweeNodesToInterpret.Length; i++)
                {
                    string storyTitle = "";

                    //this is where prompt parsing was supposed to go
                    //TODO move to it's own method--everything that deals in extracting the prompt

                    SilkNode newNode = new SilkNode();
                    AssignDataToNodes(newSilkStory, newNode, tweeNodesToInterpret[i], GetPrompt(i, newSilkStory, newNode), fileName);
                }
                //newSilkStory.StoryName
                mother.AddToMother(fileName, newSilkStory);
            }
            //TODO Break This Out into its own method
            foreach (KeyValuePair <string, SilkStory> silkStory in mother.MotherStory)
            {
                filenames.Add(silkStory.Key);
            }
            //


            //TODO Make this its own method
            foreach (KeyValuePair <string, SilkStory> story in mother.MotherStory)
            {
                foreach (KeyValuePair <string, SilkNode> node in story.Value.Story)
                {
                    foreach (KeyValuePair <string, string> link in node.Value.links)
                    {
                        //somewhere in here, fix linkname parsing to allow for structure that's like [[hello|hello]]
                        StringBuilder linkNameBuilder = new StringBuilder();
                        string        linkName;
                        linkNameBuilder.Append(link.Value);
                        linkName = linkNameBuilder.ToString().TrimStart().TrimEnd();
                        foreach (KeyValuePair <string, SilkNode> linkedNode in story.Value.Story)
                        {
                            string        nodeName        = "";
                            StringBuilder nodeNameBuilder = new StringBuilder();
                            for (int a = 0; a < filenames.Count; a++)
                            {
                                if (linkedNode.Value.nodeName.Contains(filenames[a] + "_"))
                                {
                                    nodeNameBuilder.Append(linkedNode.Value.nodeName.Remove(0, filenames[a].Length + 1));
                                    nodeName = nodeNameBuilder.ToString().TrimEnd();
                                }
                            }

                            if (linkName.ToString() == nodeName)
                            {
                                SilkLink newSilkLink = new SilkLink(node.Value, linkedNode.Value, link.Key);
                                node.Value.silkLinks.Add(newSilkLink);
                                //Debug.Log("SilkLink " + newSilkLink.LinkText + " " + newSilkLink.LinkedNode.nodeName);
                            }
                        }
                    }
                }
            }
        }