예제 #1
0
    public PassageNode GetPassage(string s)
    {
        PassageNode pn = null;

        CurrentPassage = Passage.TryGetValue(s, out pn) ? pn : CurrentPassage;
        return(pn);
    }
예제 #2
0
 public void SetCurrentPassage(PassageNode pn)
 {
     CurrentPassage = pn;
     if (OnChange != null)
     {
         OnChange();
     }
 }
예제 #3
0
 public TwineDialogue(string name, PassageNode startNode)
 {
     Singleton      = this;
     Passage        = new Dictionary <string, PassageNode>();
     Name           = name;
     StartPassage   = startNode;
     CurrentPassage = StartPassage;
 }
예제 #4
0
 void GetAndPlayAudio()
 {
     _node = TwineDialogue.Singleton.CurrentPassage;
     _pid  = _node.GetID();
     Debug.Log("PID: " + _pid);
     //Passage.TryGetValue (_pid, out _clip);
     audioSource.clip = audioClips[_pid];
 }
예제 #5
0
    /*
     *  Takes in a choice and returns the corresponding
     *  PassageNode. Will also trigger the isVisited flag.
     */
    public PassageNode GetDecision(string s)
    {
        PassageNode decision = GetDecisionIncognito(s);

        if (decision != null)
        {
            decision.isVisited = true;
        }
        return(decision);
    }
예제 #6
0
    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;
    }
예제 #7
0
    /*
     * 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("&#39;", "\'").Replace("&quot", "\"");
        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);
    }
예제 #8
0
 public void AddPassage(string key, PassageNode pn)
 {
     Passage.Add(key, pn);
 }
예제 #9
0
 public void ChoiceSelect(string choiceContent)
 {
     if (Choices.Count > 0)
     {
         PassageNode decision = CurrentPassage.GetDecision(choiceContent);
         TDialogue.SetCurrentPassage(decision);
         if (decision != null)
         {
             CurrentPassage = decision;
             foreach (Button b in Choices)
             {
                 Destroy(b.gameObject);
             }
             Choices.Clear();
             PassageTextDisplay.text = "";
             PassageText             = CurrentPassage.GetContent();
             _currentlyTyping        = true;
         }
         else
         {
             Debug.Log("ChoiceSelect failed!");
         }
     }
     else
     {
         List <PassageNode> AlternateEnds = TDialogue.GetPassagesTagged(AlternateEndTag);
         Debug.Log("AlternateEnds: " + AlternateEnds.Count);
         Debug.Log("Visited: " + BranchData.Singleton.ColorVisited);
         if (AlternateEnds.Count > 0 && BranchData.Singleton.ColorVisited && !AlternateEndVisited)
         {
             Destroy(ContinueButton.gameObject);
             PassageTextDisplay.text = "...";
             _currentlyTyping        = false;
             CurrentPassage          = AlternateEnds[0];
             Invoke("AlternateEndDelay", AlternateEndDelayTime);
         }
         else
         {
             List <string> tags = CurrentPassage.GetTags();
             if (tags.Contains(LoadTag))
             {
                 tags.Remove(LoadTag);
                 if (tags.Count == 1)
                 {
                     NextScene = tags[0];
                 }
             }
             if (tags.Contains(GameOverTag))
             {
                 //TODO: CALL GAMEOVER FUNCTION
                 if (GAMEOVERTHING != null)
                 {
                     GAMEOVERTHING.SetActive(true);
                     Time.timeScale = 0f;
                 }
             }
             else
             {
                 StartCoroutine(StartEndingDialogueTransition());
             }
         }
     }
 }
예제 #10
0
 public static void Play(PassageNode pn)
 {
     Play(pn.GetID());
 }