public IEnumerator DoParseSingle(IDialogueText dialogueText)
        {
            UserRequestedAllLine = false;

            foreach (string currentLetter in dialogueText.ParseSingle())
            {
                TextManager.ShowDialogueSingle(currentLetter);

                if (UserRequestedAllLine && !CurrentActer.IsAutomatic)
                {
                    yield return(null);
                }
                else
                {
                    yield return(new WaitForSeconds(CurrentStyle.Delay));
                }
            }

            yield return(new WaitForSeconds(NextDialogueDelay));

            if (!CurrentActer.IsAutomatic)
            {
                UserRequestedNextLine = false;
                while (!UserRequestedNextLine)
                {
                    yield return(null);
                }
            }
            else
            {
                yield return(new WaitForSeconds(NextDialogueDelay));
            }

            DialogueSystem.RequestNextLine();
        }
        private IEnumerator DoParseAccumulated(IDialogueText dialogueText)
        {
            UserRequestedAllLine = false;

            foreach (string currentText in dialogueText.ParseAccumulated())
            {
                TextManager.ShowDialogueAccumulated(currentText);

                if (UserRequestedAllLine)
                {
                    TextManager.ShowDialogueAccumulated(dialogueText.ToStringFull());
                    break;
                }

                yield return(new WaitForSeconds(CurrentStyle.Delay));
            }

            yield return(new WaitForSeconds(NextDialogueDelay));

            UserRequestedNextLine = false;
            while (!UserRequestedNextLine)
            {
                yield return(null);
            }

            DialogueSystem.RequestNextLine();
        }
Ejemplo n.º 3
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, Action onComplete)
        {
            onLineStart?.Invoke();

            // The final text we'll be showing for this line.
            string text = localisationProvider.GetLocalisedTextForLine(line);

            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }
            else if (text[0] == LineStartPlaceHolder)
            {
                text = text.Remove(0, 1);
            }

            if (textSpeed > 0.0f && !proceedToNextLine)
            {
                IDialogueText completeText = ComplexDialogueText.AnalyzeText(text, RunLineLogger);

                foreach (string currentText in completeText.Parse())
                {
                    LineUpdate(currentText);
                    if (proceedToNextLine)
                    {
                        // We've requested a skip of the entire line.
                        // Display all of the text immediately.
                        LineUpdate(text);
                        break;
                    }
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                LineUpdate(text);
            }

            // We're now waiting for the player to move on to the next line
            proceedToNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            LineFinishDisplaying();

            while (!proceedToNextLine)
            {
                yield return(CheckContinue());
            }

            // Avoid skipping lines if textSpeed == 0
            yield return(new WaitForEndOfFrame());

            // Hide the text and prompt
            LineEnd();

            onComplete();
        }
Ejemplo n.º 4
0
 public void AddText(IDialogueText dialogueText)
 {
     if (this.Text == null)
     {
         this.Text = dialogueText;
     }
     else
     {
         this.Text.AddText(dialogueText);
     }
 }
        private void ProcessDialogue(string dialogue)
        {
            // Antes de hacer nada se analiza el texto y se clasifican internamente las partes con tags y las simples
            IDialogueText classifiedCharacterDialogue = DialogueTextAnalyser.AnalyseText(dialogue);

            if (CurrentStyle.Delay > 0.0f)
            {
                //StartCoroutine(DoParseAccumulated(classifiedCharacterDialogue));
                StartCoroutine(DoParseSingle(classifiedCharacterDialogue));
            }
            else
            {
                TextManager.ShowDialogueAccumulated(dialogue);
            }

            VoiceManager.SpeakDialogueAccumulated(classifiedCharacterDialogue.ToStringClean());
        }
 public void AddText(IDialogueText dialogueText)
 {
     Texts.Add(dialogueText);
 }
Ejemplo n.º 7
0
 public DialogueTaggedText(TagType tag, IDialogueText dialogueText = null)
 {
     this.Tag  = tag;
     this.Text = dialogueText;
 }
Ejemplo n.º 8
0
 public void AddText(IDialogueText dialogueText)
 {
     this.Text += dialogueText.ToStringFull();
 }
Ejemplo n.º 9
0
 public void AddDialogueText(IDialogueText dialogueText)
 {
     this.Texts.Add(dialogueText);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Analiza el <paramref name="text"/> indicado, y lo clasifica según si contiene o no tags.
        /// <para>Opcionalmente, puedes añadir un <paramref name="logger"/> para que te reporte las excepciones internas que se puedan producir (mediante <see cref="ParsingException"/>).</para>
        /// </summary>
        /// <param name="text">El texto de entrada.</param>
        /// <param name="logger">Función que te reporte las excepciones internas que se puedan producir.</param>
        /// <param name="format">El formato de Tag que deseas que analice dentro del texto.</param>
        /// <returns></returns>
        public static IDialogueText AnalyzeText(string text, TagFormat format, Action <ParsingException> logger = null)
        {
            IDialogueText resultDialogueText = null;

            string textBeingAnalyzed = text;

            while (textBeingAnalyzed != null && textBeingAnalyzed.Length > 0)
            {
                int indexOfTagInit = 0;
                try
                {
                    TagOption tag = format.Extract(textBeingAnalyzed, out indexOfTagInit, out int _, out string remainingTextAfterStart);
                    if (tag != null)
                    {
                        if (indexOfTagInit > 0)
                        {
                            string textBeforeTag = textBeingAnalyzed.Substring(0, indexOfTagInit);
                            if (resultDialogueText == null)
                            {
                                resultDialogueText = new ComplexDialogueText(textBeforeTag);
                            }
                            else
                            {
                                resultDialogueText.AddText(textBeforeTag);
                            }
                        }

                        if (tag.Position == TagOptionPosition.start)
                        {
                            string    textSearchingForEnd = remainingTextAfterStart;
                            string    taggedText = null, remainingTextAfterEnd = null;
                            TagOption endTag = null;
                            while (taggedText == null && textSearchingForEnd != null && textSearchingForEnd.Length > 0)
                            {
                                endTag = format.Extract(textSearchingForEnd, out int indexOfEndTagInit, out int _, out remainingTextAfterEnd);
                                if (endTag != null)
                                {
                                    if (TagOption.Matches(tag, endTag))
                                    {
                                        taggedText        = remainingTextAfterStart.Substring(0, remainingTextAfterStart.Length - remainingTextAfterEnd.Length - endTag.Text.Length);
                                        textBeingAnalyzed = remainingTextAfterEnd; // This tag has been found correctly, go to the next portion of the text
                                        break;
                                    }
                                }
                                textSearchingForEnd = remainingTextAfterEnd;
                            }

                            if (taggedText == null)
                            {
                                throw new TagException.StartTagWithoutEndException(tag, index: text.Length - textBeingAnalyzed.Length + indexOfTagInit);
                            }
                            else
                            {
                                DialogueTaggedText dialogueTaggedText = new DialogueTaggedText(new Tag(tag, endTag), AnalyzeText(taggedText, format, logger));
                                if (resultDialogueText == null)
                                {
                                    if (remainingTextAfterEnd != null && remainingTextAfterEnd.Length > 0)
                                    {
                                        resultDialogueText = new ComplexDialogueText(dialogueTaggedText);
                                    }
                                    else
                                    {
                                        resultDialogueText = dialogueTaggedText;
                                    }
                                }
                                else
                                {
                                    resultDialogueText.AddDialogueText(dialogueTaggedText);
                                }
                            }
                        }
                        else
                        {
                            throw new TagException.EndTagBeforeStartException(tag, index: text.Length - textBeingAnalyzed.Length + indexOfTagInit);
                        }
                    }
                    else
                    {
                        if (resultDialogueText == null)
                        {
                            return(new DialogueText(textBeingAnalyzed));
                        }
                        else
                        {
                            resultDialogueText.AddText(textBeingAnalyzed);
                            return(resultDialogueText);
                        }
                    }
                }
                catch (ParsingException ex)
                {
                    // Log the exception
                    logger?.Invoke(ex);

                    int nextIndex = indexOfTagInit + 1;

                    // Add the start of the tag as raw text

                    if (resultDialogueText == null)
                    {
                        resultDialogueText = new ComplexDialogueText(textBeingAnalyzed.Substring(0, nextIndex));
                    }
                    else
                    {
                        resultDialogueText.AddText(textBeingAnalyzed[indexOfTagInit].ToString());
                    }

                    // Go to the next portion of the text (Skip the exception source)
                    textBeingAnalyzed = nextIndex < textBeingAnalyzed.Length ? textBeingAnalyzed.Substring(nextIndex) : null;
                }
            }

            return(resultDialogueText);
        }
        /// <summary>
        /// Analiza el <paramref name="text"/> indicado, y lo clasifica según si contiene o no tags.
        /// </summary>
        /// <param name="text">El texto de entrada.</param>
        /// <param name="format">El formato de Tag que deseas que analice dentro del texto.</param>
        /// <returns></returns>
        private static IDialogueText AnalyseTaggedText(string text, TagFormat format)
        {
            IDialogueText resultDialogueText = null;

            string textBeingAnalyzed = text;
            int    currentIndex      = 0;

            // Mientras quede texto por analizar
            while (textBeingAnalyzed.Length > 0)
            {
                int nextIndex      = currentIndex;
                int indexOfTagInit = 0;

                try
                {
                    // Extraes siguiente tag que haya
                    TagOption tag = format.Extract(textBeingAnalyzed, out indexOfTagInit, out int _, out string remainingTextAfterStart);

                    if (tag != null) // Aún hay tags en el texto
                    {
                        nextIndex = (text.Length - textBeingAnalyzed.Length + indexOfTagInit) + tag.Text().Length;

                        if (indexOfTagInit > 0) // Si hay tag inicial, si no hay es porque no existe inicio porque se ha quitado en iteraciones anteriores
                        {
                            // Coger el texto antes de que empiece el tag y añadirlo a resultDialogueText
                            string textBeforeTag = textBeingAnalyzed.Substring(0, indexOfTagInit);
                            if (resultDialogueText == null)
                            {
                                // El texto original es un ComplexDialogueText
                                resultDialogueText = new ComplexDialogueText(textBeforeTag);
                            }
                            else
                            {
                                // Añadir el texto al ComplexDialogueText
                                resultDialogueText.AddText(textBeforeTag);
                            }
                        }

                        if (tag.Position == TagOptionPosition.Start) // si el tag es del principio
                        {
                            string    textSearchingForEnd   = remainingTextAfterStart;
                            string    taggedText            = null;
                            string    remainingTextAfterEnd = null;
                            TagOption endTag = null;
                            while (taggedText == null && textSearchingForEnd.Length > 0) // Mientras haya texto
                            {
                                // Extraer el siguiente tag, que deberia ser el tag de cierre
                                endTag = format.Extract(textSearchingForEnd, out int indexOfEndTagInit, out int _, out remainingTextAfterEnd);
                                if (endTag != null)                     // Si el endTag se ha encontrado
                                {
                                    if (TagOption.Matches(tag, endTag)) // Si es el endTag del tag actual (soporte para nested tags)
                                    {
                                        taggedText        = remainingTextAfterStart.Substring(0, remainingTextAfterStart.Length - remainingTextAfterEnd.Length - endTag.Text().Length);
                                        textBeingAnalyzed = remainingTextAfterEnd;
                                    }
                                    else
                                    {
                                        // Actualizar texto para encontrar el endTag del tag actual
                                        textSearchingForEnd = remainingTextAfterEnd;
                                    }
                                }
                            }

                            if (taggedText == null) // Si no se ha encontrado tag de cierre para el tag actual
                            {
                                throw new TagException.StartTagWithoutEndException(tag, indexOfTagInit);
                            }
                            else
                            {
                                // Crear DialogueTaggedText a partir de este tag, porque ya sabemos cuando termina
                                // Llamada recursiva a AnalyzeText para encontrar el texto interior (y soportar posibles tags nesteados)
                                DialogueTaggedText dialogueTaggedText = new DialogueTaggedText(new TagType(tag, endTag), AnalyseTaggedText(taggedText, format));
                                if (resultDialogueText == null)
                                {
                                    if (remainingTextAfterEnd != null && remainingTextAfterEnd.Length > 0) // Si hay más texto luego
                                    {
                                        // El texto original es un ComplexDialogueText
                                        resultDialogueText = new ComplexDialogueText(dialogueTaggedText);
                                    }
                                    else // No existe más texto luego
                                    {
                                        // El texto original es un DialogueTaggedText
                                        resultDialogueText = dialogueTaggedText;
                                    }
                                }
                                else
                                {
                                    // Añadir el texto al ComplexDialogueText
                                    resultDialogueText.AddText(dialogueTaggedText);
                                }
                            }
                        }
                        else
                        {
                            throw new TagException.EndTagBeforeStartException(tag, currentIndex);
                        }
                    }
                    else // No se ha encontrado ningun tag más
                    {
                        if (resultDialogueText == null)
                        {
                            // El texto original es un DialogueText
                            resultDialogueText = new DialogueText(textBeingAnalyzed);
                        }
                        else
                        {
                            // Añadir el texto al ComplexDialogueText
                            resultDialogueText.AddText(textBeingAnalyzed);
                        }

                        return(resultDialogueText);
                    }
                }
                catch (ParsingException)
                {
                    nextIndex = (text.Length - textBeingAnalyzed.Length + indexOfTagInit) + 1;

                    // Go to the next portion of the text (Skip the exception source)
                    textBeingAnalyzed = textBeingAnalyzed.Substring(nextIndex);
                    currentIndex      = nextIndex;
                }
            }

            return(resultDialogueText);
        }