using UnityEngine;
namespace Ashwild.UI
{
///
/// Authoring container for the rotating quotes shown on the loading screen. A logic-free data
/// asset (mirrors MusicPlaylist): create one via Assets ▸ Create ▸ UI ▸ Loading Quotes, fill the
/// list in the inspector, and assign it to the LoadingScreen. Keeping the quotes here lets us add
/// or reword lines without touching code, and lets the loading screen pick from them at random.
///
[CreateAssetMenu(fileName = "LoadingQuotes", menuName = "UI/Loading Quotes")]
public class LoadingQuotes : ScriptableObject
{
#region Types
///
/// A single line shown on the loading screen: the quote itself plus an optional author shown
/// underneath. Leave the author empty for anonymous lines or plain loading tips.
///
[System.Serializable]
public struct Quote
{
[TextArea] public string text;
public string author;
}
#endregion
#region Serialized Fields
[Header("Quotes")]
[Tooltip("The pool of quotes the loading screen cycles through at random.")]
[SerializeField] private Quote[] quotes;
#endregion
#region Public API
///
/// True when at least one quote is authored — guards the loading screen against an empty asset.
///
public bool HasQuotes => quotes != null && quotes.Length > 0;
///
/// Number of authored quotes.
///
public int Count => quotes != null ? quotes.Length : 0;
///
/// Returns a random quote while avoiding the one at so the same
/// line never shows twice in a row (unless there is only one quote). Outputs the chosen index
/// so the caller can feed it back in on the next call.
///
public Quote GetRandom(int avoidIndex, out int chosenIndex)
{
if (!HasQuotes)
{
chosenIndex = -1;
return default;
}
if (quotes.Length == 1)
{
chosenIndex = 0;
return quotes[0];
}
int index = Random.Range(0, quotes.Length);
if (index == avoidIndex)
index = (index + 1) % quotes.Length;
chosenIndex = index;
return quotes[index];
}
#endregion
}
}