Static helper that maps level map symbols to preview Colors for the editor thumbnail. It defines background and empty colors and returns a Color for a given char using a switch expression with a fallback to Empty.
using Sandbox;
namespace Breakout;
/// <summary>
/// Maps level symbols to the colors used when drawing a level's thumbnail preview. This is only for
/// the editor preview image; the in-game bricks get their color from the spawner's palette.
/// </summary>
public static class BlockPalette
{
public static readonly Color Background = new( 0.07f, 0.08f, 0.10f );
public static readonly Color Empty = new( 0.16f, 0.17f, 0.19f );
/// <summary>
/// The preview color for a level symbol (falls back to the empty-cell color for unknown symbols).
/// </summary>
public static Color ColorFor( char symbol )
{
return symbol switch
{
'1' => new Color( 0.95f, 0.62f, 0.20f ), // normal
'2' => new Color( 0.36f, 0.55f, 0.78f ), // multi-hit
'P' => new Color( 0.35f, 0.78f, 0.42f ), // power-up (multi-ball)
'E' => new Color( 0.30f, 0.78f, 0.80f ), // expand
'X' => new Color( 0.86f, 0.27f, 0.27f ), // exploding
'#' => new Color( 0.55f, 0.55f, 0.58f ), // unbreakable
'S' => new Color( 1.00f, 0.45f, 0.20f ), // fast ball
'B' => new Color( 0.40f, 0.70f, 1.00f ), // big ball
'F' => new Color( 1.00f, 0.35f, 0.10f ), // fireball
_ => Empty,
};
}
}