private void AddWord(ModifiedDialogue mD, string modifier, int index)
 {
     if (modifier == modifiers[0])
     {
         mD.jitterIndices.Add(index);
     }
     else if (modifier == modifiers[1])
     {
         mD.waveIndices.Add(index);
     }
     else if (modifier == modifiers[2])
     {
         mD.colorIndices[0].Add(index);
     }
     else if (modifier == modifiers[3])
     {
         mD.colorIndices[1].Add(index);
     }
     else if (modifier == modifiers[4])
     {
         mD.colorIndices[2].Add(index);
     }
     else if (modifier == modifiers[5])
     {
         mD.colorIndices[3].Add(index);
     }
 }
Beispiel #2
0
    public void DisplayNextSentence()
    {
        sentencesLeft = sentences.Count;

        if (sentencesLeft <= 0)
        {
            EndDialogue();
            return;
        }

        sentenceCount++;

        StopAllCoroutines();

        currentSentence = sentences.Dequeue();

        mD = cD.FindMods(currentSentence);

        currentSentence = mD.sentence;

        if (mD.yesNoQuestion)
        {
            yesNoBox.SetActive(true);

            yesText.text = mD.yNFirstTerm;
            noText.text  = mD.yNSecondTerm;
        }
        else
        {
            yesNoBox.SetActive(false);
        }

        fX.type = true;

        StartCoroutine(fX.ApplyEffects(currentSentence, mD.colorIndices, mD.waveIndices.ToArray(), mD.jitterIndices.ToArray()));
    }
    public ModifiedDialogue FindMods(string sentence)
    {
        ModifiedDialogue mD = new ModifiedDialogue();

        string finishedSentence = sentence;

        //Make an array of strings from the initial sentence
        string[] words = sentence.Split(' ');

        int firstIndex = -1;

        //Create a new list that represents the characters in between the modifiers
        List <char> lettersBetween = new List <char>();

        //For each color create a new list
        for (int i = 0; i < 4; i++)
        {
            mD.colorIndices.Add(new List <int>());
        }

        //For every modifier
        for (int x = 0; x < modifiers.Length; x++)
        {
            //For every word
            for (int y = 0; y < words.Length; y++)
            {
                //If the word contains a modifier
                if (words[y].Contains(modifiers[x]))
                {
                    //If two identical modifiers are on the same word
                    if (words[y].IndexOf(modifiers[x]) != words[y].LastIndexOf(modifiers[x]))
                    {
                        //Add the word to the list
                        AddWord(mD, modifiers[x], y);

                        //Replace all of the modifiers
                        words[y].Replace(modifiers[x], "");
                    }
                    else
                    {
                        //If there is no defined first index yet
                        if (firstIndex == -1)
                        {
                            //Set it to y
                            firstIndex = y;
                        }
                        else
                        {
                            for (int z = firstIndex; z <= y; z++)
                            {
                                AddWord(mD, modifiers[x], z);
                            }

                            words[firstIndex].Replace(modifiers[x], "");
                            words[y].Replace(modifiers[x], "");

                            firstIndex = -1;
                        }
                    }

                    finishedSentence = finishedSentence.Replace(modifiers[x], "");
                }
            }
        }

        mD.sentence = finishedSentence;

        mD = sC.CheckForSpecialConditions(mD);

        return(mD);
    }
Beispiel #4
0
    public ModifiedDialogue CheckForSpecialConditions(ModifiedDialogue mD)
    {
        ModifiedDialogue newMD = mD;

        string sentence = newMD.sentence;

        string toReplace = null;

        if (sentence.Contains("~YesNo:"))
        {
            bool foundFirstTerm      = false;
            bool foundFirstTermName  = false;
            bool foundAllFirstTerm   = false;
            bool foundSecondTermName = false;
            bool foundAllSecondTerm  = false;

            string firstTerm  = null;
            string secondTerm = null;

            string firstResponseName  = null;
            string secondResponseName = null;

            int firstResponseIndex  = 0;
            int secondResponseIndex = 0;
            int responseIndex       = -1;

            string firstTermParse  = null;
            string secondTermParse = null;

            for (int i = System.Array.IndexOf(sentence.ToCharArray(), ':') + 1; i < sentence.ToCharArray().Length; i++)
            {
                if (foundFirstTerm == false)
                {
                    if (sentence.ToCharArray()[i] != ',')
                    {
                        firstTerm += sentence.ToCharArray()[i];
                    }
                    else
                    {
                        for (int j = System.Array.IndexOf(firstTerm.ToCharArray(), '(') + 1; j < firstTerm.ToCharArray().Length; j++)
                        {
                            if (!foundAllFirstTerm)
                            {
                                if (firstTerm.ToCharArray()[j] != '[' && !foundFirstTermName)
                                {
                                    firstResponseName += firstTerm.ToCharArray()[j];
                                }
                                else
                                {
                                    if (firstTerm.ToCharArray()[j] == '[')
                                    {
                                        foundFirstTermName = true;

                                        j++;
                                    }

                                    if (firstTerm.ToCharArray()[j] != ']')
                                    {
                                        firstTermParse += firstTerm.ToCharArray()[j];
                                    }
                                    else
                                    {
                                        int.TryParse(firstTermParse, out firstResponseIndex);

                                        if (firstResponseIndex < 0)
                                        {
                                            firstResponseIndex = 0;
                                            Debug.LogError("First response index failed to parse properly.");
                                        }

                                        foundAllFirstTerm = true;
                                    }
                                }
                            }
                        }

                        firstTerm = firstTerm.Replace("(" + firstResponseName + "[" + firstResponseIndex.ToString() + "])", "");

                        newMD.yNFirstTerm = firstTerm;

                        foundFirstTerm = true;
                    }
                }
                else
                {
                    if (sentence.ToCharArray()[i] == ',')
                    {
                        i++;
                    }
                    if (sentence.ToCharArray()[i] != '#')
                    {
                        secondTerm += sentence.ToCharArray()[i];
                    }
                    //EDIT HERE
                    else
                    {
                        for (int l = System.Array.IndexOf(secondTerm.ToCharArray(), '(') + 1; l < secondTerm.ToCharArray().Length; l++)
                        {
                            if (!foundAllSecondTerm)
                            {
                                if (secondTerm.ToCharArray()[l] != '[' && !foundSecondTermName)
                                {
                                    secondResponseName += secondTerm.ToCharArray()[l];
                                }
                                else
                                {
                                    if (secondTerm.ToCharArray()[l] == '[')
                                    {
                                        foundSecondTermName = true;

                                        l++;
                                    }

                                    if (secondTerm.ToCharArray()[l] != ']')
                                    {
                                        secondTermParse += secondTerm.ToCharArray()[l];
                                    }
                                    else
                                    {
                                        int.TryParse(secondTermParse, out secondResponseIndex);

                                        foundAllSecondTerm = true;
                                    }
                                }
                            }
                        }

                        secondTerm = secondTerm.Replace("(" + secondResponseName + "[" + secondResponseIndex.ToString() + "])", "");

                        newMD.yNSecondTerm = secondTerm;

                        newMD.yNFirstResponseTriggerName  = firstResponseName;
                        newMD.yNSecondResponseTriggerName = secondResponseName;

                        newMD.yNFirstResponseTriggerIndex  = firstResponseIndex;
                        newMD.yNSecondResponseTriggerIndex = secondResponseIndex;

                        break;
                    }
                }
            }

            if (sentence.Contains("])#"))
            {
                string toParse = null;

                for (int r = System.Array.IndexOf(sentence.ToCharArray(), '#') + 1; r < sentence.ToCharArray().Length; r++)
                {
                    if (sentence.ToCharArray()[r] != '~')
                    {
                        toParse += sentence.ToCharArray()[r];
                    }

                    else
                    {
                        int.TryParse(toParse, out responseIndex);

                        break;
                    }
                }
            }

            //secondTerm = secondTerm.Replace("#" + responseIndex.ToString(), "");

            toReplace = "~YesNo:" + firstTerm + "(" + firstResponseName + "[" + firstResponseIndex.ToString() + "])," + secondTerm + "(" + secondResponseName + "[" + secondResponseIndex.ToString() + "])";

            if (responseIndex != -1)
            {
                toReplace += "#" + responseIndex.ToString();
            }

            toReplace += "~";

            mD.sentence = sentence.Replace(toReplace, "");

            newMD.yesNoQuestion = true;

            newMD.yNIndex = responseIndex;

            if (sentence.Contains("{Essay}"))
            {
                sentence = sentence.Replace("{Essay}", "");

                newMD.essayQuestion = true;
            }
        }

        return(newMD);
    }
Beispiel #5
0
    public ModifiedDialogue FindMods(string sentence)
    {
        ModifiedDialogue mD = new ModifiedDialogue();

        string finishedSentence = sentence;

        List <int> jitterIndices = new List <int>();
        List <int> waveIndices   = new List <int>();
        List <int> keyIndices    = new List <int>();
        List <int> redIndices    = new List <int>();

        for (int x = 0; x < modifiers.Length; x++)
        {
            List <string> modWords = new List <string>();
            if (sentence != null)
            {
                if (sentence.Contains(modifiers[x]))
                {
                    modWords.Clear();

                    int startingIndex = 0;

                    string[] sentenceWords = sentence.Replace(modifiers[x], "").Split(' ');

                    finishedSentence = finishedSentence.Replace(modifiers[x], "");

                    MatchCollection modMatches = modReges[x].Matches(sentence);

                    for (int y = 0; y < modMatches.Count; y++)
                    {
                        startingIndex = System.Array.IndexOf(sentence.Split(' '), modMatches[y].Value.Split(' ')[0]);

                        foreach (string word in modMatches[y].Value.Split(' '))
                        {
                            modWords.Add(word.Replace(modifiers[x], ""));
                        }

                        for (int i = 0; i < modWords.Count; i++)
                        {
                            if (modifiers[x] == "~")
                            {
                                jitterIndices.Add(i + startingIndex);
                            }
                            else if (modifiers[x] == "=")
                            {
                                waveIndices.Add(i + startingIndex);
                            }
                            else if (modifiers[x] == "#")
                            {
                                keyIndices.Add(i + startingIndex);
                            }
                            else if (modifiers[x] == "%")
                            {
                                redIndices.Add(i + startingIndex);
                            }
                        }
                    }
                }
            }
        }

        mD.jitterIndices = jitterIndices;
        mD.waveIndices   = waveIndices;

        mD.colorIndices.Clear();
        if (keyIndices.Count > 0)
        {
            mD.colorIndices.Add(keyIndices.ToArray());
        }
        else
        {
            mD.colorIndices.Add(null);
        }
        mD.sentence = finishedSentence;

        if (redIndices.Count > 0)
        {
            mD.colorIndices.Add(redIndices.ToArray());
        }
        else
        {
            mD.colorIndices.Add(null);
        }

        mD.sentence = finishedSentence;

        return(mD);
    }