/// <summary> /// Appends additional dialog for the specified speaker to the state. /// <paramref name="dialog"/> will have leading and trailing whitespace /// removed and a space will be prepended to it if the existing dialog /// for the specified speaker doesn't end with a whitespace. /// /// If you don't want any input sanitization, use /// <see cref="AppendRawDialog(string, string)"/> instead. /// </summary> /// <param name="speaker">The speaker to add dialog for.</param> /// <param name="dialog">The dialog to add.</param> /// <exception cref="ArgumentNullException"> /// Thrown if either <paramref name="speaker"/> or /// <paramref name="dialog"/> is null. /// </exception> public void AppendDialog(string speaker, string dialog) { speaker = speaker ?? DefaultSpeaker; if (dialog == null) { throw new ArgumentNullException(nameof(dialog)); } if (Dialog.ContainsKey(speaker) && Dialog[speaker].Length > 0) { var ch = Dialog[speaker][Dialog[speaker].Length - 1]; if (char.IsWhiteSpace(ch)) { Dialog[speaker] += dialog; OnAppendDialog?.Invoke(speaker, dialog); } else { Dialog[speaker] += " " + dialog; OnAppendDialog?.Invoke(speaker, " " + dialog); } } else { Dialog[speaker] = dialog; OnAppendDialog?.Invoke(speaker, dialog); } }
/// <summary> /// Adds dialog to the state without any input sanitization. /// </summary> /// <param name="speaker">The speaker to add dialog for.</param> /// <param name="dialog">The dialog to add.</param> /// <exception cref="ArgumentNullException"> /// Thrown if either <paramref name="speaker"/> or /// <paramref name="dialog"/> is null. /// </exception> public void AppendRawDialog(string speaker, string dialog) { speaker = speaker ?? DefaultSpeaker; if (dialog == null) { throw new ArgumentNullException(nameof(dialog)); } if (Dialog.ContainsKey(speaker)) { Dialog[speaker] += dialog; OnAppendDialog?.Invoke(speaker, dialog); } else { Dialog.Add(speaker, dialog); OnAppendDialog?.Invoke(speaker, dialog); } }