public TwineDialogue(string name, PassageNode startNode) { Singleton = this; Passage = new Dictionary <string, PassageNode>(); Name = name; StartPassage = startNode; CurrentPassage = StartPassage; }
/* * Basic constructor that sets all the fields of the PassageNode. * Also initializes the choice dictionary. */ public PassageNode(TwineDialogue parent, int pid, string name, List <string> tags, string position, string content) { _parent = parent; _passageID = pid; _name = name; _tags = tags; _position = position; _content = content; isVisited = false; _choiceDictionary = new Dictionary <string, string>(); }
void Start() { TDialogue = TwineReader.Parse(DialogueFile); List <PassageNode> AlternateStarts = TDialogue.GetPassagesTagged(AlternateStartTag); //BranchData.Singleton.EnemiesKilled = 5; //Testing the alternate beginning. CurrentPassage = AlternateStarts.Count > 0 && BranchData.Singleton.EnemiesKilled >= EnemiesKilledThreshhold ? AlternateStarts[0] : TDialogue.StartPassage; TDialogue.SetCurrentPassage(CurrentPassage); PassageText = CurrentPassage.GetContent(); _currentlyTyping = true; _activatedCoRoutine = false; }
/* * Parses a Story file from Twine in Harlowe format. * The data is stored as so: * 1: PID * 2: Name * 3: Tags * 4: Position * 5: Content */ public static TwineDialogue Parse(TextAsset ta) { string s = ta.text.Replace("'", "\'").Replace(""", "\""); TwineDialogue result = new TwineDialogue(); //Getting the Story Data GroupCollection storyGroups = RegexParse(STORY_PATTERN, s)[0].Groups; result.Name = storyGroups[1].Value; string startNodeIndex = storyGroups[2].Value; MatchCollection passageMatches = RegexParse(PASSAGE_PATTERN, s); foreach (Match pmatch in passageMatches) { //For each passage, find the regex groups GroupCollection passageGroups = pmatch.Groups; //Apply the content regex on the passage body MatchCollection textMatches = RegexParse(TEXT_PATTERN, passageGroups[5].Value); //Grab the content from the passage body string contentText = ""; if (textMatches.Count > 0) { contentText = textMatches[0].Groups[1].Value; } else { contentText = passageGroups[5].Value; } List <string> tags = new List <string>(passageGroups[3].Value.Split(' ')); //Create a node based on the regex groups from the passage regex PassageNode newNode = new PassageNode(result, int.Parse(passageGroups[1].Value), passageGroups[2].Value, tags, passageGroups[4].Value, contentText); //Check if the passage ID is equal to the start node ID of the story if (passageGroups[1].Value.Equals(startNodeIndex)) { result.StartPassage = newNode; } result.AddPassage(passageGroups[2].Value, newNode); //Check all the choices in the passage foreach (Match cmatch in RegexParse(CHOICE_PATTERN, passageGroups[5].Value)) { GroupCollection choiceGroups = cmatch.Groups; newNode.AddChoice(choiceGroups[1].Value, choiceGroups[2].Value); } } return(result); }
public TwineDialogue(string name) { Singleton = this; Passage = new Dictionary <string, PassageNode>(); Name = name; }
public TwineDialogue() { Singleton = this; Passage = new Dictionary <string, PassageNode>(); }