void AssignDataToNodes(SilkStory newSilkStory, SilkNode newNode, string newTweeData, string newPassage, string storyTitle) { newNode.nodeName = storyTitle + "_" + ReturnTitle(newTweeData).TrimEnd(' '); //only to remove it when required in GetNodeName newNode.StoryName = storyTitle; //add custom tag names // //TODO TEST //newNode.tags = ReturnCustomTags(newTweeData); //add custom tags //TODO process tags just in time, rather than doing a tag-pass /* * foreach (KeyValuePair<string, string[]> tagName in newNode.tags) { * * string newTagName = ""; * //Right now, you can't use underscores in your custom tag names * if (tagName.Key.Contains("_")) { * newTagName = tagName.Key.Remove(tagName.Key.IndexOf('_')).TrimStart().TrimEnd(); * } * if (tagFactory.SetTag(newTagName, tagName.Value) != null) { * newNode.silkTags.Add(tagFactory.SetTag(newTagName, tagName.Value)); * } * else { * Debug.LogError(newTagName + " is not a recognized tag. Check your TagFactory"); * } * } */ //Debug.Log(newNode.silkTags[0].TagName); //add passage newNode.nodePassage = newPassage; //TODO Add the correct amount of links to the list //add link names //Debug.Log(ReturnLinks(newTweeData).Count); newNode.links = ReturnLinks(newTweeData); newSilkStory.AddToStory(newNode.nodeName, newNode); }
void AssignDataToNodes(SilkStory newSilkStory, SilkNode newNode, string newTweeData, string newPassage, string storyTitle) { //TODO figure out where this g----Title is started newNode.nodeName = storyTitle + "_" + ReturnTitle(newTweeData).TrimEnd(' '); //only to remove it when required in GetNodeName newNode.StoryName = storyTitle; //add custom tag names newNode.tags = ReturnCustomTags(newTweeData); //add custom tags foreach (KeyValuePair <string, string[]> tagName in newNode.tags) { string newTagName = ""; //Right now, you can't use underscores in your custom tag names if (tagName.Key.Contains("_")) { newTagName = tagName.Key.Remove(tagName.Key.IndexOf('_')).TrimStart().TrimEnd(); } if (tagFactory.SetTag(newTagName, tagName.Value) != null) { newNode.silkTags.Add(tagFactory.SetTag(newTagName, tagName.Value)); } else { Debug.LogError(newTagName + " is not a recognized tag. Check your TagFactory"); } } //Debug.Log(newNode.silkTags[0].TagName); //add passage newNode.nodePassage = newPassage; //TODO Add the correct amount of links to the list //add link names newNode.links = ReturnLinks(newTweeData); newSilkStory.AddToStory(newNode.nodeName, newNode); }
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); } } } }
string GetPrompt(int c, SilkStory story, SilkNode curNode) { StringBuilder curNodeText = new StringBuilder(tweeNodesToInterpret[c]); StringBuilder promptContainer = new StringBuilder(tweeNodesToInterpret[c]); for (int p = 0; p < curNodeText.Length; p++) { //check for prompt if ((p + 2) < curNodeText.Length && (p - 2) > 0) { if (curNodeText [p - 1] == '>' && curNodeText [p - 2] == '>') { if (curNodeText [p] == '\n') { if (curNodeText [p + 1] != '<' && curNodeText [p + 1] != '[') { curNodeText.Insert(p + 1, "<<prompt>>"); } } } } } //Debug.Log ("CUR NODE TEXT >>" + curNodeText); if (tweeNodesToInterpret[c].Contains("|")) { promptContainer.Replace("|", string.Empty); } if (tweeNodesToInterpret[c].Contains(ReturnTitle(tweeNodesToInterpret[c]))) { string storyTitleCheck = ReturnTitle(tweeNodesToInterpret[c]).TrimStart().TrimEnd(); if (storyTitleCheck == "StoryTitle") { story.SetStoryName(ReturnStoryTitle(tweeNodesToInterpret[c])); //storyTitle = story.StoryName; //story.SetStoryName(filename); } else if (storyTitleCheck == "MetaData") { } else { promptContainer.Replace(ReturnTitle(tweeNodesToInterpret[c]), string.Empty, 0, ReturnTitle(tweeNodesToInterpret[c]).Length); } } for (int k = 0; k < curNodeText.Length; k++) { //problem?? StringBuilder newTag; //while (promptContainer[0] == '\n') { //promptContainer.Remove(0, 1); //} /* * if(promptContainer[0] == '<' && promptContainer[1] == '<') { * newTag = new StringBuilder(); * for (int i = 0; i < promptContainer.Length; i++) { * if(promptContainer[i] == '>' && promptContainer[i+1] == '>') { * //for testing * //if below says .Remove(); it should rather extract the tag * //and put it on the execution queue * * promptContainer.Remove(0, newTag.Length); * break; * } * else { * newTag.Append(promptContainer[i]); * } * } * Debug.Log(newTag); * }*/ if (curNodeText[k] == '<' && curNodeText[k + 1] == '<') { string rawTag = ""; for (int t = k; t < curNodeText.Length; t++) { if (curNodeText[t - 1] == '>' && curNodeText[t - 2] == '>') { break; } else { rawTag += curNodeText[t]; } } // //TEST TAG REPLACEMENT //promptContainer.Replace(rawTag, ParseRawTag(rawTag, tagFactory).Value); //if promptcontainer is empty and contains <<prompt>>, delete prompt //Debug.Log ("RAWTAG" + rawTag); if (ParseRawTag(rawTag, tagFactory).type == TagType.INLINE) { //if (ParseRawTag(rawTag, tagFactory).TagName == "connect") { // ParseRawTag(rawTag, tagFactory).TagExecute(); //} promptContainer.Replace(rawTag, ParseRawTag(rawTag, tagFactory).Value); //Debug.Log("IN"); } else if (ParseRawTag(rawTag, tagFactory).type == TagType.SEQUENCED) { curNode.executionQueue.Add(ParseRawTag(rawTag, tagFactory)); promptContainer.Replace(rawTag, ParseRawTag(rawTag, tagFactory).Value); //Debug.Log("SQ"); } if (String.IsNullOrEmpty(promptContainer.ToString().Trim())) { if (curNodeText.ToString().Contains("<<prompt>>")) { curNodeText.Replace("<<prompt>>", String.Empty); } //Debug.Log("NODE NODE::"+curNodeText); } //return to here //Debug.Log(ParseRawTag(rawTag, tagFactory).TagName + " " + ParseRawTag(rawTag, tagFactory).type); } //if k is } foreach (KeyValuePair <string, string> entry in ReturnLinks(tweeNodesToInterpret[c])) { if (tweeNodesToInterpret[c].Contains("[[" + entry.Key) || tweeNodesToInterpret[c].Contains("[[" + entry.Value)) { promptContainer.Replace("[[" + entry.Key, String.Empty); ////////////////////////////////////////////////////////////// //this is to catch instances where the syntax [[link]] is used //in order to remove the trailing "]]" ////////////////////////////////////////////////////////////// if (entry.Key == entry.Value) { promptContainer.Replace("]]", String.Empty); } promptContainer.Replace(entry.Value + "]]", String.Empty); } } promptContainer.Replace(System.Environment.NewLine, String.Empty); //test prompt //curNode.executionQueue.Enqueue(tagFactory.SetTag("prompt", null)); return(promptContainer.ToString()); }
void GetPostTags(int c, SilkStory story) { //get tags after prompt }
//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); } } } } } }
public void AddToMother(string storyName, SilkStory story) { motherStory.Add(storyName, story); }