Chatter.cs
namespace NiuLai;
/// <summary>Non-blocking movie mutter. Walk while the grassland talks.</summary>
public static class Chatter
{
public static string Who { get; private set; } = "";
public static string Cn { get; private set; } = "";
public static string En { get; private set; } = "";
public static float Left { get; private set; }
public static int Version { get; private set; }
public static bool Visible => Left > 0f && !string.IsNullOrEmpty( Cn );
public static void Say( string who, Line line, float sec = 2.7f )
{
if ( GameState.Talking || FilmCut.Playing )
return;
if ( string.IsNullOrEmpty( line.Cn ) )
return;
Who = who ?? "";
Cn = line.Cn;
En = line.En ?? "";
Left = sec;
Version++;
}
public static void Tick( float dt )
{
if ( Left <= 0f )
return;
Left -= dt;
if ( Left <= 0f )
{
Left = 0f;
Version++;
}
}
public static Line Pick( Line[] pool )
{
if ( pool is not { Length: > 0 } )
return default;
return pool[Random.Shared.Int( 0, pool.Length - 1 )];
}
}